diff --git a/Makefile b/Makefile index f608ae3..11a112b 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,5 @@ $(EXE): $(OBJ) .c.o: $(CC) $(CFLAGS) $< -o $@ +clean: + rm *.o telegram || true diff --git a/constants.h b/constants.h new file mode 100644 index 0000000..2719d44 --- /dev/null +++ b/constants.h @@ -0,0 +1,253 @@ +#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 0x990d1493 +#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 0x2215bcbd +#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 0x3cf4b1be +#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 0xddbcd4a5 +#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 0xbb8ba607 +#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 0xa0d9c0c +#define CODE_updates_difference_empty 0x5d75a138 +#define CODE_updates_difference 0x8adb0077 +#define CODE_updates_difference_slice 0xc5e839b4 +#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 0x232d5905 +#define CODE_nearest_dc 0x8e1a1775 +#define CODE_help_invite_text 0x18cb9f78 +#define CODE_invoke_after_msg 0xcb9f372d +#define CODE_invoke_after_msgs 0x3dc4b4f0 +#define CODE_invoke_with_layer1 0x53835315 +#define CODE_init_connection 0x3fc12e08 +#define CODE_auth_check_phone 0x6fe51dfb +#define CODE_auth_send_code 0xd16ff372 +#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 0xa28557ac +#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 0x5b36855a +#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_save_app_log 0x6f02f748 +#define CODE_help_get_invite_text 0xa4a95186 +#endif diff --git a/mtproto-common.h b/mtproto-common.h index ac3ffc5..6c7f156 100644 --- a/mtproto-common.h +++ b/mtproto-common.h @@ -8,6 +8,7 @@ #include #include "interface.h" +#include "constants.h" /* DH key exchange protocol data structures */ #define CODE_req_pq 0x60469778 #define CODE_resPQ 0x05162463 @@ -22,18 +23,11 @@ #define CODE_dh_gen_retry 0x46dc1fb9 #define CODE_dh_gen_fail 0xa69dae02 -/* generic data structures */ -#define CODE_vector_long 0xc734a64e -#define CODE_vector_int 0xa03855ae -#define CODE_vector_Object 0xa351ae8e -#define CODE_vector 0x1cb5c415 - /* service messages */ #define CODE_rpc_result 0xf35c6d01 #define CODE_rpc_error 0x2144ca19 #define CODE_msg_container 0x73f1f8dc #define CODE_msg_copy 0xe06046b2 -#define CODE_http_wait 0x9299359f #define CODE_msgs_ack 0x62d6b459 #define CODE_bad_msg_notification 0xa7eff811 #define CODE_bad_server_salt 0xedab447b @@ -59,95 +53,6 @@ #define CODE_msg_detailed_info 0x276d3ec6 #define CODE_msg_new_detailed_info 0x809db6df #define CODE_ping_delay_disconnect 0xf3427b8c - -/* sample rpc query/response structures */ -#define CODE_getUser 0xb0f732d5 -#define CODE_getUsers 0x2d84d5f5 -#define CODE_user 0xd23c81a3 -#define CODE_no_user 0xc67599d1 - -#define CODE_msgs_random 0x12345678 -#define CODE_random_msg 0x87654321 - -#define RPC_INVOKE_REQ 0x2374df3d -#define RPC_INVOKE_KPHP_REQ 0x99a37fda -#define RPC_REQ_RUNNING 0x346d5efa -#define RPC_REQ_ERROR 0x7ae432f5 -#define RPC_REQ_RESULT 0x63aeda4e -#define RPC_READY 0x6a34cac7 -#define RPC_STOP_READY 0x59d86654 -#define RPC_SEND_SESSION_MSG 0x1ed5a3cc -#define RPC_RESPONSE_INDIRECT 0x2194f56e - -/* RPC for workers */ -#define CODE_send_session_msg 0x81bb412c -#define CODE_sendMsgOk 0x29841ee2 -#define CODE_sendMsgNoSession 0x2b2b9e78 -#define CODE_sendMsgFailed 0x4b0cbd57 -#define CODE_get_auth_sessions 0x611f7845 -#define CODE_authKeyNone 0x8a8bc1f3 -#define CODE_authKeySessions 0x6b7f026c -#define CODE_add_session_box 0xe707e295 -#define CODE_set_session_box 0x193d4231 -#define CODE_replace_session_box 0xcb101b49 -#define CODE_replace_session_box_cas 0xb2bbfa78 -#define CODE_delete_session_box 0x01b78d81 -#define CODE_delete_session_box_cas 0xb3fdc3c5 -#define CODE_session_box_no_session 0x43f46c33 -#define CODE_session_box_created 0xe1dd5d40 -#define CODE_session_box_replaced 0xbd9cb6b2 -#define CODE_session_box_deleted 0xaf8fd05e -#define CODE_session_box_not_found 0xb3560a7f -#define CODE_session_box_found 0x560fe356 -#define CODE_session_box_changed 0x014b31b8 -#define CODE_get_session_box 0x8793a924 -#define CODE_get_session_box_cond 0x7888fab6 -#define CODE_session_box_session_absent 0x9e234062 -#define CODE_session_box_absent 0xa1a106eb -#define CODE_session_box 0x7956cd97 -#define CODE_session_box_large 0xb568d189 -#define CODE_get_sessions_activity 0x059dc5f6 -#define CODE_sessions_activities 0x60ce5b1d -#define CODE_get_session_activity 0x96dbac11 -#define CODE_session_activity 0xe175e8e0 - -/* RPC for front/proxy */ -#define RPC_FRONT 0x27a456f3 -#define RPC_FRONT_ACK 0x624abd23 -#define RPC_FRONT_ERR 0x71dda175 -#define RPC_PROXY_REQ 0x36cef1ee -#define RPC_PROXY_ANS 0x4403da0d -#define RPC_CLOSE_CONN 0x1fcf425d -#define RPC_CLOSE_EXT 0x5eb634a2 -#define RPC_SIMPLE_ACK 0x3bac409b - - - -#define CODE_auth_send_code 0xd16ff372 -#define CODE_auth_sent_code 0x2215bcbd -#define CODE_help_get_config 0xc4f9186b -#define CODE_config 0x232d5905 -#define CODE_dc_option 0x2ec2a43c -#define CODE_bool_false 0xbc799737 -#define CODE_bool_true 0x997275b5 -#define CODE_user_self 0x720535ec -#define CODE_auth_authorization 0xf6b673a4 -#define CODE_user_profile_photo_empty 0x4f11bae1 -#define CODE_user_profile_photo 0x990d1493 -#define CODE_user_status_empty 0x9d05049 -#define CODE_user_status_online 0xedb93949 -#define CODE_user_status_offline 0x8c703f -#define CODE_sign_in 0xbcd51581 -#define CODE_file_location 0x53d69076 -#define CODE_file_location_unavailable 0x7c596b46 -#define CODE_contacts_get_contacts 0x22c6aa08 -#define CODE_contacts_contacts 0x6f8b8cb2 -#define CODE_contact 0xf911c994 -#define CODE_user_empty 0x200250ba -#define CODE_user_contact 0xf2fb8319 -#define CODE_user_request 0x22e8ceb0 -#define CODE_user_foreign 0x5214c89d -#define CODE_user_deleted 0xb29ad7cc #define CODE_gzip_packed 0x3072cfa1 diff --git a/queries.c b/queries.c index 893ed96..8742f13 100644 --- a/queries.c +++ b/queries.c @@ -363,7 +363,7 @@ struct query_methods sign_in_methods = { int do_send_code_result (const char *code) { clear_packet (); - out_int (CODE_sign_in); + out_int (CODE_auth_sign_in); out_string (suser); out_string (phone_code_hash); out_string (code); diff --git a/structures.c b/structures.c index e67770e..0bed6f8 100644 --- a/structures.c +++ b/structures.c @@ -101,6 +101,38 @@ void fetch_user (struct user *U) { } } +void fetch_chat (struct chat *C) { + memset (C, 0, sizeof (*C)); + unsigned x = fetch_int (); + assert (x == CODE_chat_empty || x == CODE_chat || x == CODE_chat_forbidden); + C->id = fetch_int (); + if (x == CODE_chat_empty) { + C->flags = 1; + return; + } + if (x == CODE_chat_forbidden) { + C->flags |= 8; + } + C->title = fetch_str_dup (); + C->print_title = strdup (C->title); + char *s = C->print_title; + while (*s) { + if (*s == ' ') { *s = '_'; } + s ++; + } + if (x == CODE_chat) { + unsigned y = fetch_int (); + if (y == CODE_chat_photo_empty) { + C->photo_small.dc = -2; + C->photo_big.dc = -2; + } else { + assert (y == CODE_chat_photo); + fetch_file_location (&C->photo_small); + fetch_file_location (&C->photo_big); + } + } + +} #define user_cmp(a,b) ((a)->id - (b)->id) diff --git a/structures.h b/structures.h index e3d05c1..717a5aa 100644 --- a/structures.h +++ b/structures.h @@ -27,6 +27,18 @@ struct user { struct user_status status; }; +struct chat { + int id; + int flags; + char *title; + char *print_title; + int user_num; + int date; + int version; + struct file_location photo_big; + struct file_location photo_small; +}; + void fetch_file_location (struct file_location *loc); void fetch_user (struct user *U); struct user *fetch_alloc_user (void);