diff --git a/Makefile.in b/Makefile.in index c0b7ef8..7c95736 100644 --- a/Makefile.in +++ b/Makefile.in @@ -36,7 +36,7 @@ CC=@CC@ .SUFFIXES: .c .h .o all: ${EXE_LIST} ${DIR_LIST} -create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto.c ${AUTO}/auto-header.h +create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto.c ${AUTO}/auto-header.h ${AUTO}/constants.h create_dirs: ${DIR_LIST} ${DIR_LIST}: @@ -59,8 +59,14 @@ ${EXE}/telegram-cli: ${TG_OBJECTS} ${COMMON_OBJECTS} ${EXE}/generate: ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${CC} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -o $@ -${AUTO}/scheme.tlo: ${srcdir}/scheme.tl ${EXE}/tlc - ${EXE}/tlc -e $@ ${srcdir}/scheme.tl +${AUTO}/scheme.tlo: ${AUTO}/scheme.tl ${EXE}/tlc + ${EXE}/tlc -e $@ ${AUTO}/scheme.tl + +${AUTO}/scheme.tl: ${srcdir}/scheme.tl ${srcdir}/binlog.tl + cat $^ > $@ + +${AUTO}/scheme2.tl: ${AUTO}/scheme.tl ${EXE}/tlc + ${EXE}/tlc -E ${AUTO}/scheme.tl 2> $@ || ( cat $@ && rm $@ && false ) ${AUTO}/auto.c: ${AUTO}/scheme.tlo ${EXE}/generate ${EXE}/generate ${AUTO}/scheme.tlo > $@ @@ -68,6 +74,9 @@ ${AUTO}/auto.c: ${AUTO}/scheme.tlo ${EXE}/generate ${AUTO}/auto-header.h: ${AUTO}/scheme.tlo ${EXE}/generate ${EXE}/generate -H ${AUTO}/scheme.tlo > $@ +${AUTO}/constants.h: ${AUTO}/scheme2.tl + awk -f ${srcdir}/gen_constants_h.awk < $^ > $@ + clean: rm -rf ${DIR_LIST} config.log config.status > /dev/null || echo "all clean" diff --git a/auto.h b/auto.h index 591f329..3c0d055 100644 --- a/auto.h +++ b/auto.h @@ -14,11 +14,14 @@ struct paramed_type { #define NAME_ARRAY 0x89932ad9 #define TYPE_TO_PARAM(NAME) (&(struct paramed_type) {.type = &tl_type_## NAME, .params=0}) +#define TYPE_TO_PARAM_1(NAME,PARAM1) (&(struct paramed_type) {.type = &tl_type_## NAME, .params=(struct paramed_type *[1]){PARAM1}}) #define ODDP(x) (((long)(x)) & 1) #define EVENP(x) (!ODDP(x)) #define INT2PTR(x) (void *)(long)(((long)x) * 2 + 1) #define PTR2INT(x) ((((long)x) - 1) / 2) +#define FETCH_COMBINATOR_FUNCTION(NAME) + #include "auto/auto-header.h" #endif diff --git a/binlog.c b/binlog.c index b544876..e22159a 100644 --- a/binlog.c +++ b/binlog.c @@ -76,6 +76,125 @@ void *alloc_log_event (int l UU) { long long binlog_pos; +int fetch_comb_binlog_start (void *extra) { + return 0; +} + +int fetch_comb_binlog_dc_option (void *extra) { + int id = fetch_int (); + int l1 = prefetch_strlen (); + assert (l1 >= 0); + char *name = fetch_str (l1); + int l2 = prefetch_strlen (); + assert (l2 >= 0); + char *ip = fetch_str (l2); + int port = fetch_int (); + + if (verbosity) { + logprintf ("DC%d '%s' update: %s:%d\n", id, name, ip, port); + } + + alloc_dc (id, tstrndup (ip, l2), port); + return 0; +} + +int fetch_comb_binlog_auth_key (void *extra) { + int num = fetch_int (); + assert (num >= 0 && num <= MAX_DC_ID); + assert (DC_list[num]); + DC_list[num]->auth_key_id = fetch_long (); + fetch_ints (DC_list[num]->auth_key, 64); + DC_list[num]->flags |= 1; + return 0; +} + +int fetch_comb_binlog_default_dc (void *extra) { + int num = fetch_int (); + assert (num >= 0 && num <= MAX_DC_ID); + DC_working = DC_list[num]; + dc_working_num = num; + return 0; +} + +int fetch_comb_binlog_our_id (void *extra) { + our_id = fetch_int (); + #ifdef USE_LUA + lua_our_id (our_id); + #endif + return 0; +} + +int fetch_comb_binlog_dc_signed (void *extra) { + int num = fetch_int (); + assert (num >= 0 && num <= MAX_DC_ID); + assert (DC_list[num]); + DC_list[num]->has_auth = 1; + return 0; +} + +int fetch_comb_binlog_dc_salt (void *extra) { + int num = fetch_int (); + assert (num >= 0 && num <= MAX_DC_ID); + assert (DC_list[num]); + DC_list[num]->server_salt = fetch_long (); + return 0; +} + +int fetch_comb_binlog_new_user (void *extra) { + peer_id_t id = MK_USER (fetch_int ()); + peer_t *_U = user_chat_get (id); + if (!_U) { + _U = talloc0 (sizeof (*_U)); + _U->id = id; + insert_user (_U); + } else { + assert (!(_U->flags & FLAG_CREATED)); + } + struct user *U = (void *)_U; + U->flags |= FLAG_CREATED; + if (get_peer_id (id) == our_id) { + U->flags |= FLAG_USER_SELF; + } + U->first_name = fetch_str_dup (); + U->last_name = fetch_str_dup (); + assert (!U->print_name); + U->print_name = create_print_name (U->id, U->first_name, U->last_name, 0, 0); + + peer_insert_name ((void *)U); + U->access_hash = fetch_long (); + U->phone = fetch_str_dup (); + if (fetch_int ()) { + U->flags |= FLAG_USER_CONTACT; + } + + #ifdef USE_LUA + lua_user_update (U); + #endif + return 0; +} + +int fetch_comb_binlog_new_user (void *extra) { + peer_id_t id = MK_USER (fetch_int ()); + peer_t *U = user_chat_get (id); + assert (U); + U->flags |= FLAG_DELETED; + + #ifdef USE_LUA + lua_user_update (U); + #endif + return 0; +} + +FETCH_COMBINATOR_FUNCTION (binlog_start) +FETCH_COMBINATOR_FUNCTION (binlog_dc_option) +FETCH_COMBINATOR_FUNCTION (binlog_auth_key) +FETCH_COMBINATOR_FUNCTION (binlog_default_dc) +FETCH_COMBINATOR_FUNCTION (binlog_our_id) +FETCH_COMBINATOR_FUNCTION (binlog_dc_signed) +FETCH_COMBINATOR_FUNCTION (binlog_dc_salt) +FETCH_COMBINATOR_FUNCTION (binlog_new_user) +FETCH_COMBINATOR_FUNCTION (binlog_user_delete) + void replay_log_event (void) { int *start = rptr; in_replay_log = 1; @@ -89,258 +208,6 @@ void replay_log_event (void) { in_ptr = rptr; in_end = wptr; switch (op) { - case LOG_START: - rptr ++; - break; - case CODE_binlog_dc_option: - in_ptr ++; - { - int id = fetch_int (); - int l1 = prefetch_strlen (); - char *name = fetch_str (l1); - int l2 = prefetch_strlen (); - char *ip = fetch_str (l2); - int port = fetch_int (); - if (verbosity) { - logprintf ( "id = %d, name = %.*s ip = %.*s port = %d\n", id, l1, name, l2, ip, port); - } - alloc_dc (id, tstrndup (ip, l2), port); - } - rptr = in_ptr; - break; - case LOG_AUTH_KEY: - rptr ++; - { - int num = *(rptr ++); - assert (num >= 0 && num <= MAX_DC_ID); - assert (DC_list[num]); - DC_list[num]->auth_key_id = *(long long *)rptr; - rptr += 2; - memcpy (DC_list[num]->auth_key, rptr, 256); - rptr += 64; - DC_list[num]->flags |= 1; - }; - break; - case LOG_DEFAULT_DC: - rptr ++; - { - int num = *(rptr ++); - assert (num >= 0 && num <= MAX_DC_ID); - DC_working = DC_list[num]; - dc_working_num = num; - } - break; - case LOG_OUR_ID: - rptr ++; - { - our_id = *(rptr ++); - #ifdef USE_LUA - lua_our_id (our_id); - #endif - } - break; - case LOG_DC_SIGNED: - rptr ++; - { - int num = *(rptr ++); - assert (num >= 0 && num <= MAX_DC_ID); - assert (DC_list[num]); - DC_list[num]->has_auth = 1; - } - break; - case LOG_DC_SALT: - rptr ++; - { - int num = *(rptr ++); - assert (num >= 0 && num <= MAX_DC_ID); - assert (DC_list[num]); - DC_list[num]->server_salt = *(long long *)rptr; - rptr += 2; - }; - break; -/* case CODE_user_empty: - case CODE_user_self: - case CODE_user_contact: - case CODE_user_request: - case CODE_user_foreign: - case CODE_user_deleted: - fetch_alloc_user (); - rptr = in_ptr; - break;*/ - case LOG_DH_CONFIG: - get_dh_config_on_answer (0); - rptr = in_ptr; - break; - case LOG_ENCR_CHAT_KEY: - rptr ++; - { - peer_id_t id = MK_ENCR_CHAT (*(rptr ++)); - struct secret_chat *U = (void *)user_chat_get (id); - assert (U); - U->key_fingerprint = *(long long *)rptr; - rptr += 2; - memcpy (U->key, rptr, 256); - rptr += 64; - }; - break; - case LOG_ENCR_CHAT_SEND_ACCEPT: - rptr ++; - { - peer_id_t id = MK_ENCR_CHAT (*(rptr ++)); - struct secret_chat *U = (void *)user_chat_get (id); - assert (U); - U->key_fingerprint = *(long long *)rptr; - rptr += 2; - memcpy (U->key, rptr, 256); - rptr += 64; - if (!U->g_key) { - U->g_key = talloc (256); - } - memcpy (U->g_key, rptr, 256); - rptr += 64; - }; - break; - case LOG_ENCR_CHAT_SEND_CREATE: - rptr ++; - { - peer_id_t id = MK_ENCR_CHAT (*(rptr ++)); - struct secret_chat *U = (void *)user_chat_get (id); - assert (!U || !(U->flags & FLAG_CREATED)); - if (!U) { - U = talloc0 (sizeof (peer_t)); - U->id = id; - insert_encrypted_chat ((void *)U); - } - U->flags |= FLAG_CREATED; - U->user_id = *(rptr ++); - memcpy (U->key, rptr, 256); - rptr += 64; - if (!U->print_name) { - peer_t *P = user_chat_get (MK_USER (U->user_id)); - if (P) { - U->print_name = create_print_name (U->id, "!", P->user.first_name, P->user.last_name, 0); - } else { - static char buf[100]; - tsnprintf (buf, 99, "user#%d", U->user_id); - U->print_name = create_print_name (U->id, "!", buf, 0, 0); - } - peer_insert_name ((void *)U); - } - }; - break; - case LOG_ENCR_CHAT_DELETED: - rptr ++; - { - peer_id_t id = MK_ENCR_CHAT (*(rptr ++)); - struct secret_chat *U = (void *)user_chat_get (id); - if (!U) { - U = talloc0 (sizeof (peer_t)); - U->id = id; - insert_encrypted_chat ((void *)U); - } - U->flags |= FLAG_CREATED; - U->state = sc_deleted; - }; - break; - case LOG_ENCR_CHAT_WAITING: - rptr ++; - { - peer_id_t id = MK_ENCR_CHAT (*(rptr ++)); - struct secret_chat *U = (void *)user_chat_get (id); - assert (U); - U->state = sc_waiting; - U->date = *(rptr ++); - U->admin_id = *(rptr ++); - U->user_id = *(rptr ++); - U->access_hash = *(long long *)rptr; - rptr += 2; - }; - break; - case LOG_ENCR_CHAT_REQUESTED: - rptr ++; - { - peer_id_t id = MK_ENCR_CHAT (*(rptr ++)); - struct secret_chat *U = (void *)user_chat_get (id); - if (!U) { - U = talloc0 (sizeof (peer_t)); - U->id = id; - insert_encrypted_chat ((void *)U); - } - U->flags |= FLAG_CREATED; - U->state = sc_request; - U->date = *(rptr ++); - U->admin_id = *(rptr ++); - U->user_id = *(rptr ++); - U->access_hash = *(long long *)rptr; - if (!U->print_name) { - peer_t *P = user_chat_get (MK_USER (U->user_id)); - if (P) { - U->print_name = create_print_name (U->id, "!", P->user.first_name, P->user.last_name, 0); - } else { - static char buf[100]; - tsnprintf (buf, 99, "user#%d", U->user_id); - U->print_name = create_print_name (U->id, "!", buf, 0, 0); - } - peer_insert_name ((void *)U); - } - rptr += 2; - }; - break; - case LOG_ENCR_CHAT_OK: - rptr ++; - { - peer_id_t id = MK_ENCR_CHAT (*(rptr ++)); - struct secret_chat *U = (void *)user_chat_get (id); - assert (U); - U->state = sc_ok; - #ifdef USE_LUA - lua_secret_chat_created (U); - #endif - } - break; - case CODE_binlog_new_user: - in_ptr ++; - { - peer_id_t id = MK_USER (fetch_int ()); - peer_t *_U = user_chat_get (id); - if (!_U) { - _U = talloc0 (sizeof (*_U)); - _U->id = id; - insert_user (_U); - } else { - assert (!(_U->flags & FLAG_CREATED)); - } - struct user *U = (void *)_U; - U->flags |= FLAG_CREATED; - if (get_peer_id (id) == our_id) { - U->flags |= FLAG_USER_SELF; - } - U->first_name = fetch_str_dup (); - U->last_name = fetch_str_dup (); - assert (!U->print_name); - U->print_name = create_print_name (U->id, U->first_name, U->last_name, 0, 0); - peer_insert_name ((void *)U); - U->access_hash = fetch_long (); - U->phone = fetch_str_dup (); - if (fetch_int ()) { - U->flags |= FLAG_USER_CONTACT; - } - - #ifdef USE_LUA - lua_user_update (U); - #endif - } - rptr = in_ptr; - break; - case CODE_binlog_user_delete: - rptr ++; - { - peer_id_t id = MK_USER (*(rptr ++)); - peer_t *U = user_chat_get (id); - assert (U); - U->flags |= FLAG_DELETED; - } - break; case CODE_binlog_set_user_access_token: rptr ++; { diff --git a/binlog.h b/binlog.h index d0d2d9b..235bbe3 100644 --- a/binlog.h +++ b/binlog.h @@ -36,7 +36,6 @@ #define LOG_ENCR_CHAT_REQUESTED 0x9011011a #define LOG_ENCR_CHAT_OK 0x7612ce13 -#define CODE_binlog_new_user 0xe04f30de #define CODE_binlog_user_delete 0xf7a27c79 #define CODE_binlog_set_user_access_token 0x1349f615 #define CODE_binlog_set_user_phone 0x5d3afde2 diff --git a/binlog.tl b/binlog.tl index c7c80b7..7ddcf33 100644 --- a/binlog.tl +++ b/binlog.tl @@ -1,10 +1,11 @@ -log.peer peer_type:int peer_id:int = log.Peer; - -log.dc num:int hostname:string ip:string port:int = log.Event; -log.dcRenum old_num:int new_num:int = log.Event; -log.authKey dc:int key:bytes key_id:long = log.Event; -log.signIn dc:int id:int = log.Event; - - -log.user id:int flags:int access_hash:long first_name:string last_name:string real_first_name:string real_last_name:string phone:string photo:log.Photo photo_id:long photo_big:log.FileLocation photo_small:long.FileLocation = log.Event; +---types--- +binlog.start = binlog.Update; +binlog.dcUpdate id:int name:string ip:string port:int = binlog.Update; +binlog.authKey dc:int key_id:long key:64*[int] = binlog.Update; +binlog.defaultDc dc:int = binlog.Update; +binlog.ourId id:int = binlog.Update; +binlog.dcSigned id:int = binlog.Update; +binlog.dcSalt id:int salt:long = binlog.Update; +binlog.newUser id:int first_name:string last_name:string hash:long phone:string is_contact:int = binlog.Update; +binlog.userDelete id:int = binlog.Update; diff --git a/constants.h b/constants.h deleted file mode 100644 index cd19aa8..0000000 --- a/constants.h +++ /dev/null @@ -1,383 +0,0 @@ -/* - This file is part of telegram-client. - - Telegram-client is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - Telegram-client is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this telegram-client. If not, see . - - Copyright Vitaly Valtman 2013 -*/ -#ifndef CONSTANTS_H -#define CONSTANTS_H -#define CODE_bool_false 0xbc799737 -#define CODE_bool_true 0x997275b5 -#define CODE_vector 0x1cb5c415 -#define CODE_error 0xc4b9f9bb -#define CODE_null 0x56730bcc -#define CODE_input_peer_empty 0x7f3b18ea -#define CODE_input_peer_self 0x7da07ec9 -#define CODE_input_peer_contact 0x1023dbe8 -#define CODE_input_peer_foreign 0x9b447325 -#define CODE_input_peer_chat 0x179be863 -#define CODE_input_user_empty 0xb98886cf -#define CODE_input_user_self 0xf7c1b13f -#define CODE_input_user_contact 0x86e94f65 -#define CODE_input_user_foreign 0x655e74ff -#define CODE_input_phone_contact 0xf392b7f4 -#define CODE_input_file 0xf52ff27f -#define CODE_input_media_empty 0x9664f57f -#define CODE_input_media_uploaded_photo 0x2dc53a7d -#define CODE_input_media_photo 0x8f2ab2ec -#define CODE_input_media_geo_point 0xf9c44144 -#define CODE_input_media_contact 0xa6e45987 -#define CODE_input_media_uploaded_video 0x4847d92a -#define CODE_input_media_uploaded_thumb_video 0xe628a145 -#define CODE_input_media_video 0x7f023ae6 -#define CODE_input_chat_photo_empty 0x1ca48f57 -#define CODE_input_chat_uploaded_photo 0x94254732 -#define CODE_input_chat_photo 0xb2e1bf08 -#define CODE_input_geo_point_empty 0xe4c123d6 -#define CODE_input_geo_point 0xf3b7acc9 -#define CODE_input_photo_empty 0x1cd7bf0d -#define CODE_input_photo 0xfb95c6c4 -#define CODE_input_video_empty 0x5508ec75 -#define CODE_input_video 0xee579652 -#define CODE_input_file_location 0x14637196 -#define CODE_input_video_file_location 0x3d0364ec -#define CODE_input_photo_crop_auto 0xade6b004 -#define CODE_input_photo_crop 0xd9915325 -#define CODE_input_app_event 0x770656a8 -#define CODE_peer_user 0x9db1bc6d -#define CODE_peer_chat 0xbad0e5bb -#define CODE_storage_file_unknown 0xaa963b05 -#define CODE_storage_file_jpeg 0x7efe0e -#define CODE_storage_file_gif 0xcae1aadf -#define CODE_storage_file_png 0xa4f63c0 -#define CODE_storage_file_mp3 0x528a0677 -#define CODE_storage_file_mov 0x4b09ebbc -#define CODE_storage_file_partial 0x40bc6f52 -#define CODE_storage_file_mp4 0xb3cea0e4 -#define CODE_storage_file_webp 0x1081464c -#define CODE_file_location_unavailable 0x7c596b46 -#define CODE_file_location 0x53d69076 -#define CODE_user_empty 0x200250ba -#define CODE_user_self 0x720535ec -#define CODE_user_contact 0xf2fb8319 -#define CODE_user_request 0x22e8ceb0 -#define CODE_user_foreign 0x5214c89d -#define CODE_user_deleted 0xb29ad7cc -#define CODE_user_profile_photo_empty 0x4f11bae1 -#define CODE_user_profile_photo 0xd559d8c8 -#define CODE_user_status_empty 0x9d05049 -#define CODE_user_status_online 0xedb93949 -#define CODE_user_status_offline 0x8c703f -#define CODE_chat_empty 0x9ba2d800 -#define CODE_chat 0x6e9c9bc7 -#define CODE_chat_forbidden 0xfb0ccc41 -#define CODE_chat_full 0x630e61be -#define CODE_chat_participant 0xc8d7493e -#define CODE_chat_participants_forbidden 0xfd2bb8a -#define CODE_chat_participants 0x7841b415 -#define CODE_chat_photo_empty 0x37c1011c -#define CODE_chat_photo 0x6153276a -#define CODE_message_empty 0x83e5de54 -#define CODE_message 0x22eb6aba -#define CODE_message_forwarded 0x5f46804 -#define CODE_message_service 0x9f8d60bb -#define CODE_message_media_empty 0x3ded6320 -#define CODE_message_media_photo 0xc8c45a2a -#define CODE_message_media_video 0xa2d24290 -#define CODE_message_media_geo 0x56e0d474 -#define CODE_message_media_contact 0x5e7d2f39 -#define CODE_message_media_unsupported 0x29632a36 -#define CODE_message_action_empty 0xb6aef7b0 -#define CODE_message_action_chat_create 0xa6638b9a -#define CODE_message_action_chat_edit_title 0xb5a1ce5a -#define CODE_message_action_chat_edit_photo 0x7fcb13a8 -#define CODE_message_action_chat_delete_photo 0x95e3fbef -#define CODE_message_action_chat_add_user 0x5e3cfc4b -#define CODE_message_action_chat_delete_user 0xb2ae9b0c -#define CODE_dialog 0x214a8cdf -#define CODE_photo_empty 0x2331b22d -#define CODE_photo 0x22b56751 -#define CODE_photo_size_empty 0xe17e23c -#define CODE_photo_size 0x77bfb61b -#define CODE_photo_cached_size 0xe9a734fa -#define CODE_video_empty 0xc10658a8 -#define CODE_video 0x5a04a49f -#define CODE_geo_point_empty 0x1117dd5f -#define CODE_geo_point 0x2049d70c -#define CODE_auth_checked_phone 0xe300cc3b -#define CODE_auth_sent_code 0xefed51d9 -#define CODE_auth_authorization 0xf6b673a4 -#define CODE_auth_exported_authorization 0xdf969c2d -#define CODE_input_notify_peer 0xb8bc5b0c -#define CODE_input_notify_users 0x193b4417 -#define CODE_input_notify_chats 0x4a95e84e -#define CODE_input_notify_all 0xa429b886 -#define CODE_input_peer_notify_events_empty 0xf03064d8 -#define CODE_input_peer_notify_events_all 0xe86a2c74 -#define CODE_input_peer_notify_settings 0x46a2ce98 -#define CODE_peer_notify_events_empty 0xadd53cb3 -#define CODE_peer_notify_events_all 0x6d1ded88 -#define CODE_peer_notify_settings_empty 0x70a68512 -#define CODE_peer_notify_settings 0x8d5e11ee -#define CODE_wall_paper 0xccb03657 -#define CODE_user_full 0x771095da -#define CODE_contact 0xf911c994 -#define CODE_imported_contact 0xd0028438 -#define CODE_contact_blocked 0x561bc879 -#define CODE_contact_found 0xea879f95 -#define CODE_contact_suggested 0x3de191a1 -#define CODE_contact_status 0xaa77b873 -#define CODE_chat_located 0x3631cf4c -#define CODE_contacts_foreign_link_unknown 0x133421f8 -#define CODE_contacts_foreign_link_requested 0xa7801f47 -#define CODE_contacts_foreign_link_mutual 0x1bea8ce1 -#define CODE_contacts_my_link_empty 0xd22a1c60 -#define CODE_contacts_my_link_requested 0x6c69efee -#define CODE_contacts_my_link_contact 0xc240ebd9 -#define CODE_contacts_link 0xeccea3f5 -#define CODE_contacts_contacts 0x6f8b8cb2 -#define CODE_contacts_contacts_not_modified 0xb74ba9d2 -#define CODE_contacts_imported_contacts 0xd1cd0a4c -#define CODE_contacts_blocked 0x1c138d15 -#define CODE_contacts_blocked_slice 0x900802a1 -#define CODE_contacts_found 0x566000e -#define CODE_contacts_suggested 0x5649dcc5 -#define CODE_messages_dialogs 0x15ba6c40 -#define CODE_messages_dialogs_slice 0x71e094f3 -#define CODE_messages_messages 0x8c718e87 -#define CODE_messages_messages_slice 0xb446ae3 -#define CODE_messages_message_empty 0x3f4e0648 -#define CODE_messages_message 0xff90c417 -#define CODE_messages_stated_messages 0x969478bb -#define CODE_messages_stated_message 0xd07ae726 -#define CODE_messages_sent_message 0xd1f4d35c -#define CODE_messages_chat 0x40e9002a -#define CODE_messages_chats 0x8150cbd8 -#define CODE_messages_chat_full 0xe5d7d19c -#define CODE_messages_affected_history 0xb7de36f2 -#define CODE_input_messages_filter_empty 0x57e2f66c -#define CODE_input_messages_filter_photos 0x9609a51c -#define CODE_input_messages_filter_video 0x9fc00e65 -#define CODE_input_messages_filter_photo_video 0x56e9f0e4 -#define CODE_update_new_message 0x13abdb3 -#define CODE_update_message_i_d 0x4e90bfd6 -#define CODE_update_read_messages 0xc6649e31 -#define CODE_update_delete_messages 0xa92bfe26 -#define CODE_update_restore_messages 0xd15de04d -#define CODE_update_user_typing 0x6baa8508 -#define CODE_update_chat_user_typing 0x3c46cfe6 -#define CODE_update_chat_participants 0x7761198 -#define CODE_update_user_status 0x1bfbd823 -#define CODE_update_user_name 0xda22d9ad -#define CODE_update_user_photo 0x95313b0c -#define CODE_update_contact_registered 0x2575bbb9 -#define CODE_update_contact_link 0x51a48a9a -#define CODE_update_activation 0x6f690963 -#define CODE_update_new_authorization 0x8f06529a -#define CODE_updates_state 0xa56c2a3e -#define CODE_updates_difference_empty 0x5d75a138 -#define CODE_updates_difference 0xf49ca0 -#define CODE_updates_difference_slice 0xa8fb1981 -#define CODE_updates_too_long 0xe317af7e -#define CODE_update_short_message 0xd3f45784 -#define CODE_update_short_chat_message 0x2b2fbd4e -#define CODE_update_short 0x78d4dec1 -#define CODE_updates_combined 0x725b04c3 -#define CODE_updates 0x74ae4240 -#define CODE_photos_photos 0x8dca6aa5 -#define CODE_photos_photos_slice 0x15051f54 -#define CODE_photos_photo 0x20212ca8 -#define CODE_upload_file 0x96a18d5 -#define CODE_dc_option 0x2ec2a43c -#define CODE_config 0x2e54dd74 -#define CODE_nearest_dc 0x8e1a1775 -#define CODE_help_app_update 0x8987f311 -#define CODE_help_no_app_update 0xc45a6536 -#define CODE_help_invite_text 0x18cb9f78 -#define CODE_messages_stated_messages_links 0x3e74f5c6 -#define CODE_messages_stated_message_link 0xa9af2881 -#define CODE_messages_sent_message_link 0xe9db4a3f -#define CODE_input_geo_chat 0x74d456fa -#define CODE_input_notify_geo_chat_peer 0x4d8ddec8 -#define CODE_geo_chat 0x75eaea5a -#define CODE_geo_chat_message_empty 0x60311a9b -#define CODE_geo_chat_message 0x4505f8e1 -#define CODE_geo_chat_message_service 0xd34fa24e -#define CODE_geochats_stated_message 0x17b1578b -#define CODE_geochats_located 0x48feb267 -#define CODE_geochats_messages 0xd1526db1 -#define CODE_geochats_messages_slice 0xbc5863e8 -#define CODE_message_action_geo_chat_create 0x6f038ebc -#define CODE_message_action_geo_chat_checkin 0xc7d53de -#define CODE_update_new_geo_chat_message 0x5a68e3f7 -#define CODE_wall_paper_solid 0x63117f24 -#define CODE_update_new_encrypted_message 0x12bcbd9a -#define CODE_update_encrypted_chat_typing 0x1710f156 -#define CODE_update_encryption 0xb4a2e88d -#define CODE_update_encrypted_messages_read 0x38fe25b7 -#define CODE_encrypted_chat_empty 0xab7ec0a0 -#define CODE_encrypted_chat_waiting 0x3bf703dc -#define CODE_encrypted_chat_requested 0xc878527e -#define CODE_encrypted_chat 0xfa56ce36 -#define CODE_encrypted_chat_discarded 0x13d6dd27 -#define CODE_input_encrypted_chat 0xf141b5e1 -#define CODE_encrypted_file_empty 0xc21f497e -#define CODE_encrypted_file 0x4a70994c -#define CODE_input_encrypted_file_empty 0x1837c364 -#define CODE_input_encrypted_file_uploaded 0x64bd0306 -#define CODE_input_encrypted_file 0x5a17b5e5 -#define CODE_input_encrypted_file_location 0xf5235d55 -#define CODE_encrypted_message 0xed18c118 -#define CODE_encrypted_message_service 0x23734b06 -#define CODE_decrypted_message_layer 0x99a438cf -#define CODE_decrypted_message 0x1f814f1f -#define CODE_decrypted_message_service 0xaa48327d -#define CODE_decrypted_message_media_empty 0x89f5c4a -#define CODE_decrypted_message_media_photo 0x32798a8c -#define CODE_decrypted_message_media_video 0x4cee6ef3 -#define CODE_decrypted_message_media_geo_point 0x35480a59 -#define CODE_decrypted_message_media_contact 0x588a0a97 -#define CODE_decrypted_message_action_set_message_t_t_l 0xa1733aec -#define CODE_messages_dh_config_not_modified 0xc0e24635 -#define CODE_messages_dh_config 0x2c221edd -#define CODE_messages_sent_encrypted_message 0x560f8935 -#define CODE_messages_sent_encrypted_file 0x9493ff32 -#define CODE_input_file_big 0xfa4f0bb5 -#define CODE_input_encrypted_file_big_uploaded 0x2dc173c8 -#define CODE_update_chat_participant_add 0x3a0eeb22 -#define CODE_update_chat_participant_delete 0x6e5f8c22 -#define CODE_update_dc_options 0x8e5e9873 -#define CODE_input_media_uploaded_audio 0x61a6d436 -#define CODE_input_media_audio 0x89938781 -#define CODE_input_media_uploaded_document 0x34e794bd -#define CODE_input_media_uploaded_thumb_document 0x3e46de5d -#define CODE_input_media_document 0xd184e841 -#define CODE_message_media_document 0x2fda2204 -#define CODE_message_media_audio 0xc6b68300 -#define CODE_input_audio_empty 0xd95adc84 -#define CODE_input_audio 0x77d440ff -#define CODE_input_document_empty 0x72f0eaae -#define CODE_input_document 0x18798952 -#define CODE_input_audio_file_location 0x74dc404d -#define CODE_input_document_file_location 0x4e45abe9 -#define CODE_decrypted_message_media_document 0xb095434b -#define CODE_decrypted_message_media_audio 0x6080758f -#define CODE_audio_empty 0x586988d8 -#define CODE_audio 0x427425e7 -#define CODE_document_empty 0x36f8c871 -#define CODE_document 0x9efc6326 -#define CODE_invoke_after_msg 0xcb9f372d -#define CODE_invoke_after_msgs 0x3dc4b4f0 -#define CODE_invoke_with_layer1 0x53835315 -#define CODE_auth_check_phone 0x6fe51dfb -#define CODE_auth_send_code 0x768d5f4d -#define CODE_auth_send_call 0x3c51564 -#define CODE_auth_sign_up 0x1b067634 -#define CODE_auth_sign_in 0xbcd51581 -#define CODE_auth_log_out 0x5717da40 -#define CODE_auth_reset_authorizations 0x9fab0d1a -#define CODE_auth_send_invites 0x771c1d97 -#define CODE_auth_export_authorization 0xe5bfffcd -#define CODE_auth_import_authorization 0xe3ef9613 -#define CODE_account_register_device 0x446c712c -#define CODE_account_unregister_device 0x65c55b40 -#define CODE_account_update_notify_settings 0x84be5b93 -#define CODE_account_get_notify_settings 0x12b3ad31 -#define CODE_account_reset_notify_settings 0xdb7e1747 -#define CODE_account_update_profile 0xf0888d68 -#define CODE_account_update_status 0x6628562c -#define CODE_account_get_wall_papers 0xc04cfac2 -#define CODE_users_get_users 0xd91a548 -#define CODE_users_get_full_user 0xca30a5b1 -#define CODE_contacts_get_statuses 0xc4a353ee -#define CODE_contacts_get_contacts 0x22c6aa08 -#define CODE_contacts_import_contacts 0xda30b32d -#define CODE_contacts_search 0x11f812d8 -#define CODE_contacts_get_suggested 0xcd773428 -#define CODE_contacts_delete_contact 0x8e953744 -#define CODE_contacts_delete_contacts 0x59ab389e -#define CODE_contacts_block 0x332b49fc -#define CODE_contacts_unblock 0xe54100bd -#define CODE_contacts_get_blocked 0xf57c350f -#define CODE_messages_get_messages 0x4222fa74 -#define CODE_messages_get_dialogs 0xeccf1df6 -#define CODE_messages_get_history 0x92a1df2f -#define CODE_messages_search 0x7e9f2ab -#define CODE_messages_read_history 0xb04f2510 -#define CODE_messages_delete_history 0xf4f8fb61 -#define CODE_messages_delete_messages 0x14f2dd0a -#define CODE_messages_restore_messages 0x395f9d7e -#define CODE_messages_received_messages 0x28abcb68 -#define CODE_messages_set_typing 0x719839e9 -#define CODE_messages_send_message 0x4cde0aab -#define CODE_messages_send_media 0xa3c85d76 -#define CODE_messages_forward_messages 0x514cd10f -#define CODE_messages_get_chats 0x3c6aa187 -#define CODE_messages_get_full_chat 0x3b831c66 -#define CODE_messages_edit_chat_title 0xb4bc68b5 -#define CODE_messages_edit_chat_photo 0xd881821d -#define CODE_messages_add_chat_user 0x2ee9ee9e -#define CODE_messages_delete_chat_user 0xc3c5cd23 -#define CODE_messages_create_chat 0x419d9aee -#define CODE_updates_get_state 0xedd4882a -#define CODE_updates_get_difference 0xa041495 -#define CODE_photos_update_profile_photo 0xeef579a0 -#define CODE_photos_upload_profile_photo 0xd50f9c88 -#define CODE_upload_save_file_part 0xb304a621 -#define CODE_upload_get_file 0xe3a6cfb5 -#define CODE_help_get_config 0xc4f9186b -#define CODE_help_get_nearest_dc 0x1fb33026 -#define CODE_help_get_app_update 0xc812ac7e -#define CODE_help_save_app_log 0x6f02f748 -#define CODE_help_get_invite_text 0xa4a95186 -#define CODE_photos_get_user_photos 0xb7ee553c -#define CODE_invoke_with_layer2 0x289dd1f6 -#define CODE_messages_forward_message 0x3f3f4f2 -#define CODE_messages_send_broadcast 0x41bb0972 -#define CODE_invoke_with_layer3 0xb7475268 -#define CODE_geochats_get_located 0x7f192d8f -#define CODE_geochats_get_recents 0xe1427e6f -#define CODE_geochats_checkin 0x55b3e8fb -#define CODE_geochats_get_full_chat 0x6722dd6f -#define CODE_geochats_edit_chat_title 0x4c8e2273 -#define CODE_geochats_edit_chat_photo 0x35d81a95 -#define CODE_geochats_search 0xcfcdc44d -#define CODE_geochats_get_history 0xb53f7a68 -#define CODE_geochats_set_typing 0x8b8a729 -#define CODE_geochats_send_message 0x61b0044 -#define CODE_geochats_send_media 0xb8f0deff -#define CODE_geochats_create_geo_chat 0xe092e16 -#define CODE_invoke_with_layer4 0xdea0d430 -#define CODE_invoke_with_layer5 0x417a57ae -#define CODE_invoke_with_layer6 0x3a64d54d -#define CODE_invoke_with_layer7 0xa5be56d3 -#define CODE_messages_get_dh_config 0x26cf8950 -#define CODE_messages_request_encryption 0xf64daf43 -#define CODE_messages_accept_encryption 0x3dbc0415 -#define CODE_messages_discard_encryption 0xedd923c5 -#define CODE_messages_set_encrypted_typing 0x791451ed -#define CODE_messages_read_encrypted_history 0x7f4b690a -#define CODE_messages_send_encrypted 0xa9776773 -#define CODE_messages_send_encrypted_file 0x9a901b66 -#define CODE_messages_send_encrypted_service 0x32d439a4 -#define CODE_messages_received_queue 0x55a5bb66 -#define CODE_invoke_with_layer8 0xe9abd9fd -#define CODE_upload_save_big_file_part 0xde7b673d -#define CODE_init_connection 0x69796de9 -#define CODE_invoke_with_layer9 0x76715a63 -#define CODE_invoke_with_layer10 0x39620c41 -#define CODE_invoke_with_layer11 0xa6b88fdf -#define CODE_invoke_with_layer12 0xdda60d3c -#endif diff --git a/lua-tg.c b/lua-tg.c index 1d7b6e9..fd9a12d 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -17,7 +17,7 @@ lua_State *luaState; #include "structures.h" #include "interface.h" -#include "constants.h" +#include "auto/constants.h" #include "tools.h" #include "queries.h" #include "net.h" diff --git a/mtproto-client.c b/mtproto-client.c index 221a478..be22d01 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -1409,7 +1409,7 @@ void work_update_short (struct connection *c, long long msg_id) { void work_updates (struct connection *c, long long msg_id) { int *save = in_ptr; - assert (!skip_type_any (&(struct paramed_type) {.type = &tl_type_Updates, .params=0})); + assert (!skip_type_any (TYPE_TO_PARAM (Updates))); int *save_end = in_ptr; in_ptr = save; assert (fetch_int () == CODE_updates); diff --git a/mtproto-common.h b/mtproto-common.h index 619be74..dcec745 100644 --- a/mtproto-common.h +++ b/mtproto-common.h @@ -28,7 +28,7 @@ #include "interface.h" #include "tools.h" -#include "constants.h" +#include "auto/constants.h" /* DH key exchange protocol data structures */ #define CODE_req_pq 0x60469778 #define CODE_resPQ 0x05162463 @@ -323,6 +323,17 @@ static inline void fetch_ints (void *data, int count) { memcpy (data, in_ptr, 4 * count); in_ptr += count; } + +static inline void fetch256 (void *buf) { + int l = prefetch_strlen (); + assert (l >= 0); + char *s = fetch_str (l); + if (l < 256) { + memcpy (buf + 256 - l, s, l); + } else { + memcpy (buf, s + (l - 256), 256); + } +} int get_random_bytes (unsigned char *buf, int n); diff --git a/queries.c b/queries.c index ebeec77..2a258dd 100644 --- a/queries.c +++ b/queries.c @@ -1324,15 +1324,18 @@ int send_encr_file_on_answer (struct query *q UU) { } struct query_methods send_file_part_methods = { - .on_answer = send_file_part_on_answer + .on_answer = send_file_part_on_answer, + .type = TYPE_TO_PARAM(Bool) }; struct query_methods send_file_methods = { - .on_answer = send_file_on_answer + .on_answer = send_file_on_answer, + .type = TYPE_TO_PARAM(messages_StatedMessage) }; struct query_methods send_encr_file_methods = { - .on_answer = send_encr_file_on_answer + .on_answer = send_encr_file_on_answer, + .type = TYPE_TO_PARAM(messages_SentEncryptedMessage) }; void send_part (struct send_file *f) { @@ -1614,7 +1617,8 @@ int fwd_msg_on_answer (struct query *q UU) { } struct query_methods fwd_msg_methods = { - .on_answer = fwd_msg_on_answer + .on_answer = fwd_msg_on_answer, + .type = TYPE_TO_PARAM(messages_StatedMessage) }; void do_forward_message (peer_id_t id, int n) { @@ -1653,7 +1657,8 @@ int rename_chat_on_answer (struct query *q UU) { } struct query_methods rename_chat_methods = { - .on_answer = rename_chat_on_answer + .on_answer = rename_chat_on_answer, + .type = TYPE_TO_PARAM(messages_StatedMessage) }; void do_rename_chat (peer_id_t id, char *name UU) { @@ -1698,7 +1703,8 @@ int chat_info_on_answer (struct query *q UU) { } struct query_methods chat_info_methods = { - .on_answer = chat_info_on_answer + .on_answer = chat_info_on_answer, + .type = TYPE_TO_PARAM(messages_ChatFull) }; void do_get_chat_info (peer_id_t id) { @@ -1748,7 +1754,8 @@ int user_info_on_answer (struct query *q UU) { } struct query_methods user_info_methods = { - .on_answer = user_info_on_answer + .on_answer = user_info_on_answer, + .type = TYPE_TO_PARAM(UserFull) }; void do_get_user_info (peer_id_t id) { @@ -1789,7 +1796,8 @@ int user_list_info_silent_on_answer (struct query *q UU) { } struct query_methods user_list_info_silent_methods = { - .on_answer = user_list_info_silent_on_answer + .on_answer = user_list_info_silent_on_answer, + .type = TYPE_TO_PARAM_1(Vector, TYPE_TO_PARAM(User)) }; void do_get_user_list_info_silent (int num, int *list) { @@ -1891,7 +1899,8 @@ int download_on_answer (struct query *q) { } struct query_methods download_methods = { - .on_answer = download_on_answer + .on_answer = download_on_answer, + .type = TYPE_TO_PARAM(upload_File) }; void load_next_part (struct download *D) { @@ -2092,7 +2101,8 @@ int export_auth_on_answer (struct query *q UU) { struct query_methods export_auth_methods = { .on_answer = export_auth_on_answer, - .on_error = fail_on_error + .on_error = fail_on_error, + .type = TYPE_TO_PARAM(auth_ExportedAuthorization) }; void do_export_auth (int num) { @@ -2117,7 +2127,8 @@ int import_auth_on_answer (struct query *q UU) { struct query_methods import_auth_methods = { .on_answer = import_auth_on_answer, - .on_error = fail_on_error + .on_error = fail_on_error, + .type = TYPE_TO_PARAM(auth_Authorization) }; void do_import_auth (int num) { @@ -2183,6 +2194,7 @@ int add_contact_on_answer (struct query *q UU) { struct query_methods add_contact_methods = { .on_answer = add_contact_on_answer, + .type = TYPE_TO_PARAM(contacts_ImportedContacts) }; void do_add_contact (const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, int force) { @@ -2206,7 +2218,8 @@ int msg_search_on_answer (struct query *q UU) { } struct query_methods msg_search_methods = { - .on_answer = msg_search_on_answer + .on_answer = msg_search_on_answer, + .type = TYPE_TO_PARAM(messages_Messages) }; void do_msg_search (peer_id_t id, int from, int to, int limit, const char *s) { @@ -2260,7 +2273,8 @@ int contacts_search_on_answer (struct query *q UU) { } struct query_methods contacts_search_methods = { - .on_answer = contacts_search_on_answer + .on_answer = contacts_search_on_answer, + .type = TYPE_TO_PARAM(contacts_Found) }; void do_contacts_search (int limit, const char *s) { @@ -2321,11 +2335,13 @@ int send_encr_request_on_answer (struct query *q UU) { } struct query_methods send_encr_accept_methods = { - .on_answer = send_encr_accept_on_answer + .on_answer = send_encr_accept_on_answer, + .type = TYPE_TO_PARAM(EncryptedChat) }; struct query_methods send_encr_request_methods = { - .on_answer = send_encr_request_on_answer + .on_answer = send_encr_request_on_answer, + .type = TYPE_TO_PARAM(EncryptedChat) }; int encr_root; @@ -2544,7 +2560,8 @@ int get_dh_config_on_answer (struct query *q UU) { } struct query_methods get_dh_config_methods = { - .on_answer = get_dh_config_on_answer + .on_answer = get_dh_config_on_answer, + .type = TYPE_TO_PARAM(messages_DhConfig) }; void do_accept_encr_chat_request (struct secret_chat *E) { @@ -2655,11 +2672,13 @@ int get_difference_on_answer (struct query *q UU) { } struct query_methods get_state_methods = { - .on_answer = get_state_on_answer + .on_answer = get_state_on_answer, + .type = TYPE_TO_PARAM(updates_State) }; struct query_methods get_difference_methods = { - .on_answer = get_difference_on_answer + .on_answer = get_difference_on_answer, + .type = TYPE_TO_PARAM(updates_Difference) }; void do_get_difference (void) { @@ -2746,7 +2765,8 @@ int get_suggested_on_answer (struct query *q UU) { } struct query_methods get_suggested_methods = { - .on_answer = get_suggested_on_answer + .on_answer = get_suggested_on_answer, + .type = TYPE_TO_PARAM(contacts_Suggested) }; void do_get_suggested (void) { @@ -2760,7 +2780,8 @@ void do_get_suggested (void) { /* {{{ Add user to chat */ struct query_methods add_user_to_chat_methods = { - .on_answer = fwd_msg_on_answer + .on_answer = fwd_msg_on_answer, + .type = TYPE_TO_PARAM(MessageAction) }; void do_add_user_to_chat (peer_id_t chat_id, peer_id_t id, int limit) { @@ -2818,7 +2839,8 @@ void do_create_secret_chat (peer_id_t id) { /* {{{ Create group chat */ struct query_methods create_group_chat_methods = { - .on_answer = fwd_msg_on_answer + .on_answer = fwd_msg_on_answer, + .type = TYPE_TO_PARAM(MessageAction) }; void do_create_group_chat (peer_id_t id, char *chat_topic) { @@ -2857,7 +2879,8 @@ int delete_msg_on_answer (struct query *q UU) { } struct query_methods delete_msg_methods = { - .on_answer = delete_msg_on_answer + .on_answer = delete_msg_on_answer, + .type = TYPE_TO_PARAM_1(Vector, TYPE_TO_PARAM (bare_Int)) }; void do_delete_msg (long long id) { @@ -2881,7 +2904,8 @@ int restore_msg_on_answer (struct query *q UU) { } struct query_methods restore_msg_methods = { - .on_answer = restore_msg_on_answer + .on_answer = restore_msg_on_answer, + .type = TYPE_TO_PARAM_1(Vector, TYPE_TO_PARAM (bare_Int)) }; void do_restore_msg (long long id) { @@ -2899,7 +2923,8 @@ int update_status_on_answer (struct query *q UU) { } struct query_methods update_status_methods = { - .on_answer = update_status_on_answer + .on_answer = update_status_on_answer, + .type = TYPE_TO_PARAM(Bool) }; void do_update_status (int online UU) { diff --git a/structures.c b/structures.c index 687155e..6586ffd 100644 --- a/structures.c +++ b/structures.c @@ -67,84 +67,6 @@ peer_t *Peers[MAX_PEER_NUM]; extern int binlog_enabled; -void fetch_skip_photo (void); - -#define code_assert(x) if (!(x)) { logprintf ("Can not parse at line %d\n", __LINE__); assert (0); return -1; } -#define code_try(x) if ((x) == -1) { return -1; } - -/* - * - * Fetch simple structures (immediate fetch into buffer) - * - */ - -int fetch_file_location (struct file_location *loc) { - int x = fetch_int (); - code_assert (x == CODE_file_location_unavailable || x == CODE_file_location); - - if (x == CODE_file_location_unavailable) { - loc->dc = -1; - loc->volume = fetch_long (); - loc->local_id = fetch_int (); - loc->secret = fetch_long (); - } else { - loc->dc = fetch_int (); - loc->volume = fetch_long (); - loc->local_id = fetch_int (); - loc->secret = fetch_long (); - } - return 0; -} - -int fetch_user_status (struct user_status *S) { - unsigned x = fetch_int (); - code_assert (x == CODE_user_status_empty || x == CODE_user_status_online || x == CODE_user_status_offline); - switch (x) { - case CODE_user_status_empty: - S->online = 0; - S->when = 0; - break; - case CODE_user_status_online: - S->online = 1; - S->when = fetch_int (); - break; - case CODE_user_status_offline: - S->online = -1; - S->when = fetch_int (); - break; - default: - assert (0); - } - return 0; -} - -/* - * - * Skip simple structures - * - */ - -int fetch_skip_file_location (void) { - int x = fetch_int (); - code_assert (x == CODE_file_location_unavailable || x == CODE_file_location); - - if (x == CODE_file_location_unavailable) { - in_ptr += 5; - } else { - in_ptr += 6; - } - return 0; -} - -int fetch_skip_user_status (void) { - unsigned x = fetch_int (); - code_assert (x == CODE_user_status_empty || x == CODE_user_status_online || x == CODE_user_status_offline); - if (x != CODE_user_status_empty) { - fetch_int (); - } - return 0; -} - char *create_print_name (peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4) { const char *d[4]; d[0] = a1; d[1] = a2; d[2] = a3; d[3] = a4; @@ -178,6 +100,52 @@ char *create_print_name (peer_id_t id, const char *a1, const char *a2, const cha return tstrdup (s); } +/* + * + * Fetch simple structures (immediate fetch into buffer) + * + */ + +int fetch_file_location (struct file_location *loc) { + int x = fetch_int (); + assert (x == CODE_file_location_unavailable || x == CODE_file_location); + + if (x == CODE_file_location_unavailable) { + loc->dc = -1; + loc->volume = fetch_long (); + loc->local_id = fetch_int (); + loc->secret = fetch_long (); + } else { + loc->dc = fetch_int (); + loc->volume = fetch_long (); + loc->local_id = fetch_int (); + loc->secret = fetch_long (); + } + return 0; +} + +int fetch_user_status (struct user_status *S) { + unsigned x = fetch_int (); + assert (x == CODE_user_status_empty || x == CODE_user_status_online || x == CODE_user_status_offline); + switch (x) { + case CODE_user_status_empty: + S->online = 0; + S->when = 0; + break; + case CODE_user_status_online: + S->online = 1; + S->when = fetch_int (); + break; + case CODE_user_status_offline: + S->online = -1; + S->when = fetch_int (); + break; + default: + assert (0); + } + return 0; +} + /* * * Fetch with log event @@ -186,7 +154,7 @@ char *create_print_name (peer_id_t id, const char *a1, const char *a2, const cha long long fetch_user_photo (struct user *U) { unsigned x = fetch_int (); - code_assert (x == CODE_user_profile_photo || x == CODE_user_profile_photo_old || x == CODE_user_profile_photo_empty); + assert (x == CODE_user_profile_photo || x == CODE_user_profile_photo_old || x == CODE_user_profile_photo_empty); if (x == CODE_user_profile_photo_empty) { bl_do_set_user_profile_photo (U, 0, 0, 0); return 0; @@ -195,10 +163,10 @@ long long fetch_user_photo (struct user *U) { if (x == CODE_user_profile_photo) { photo_id = fetch_long (); } - struct file_location big; - struct file_location small; - code_try (fetch_file_location (&small)); - code_try (fetch_file_location (&big)); + static struct file_location big; + static struct file_location small; + assert (fetch_file_location (&small) >= 0); + assert (fetch_file_location (&big) >= 0); bl_do_set_user_profile_photo (U, photo_id, &big, &small); return 0; @@ -206,7 +174,7 @@ long long fetch_user_photo (struct user *U) { int fetch_user (struct user *U) { unsigned x = fetch_int (); - code_assert (x == CODE_user_empty || x == CODE_user_self || x == CODE_user_contact || x == CODE_user_request || x == CODE_user_foreign || x == CODE_user_deleted); + assert (x == CODE_user_empty || x == CODE_user_self || x == CODE_user_contact || x == CODE_user_request || x == CODE_user_foreign || x == CODE_user_deleted); U->id = MK_USER (fetch_int ()); if (x == CODE_user_empty) { return 0; @@ -220,16 +188,13 @@ int fetch_user (struct user *U) { } } - int new = 0; - if (!(U->flags & FLAG_CREATED)) { - new = 1; - } + int new = !(U->flags & FLAG_CREATED); if (new) { int l1 = prefetch_strlen (); - code_assert (l1 >= 0); + assert (l1 >= 0); char *s1 = fetch_str (l1); int l2 = prefetch_strlen (); - code_assert (l2 >= 0); + assert (l2 >= 0); char *s2 = fetch_str (l2); if (x == CODE_user_deleted && !(U->flags & FLAG_DELETED)) { @@ -245,7 +210,7 @@ int fetch_user (struct user *U) { char *phone = 0; if (x != CODE_user_foreign) { phone_len = prefetch_strlen (); - code_assert (phone_len >= 0); + assert (phone_len >= 0); phone = fetch_str (phone_len); } bl_do_new_user (get_peer_id (U->id), s1, l1, s2, l2, access_token, phone, phone_len, x == CODE_user_contact); @@ -276,7 +241,7 @@ int fetch_user (struct user *U) { char *s = fetch_str (l); bl_do_set_user_phone (U, s, l); } - if (fetch_user_photo (U) < 0) { return -1; } + assert (fetch_user_photo (U) >= 0); fetch_user_status (&U->status); if (x == CODE_user_self) { @@ -326,26 +291,9 @@ void fetch_encrypted_chat (struct secret_chat *U) { } if (x == CODE_encrypted_chat_requested || x == CODE_encrypted_chat) { memset (g_key, 0, sizeof (g_key)); - memset (nonce, 0, sizeof (nonce)); } - - int l = prefetch_strlen (); - char *s = fetch_str (l); - if (l != 256) { logprintf ("l = %d\n", l); } - if (l < 256) { - memcpy (g_key + 256 - l, s, l); - } else { - memcpy (g_key, s + (l - 256), 256); - } - - /*l = prefetch_strlen (); - s = fetch_str (l); - if (l != 256) { logprintf ("l = %d\n", l); } - if (l < 256) { - memcpy (nonce + 256 - l, s, l); - } else { - memcpy (nonce, s + (l - 256), 256); - }*/ + + fetch256 (g_key); if (x == CODE_encrypted_chat) { fetch_long (); // fingerprint @@ -377,27 +325,10 @@ void fetch_encrypted_chat (struct secret_chat *U) { if (x == CODE_encrypted_chat_requested || x == CODE_encrypted_chat) { memset (g_key, 0, sizeof (g_key)); - memset (nonce, 0, sizeof (nonce)); } - - int l = prefetch_strlen (); - char *s = fetch_str (l); - if (l != 256) { logprintf ("l = %d\n", l); } - if (l < 256) { - memcpy (g_key + 256 - l, s, l); - } else { - memcpy (g_key, s + (l - 256), 256); - } - - /*l = prefetch_strlen (); - s = fetch_str (l); - if (l != 256) { logprintf ("l = %d\n", l); } - if (l < 256) { - memcpy (nonce + 256 - l, s, l); - } else { - memcpy (nonce, s + (l - 256), 256); - }*/ + fetch256 (g_key); + if (x == CODE_encrypted_chat_requested) { return; // Duplicate? } @@ -406,30 +337,17 @@ void fetch_encrypted_chat (struct secret_chat *U) { write_secret_chat_file (); } -void fetch_notify_settings (void); void fetch_user_full (struct user *U) { assert (fetch_int () == CODE_user_full); fetch_alloc_user (); - unsigned x; - assert (fetch_int () == (int)CODE_contacts_link); - x = fetch_int (); - assert (x == CODE_contacts_my_link_empty || x == CODE_contacts_my_link_requested || x == CODE_contacts_my_link_contact); - if (x == CODE_contacts_my_link_requested) { - fetch_bool (); - } - x = fetch_int (); - assert (x == CODE_contacts_foreign_link_unknown || x == CODE_contacts_foreign_link_requested || x == CODE_contacts_foreign_link_mutual); - if (x == CODE_contacts_foreign_link_requested) { - fetch_bool (); - } - fetch_alloc_user (); + assert (skip_type_any (TYPE_TO_PARAM (contacts_Link)) >= 0); int *start = in_ptr; - fetch_skip_photo (); + assert (skip_type_any (TYPE_TO_PARAM (Photo)) >= 0); bl_do_set_user_full_photo (U, start, 4 * (in_ptr - start)); - fetch_notify_settings (); - + assert (skip_type_any (TYPE_TO_PARAM (PeerNotifySettings)) >= 0); + bl_do_set_user_blocked (U, fetch_bool ()); int l1 = prefetch_strlen (); char *s1 = fetch_str (l1); @@ -523,25 +441,6 @@ void fetch_chat (struct chat *C) { } } -void fetch_notify_settings (void) { - unsigned x = fetch_int (); - assert (x == CODE_peer_notify_settings || x == CODE_peer_notify_settings_empty || x == CODE_peer_notify_settings_old); - if (x == CODE_peer_notify_settings_old) { - fetch_int (); // mute_until - int l = prefetch_strlen (); - fetch_str (l); - fetch_bool (); // show_previews - fetch_int (); // peer notify events - } - if (x == CODE_peer_notify_settings) { - fetch_int (); // mute_until - int l = prefetch_strlen (); - fetch_str (l); - fetch_bool (); // show_previews - fetch_int (); // events_mask - } -} - void fetch_chat_full (struct chat *C) { unsigned x = fetch_int (); assert (x == CODE_messages_chat_full); @@ -571,9 +470,9 @@ void fetch_chat_full (struct chat *C) { version = fetch_int (); } int *start = in_ptr; - fetch_skip_photo (); + assert (skip_type_any (TYPE_TO_PARAM (Photo)) >= 0); int *end = in_ptr; - fetch_notify_settings (); + assert (skip_type_any (TYPE_TO_PARAM (PeerNotifySettings)) >= 0); int n, i; assert (fetch_int () == CODE_vector); @@ -616,23 +515,6 @@ void fetch_photo_size (struct photo_size *S) { } } -void fetch_skip_photo_size (void) { - unsigned x = fetch_int (); - assert (x == CODE_photo_size || x == CODE_photo_cached_size || x == CODE_photo_size_empty); - int l = prefetch_strlen (); - fetch_str (l); // type - if (x != CODE_photo_size_empty) { - fetch_skip_file_location (); - in_ptr += 2; // w, h - if (x == CODE_photo_size) { - in_ptr ++; - } else { - l = prefetch_strlen (); - fetch_str (l); - } - } -} - void fetch_geo (struct geo *G) { unsigned x = fetch_int (); if (x == CODE_geo_point) { @@ -645,14 +527,6 @@ void fetch_geo (struct geo *G) { } } -void fetch_skip_geo (void) { - unsigned x = fetch_int (); - assert (x == CODE_geo_point || x == CODE_geo_point_empty); - if (x == CODE_geo_point) { - in_ptr += 4; - } -} - void fetch_photo (struct photo *P) { memset (P, 0, sizeof (*P)); unsigned x = fetch_int (); @@ -673,23 +547,6 @@ void fetch_photo (struct photo *P) { } } -void fetch_skip_photo (void) { - unsigned x = fetch_int (); - assert (x == CODE_photo_empty || x == CODE_photo); - in_ptr += 2; // id - if (x == CODE_photo_empty) { return; } - in_ptr += 2 +1 + 1; // access_hash, user_id, date - int l = prefetch_strlen (); - fetch_str (l); // caption - fetch_skip_geo (); - assert (fetch_int () == CODE_vector); - int n = fetch_int (); - int i; - for (i = 0; i < n; i++) { - fetch_skip_photo_size (); - } -} - void fetch_video (struct video *V) { memset (V, 0, sizeof (*V)); unsigned x = fetch_int (); @@ -707,18 +564,6 @@ void fetch_video (struct video *V) { V->h = fetch_int (); } -void fetch_skip_video (void) { - unsigned x = fetch_int (); - fetch_long (); - if (x == CODE_video_empty) { return; } - fetch_skip (4); - int l = prefetch_strlen (); - fetch_str (l); - fetch_skip (2); - fetch_skip_photo_size (); - fetch_skip (3); -} - void fetch_audio (struct audio *V) { memset (V, 0, sizeof (*V)); unsigned x = fetch_int (); @@ -732,13 +577,6 @@ void fetch_audio (struct audio *V) { V->dc_id = fetch_int (); } -void fetch_skip_audio (void) { - unsigned x = fetch_int (); - fetch_skip (2); - if (x == CODE_audio_empty) { return; } - fetch_skip (7); -} - void fetch_document (struct document *V) { memset (V, 0, sizeof (*V)); unsigned x = fetch_int (); @@ -754,20 +592,6 @@ void fetch_document (struct document *V) { V->dc_id = fetch_int (); } -void fetch_skip_document (void) { - unsigned x = fetch_int (); - fetch_skip (2); - if (x == CODE_document_empty) { return; } - fetch_skip (4); - int l = prefetch_strlen (); - fetch_str (l); - l = prefetch_strlen (); - fetch_str (l); - fetch_skip (1); - fetch_skip_photo_size (); - fetch_skip (1); -} - void fetch_message_action (struct message_action *M) { memset (M, 0, sizeof (*M)); unsigned x = fetch_int (); @@ -812,49 +636,6 @@ void fetch_message_action (struct message_action *M) { } } -void fetch_skip_message_action (void) { - unsigned x = fetch_int (); - int l; - switch (x) { - case CODE_message_action_empty: - break; - case CODE_message_action_geo_chat_create: - { - l = prefetch_strlen (); - fetch_str (l); - l = prefetch_strlen (); - fetch_str (l); - } - break; - case CODE_message_action_geo_chat_checkin: - break; - case CODE_message_action_chat_create: - l = prefetch_strlen (); - fetch_str (l); - assert (fetch_int () == (int)CODE_vector); - l = fetch_int (); - fetch_skip (l); - break; - case CODE_message_action_chat_edit_title: - l = prefetch_strlen (); - fetch_str (l); - break; - case CODE_message_action_chat_edit_photo: - fetch_skip_photo (); - break; - case CODE_message_action_chat_delete_photo: - break; - case CODE_message_action_chat_add_user: - fetch_int (); - break; - case CODE_message_action_chat_delete_user: - fetch_int (); - break; - default: - assert (0); - } -} - void fetch_message_short (struct message *M) { int new = !(M->flags & FLAG_CREATED); @@ -951,124 +732,6 @@ void fetch_message_media (struct message_media *M) { } } -void fetch_skip_message_media (void) { - unsigned x = fetch_int (); - switch (x) { - case CODE_message_media_empty: - break; - case CODE_message_media_photo: - fetch_skip_photo (); - break; - case CODE_message_media_video: - fetch_skip_video (); - break; - case CODE_message_media_audio: - fetch_skip_audio (); - break; - case CODE_message_media_document: - fetch_skip_document (); - break; - case CODE_message_media_geo: - fetch_skip_geo (); - break; - case CODE_message_media_contact: - { - int l; - l = prefetch_strlen (); - fetch_str (l); - l = prefetch_strlen (); - fetch_str (l); - l = prefetch_strlen (); - fetch_str (l); - fetch_int (); - } - break; - case CODE_message_media_unsupported: - { - int l = prefetch_strlen (); - fetch_str (l); - } - break; - default: - logprintf ("type = 0x%08x\n", x); - assert (0); - } -} - -void fetch_skip_message_media_encrypted (void) { - unsigned x = fetch_int (); - int l; - switch (x) { - case CODE_decrypted_message_media_empty: - break; - case CODE_decrypted_message_media_photo: - l = prefetch_strlen (); - fetch_str (l); // thumb - fetch_skip (5); - - l = prefetch_strlen (); - fetch_str (l); - - l = prefetch_strlen (); - fetch_str (l); - break; - case CODE_decrypted_message_media_video: - l = prefetch_strlen (); - fetch_str (l); // thumb - - fetch_skip (6); - - l = prefetch_strlen (); - fetch_str (l); - - l = prefetch_strlen (); - fetch_str (l); - break; - case CODE_decrypted_message_media_audio: - fetch_skip (2); - - l = prefetch_strlen (); - fetch_str (l); - - l = prefetch_strlen (); - fetch_str (l); - break; - case CODE_decrypted_message_media_document: - l = prefetch_strlen (); - fetch_str (l); // thumb - - fetch_skip (2); - - l = prefetch_strlen (); - fetch_str (l); // thumb - l = prefetch_strlen (); - fetch_str (l); // thumb - fetch_skip (1); - - l = prefetch_strlen (); - fetch_str (l); - - l = prefetch_strlen (); - fetch_str (l); - break; - case CODE_decrypted_message_media_geo_point: - fetch_skip (4); - break; - case CODE_decrypted_message_media_contact: - l = prefetch_strlen (); - fetch_str (l); // thumb - l = prefetch_strlen (); - fetch_str (l); // thumb - l = prefetch_strlen (); - fetch_str (l); // thumb - fetch_skip (1); - break; - default: - logprintf ("type = 0x%08x\n", x); - assert (0); - } -} - void fetch_message_media_encrypted (struct message_media *M) { memset (M, 0, sizeof (*M)); unsigned x = fetch_int (); @@ -1218,18 +881,6 @@ void fetch_message_media_encrypted (struct message_media *M) { } } -void fetch_skip_message_action_encrypted (void) { - unsigned x = fetch_int (); - switch (x) { - case CODE_decrypted_message_action_set_message_t_t_l: - fetch_skip (1); - break; - default: - logprintf ("x = 0x%08x\n", x); - assert (0); - } -} - void fetch_message_action_encrypted (struct message_action *M) { unsigned x = fetch_int (); switch (x) { @@ -1280,7 +931,9 @@ void fetch_message (struct message *M) { if (x == CODE_message_service) { int *start = in_ptr; - fetch_skip_message_action (); + + assert (skip_type_any (TYPE_TO_PARAM (MessageAction)) >= 0); + if (new) { if (fwd_from_id) { bl_do_create_message_service_fwd (id, from_id, get_peer_type (to_id), get_peer_id (to_id), date, fwd_from_id, fwd_date, start, (in_ptr - start)); @@ -1292,7 +945,9 @@ void fetch_message (struct message *M) { int l = prefetch_strlen (); char *s = fetch_str (l); int *start = in_ptr; - fetch_skip_message_media (); + + assert (skip_type_any (TYPE_TO_PARAM (MessageMedia)) >= 0); + if (new) { if (fwd_from_id) { bl_do_create_message_media_fwd (id, from_id, get_peer_type (to_id), get_peer_id (to_id), date, fwd_from_id, fwd_date, l, s, start, in_ptr - start); @@ -1442,11 +1097,11 @@ void fetch_encrypted_message (struct message *M) { l = prefetch_strlen (); s = fetch_str (l); start = in_ptr; - fetch_skip_message_media_encrypted (); + assert (skip_type_any (TYPE_TO_PARAM (DecryptedMessageMedia)) >= 0); end = in_ptr; } else { start = in_ptr; - fetch_skip_message_action_encrypted (); + assert (skip_type_any (TYPE_TO_PARAM (DecryptedMessageAction)) >= 0); end = in_ptr; } in_ptr = save_in_ptr; @@ -1456,7 +1111,7 @@ void fetch_encrypted_message (struct message *M) { if (sx == CODE_encrypted_message) { if (ok) { int *start_file = in_ptr; - fetch_skip_encrypted_message_file (); + assert (skip_type_any (TYPE_TO_PARAM (EncryptedFile)) >= 0); if (x == CODE_decrypted_message) { bl_do_create_message_media_encr (id, P->encr_chat.user_id, PEER_ENCR_CHAT, to_id, date, l, s, start, end - start, start_file, in_ptr - start_file); } @@ -1496,15 +1151,6 @@ void fetch_encrypted_message_file (struct message_media *M) { } } -void fetch_skip_encrypted_message_file (void) { - unsigned x = fetch_int (); - assert (x == CODE_encrypted_file || x == CODE_encrypted_file_empty); - if (x == CODE_encrypted_file_empty) { - } else { - fetch_skip (7); - } -} - static int id_cmp (struct message *M1, struct message *M2) { if (M1->id < M2->id) { return -1; } else if (M1->id > M2->id) { return 1; } diff --git a/tl-parser.c b/tl-parser.c index b6b709e..9b48b46 100644 --- a/tl-parser.c +++ b/tl-parser.c @@ -1197,6 +1197,8 @@ struct tl_constructor *tl_add_function (struct tl_type *a, const char *_id, int assert (magic && magic != (unsigned)-1); } + len = x; + struct tl_constructor _t = {.id = id}; if (tree_lookup_tl_constructor (tl_function_tree, &_t)) { TL_ERROR ("Duplicate function id `%s`\n", id); diff --git a/tools.c b/tools.c index db65476..7213d0e 100644 --- a/tools.c +++ b/tools.c @@ -139,6 +139,9 @@ void *talloc (size_t size) { *(int *)(p + RES_AFTER + 4 + size) = used_blocks; blocks[used_blocks ++] = p; + if (used_blocks - 1 == 24867) { + assert (0); + } tcheck (); return p + 8; #else