diff --git a/binlog.c b/binlog.c index 543831f..810bbab 100644 --- a/binlog.c +++ b/binlog.c @@ -180,7 +180,7 @@ int fetch_comb_binlog_set_seq (void *extra) { int fetch_comb_binlog_user_add (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *_U = user_chat_get (id); + peer_t *_U = peer_get (id); if (!_U) { _U = talloc0 (sizeof (*_U)); _U->id = id; @@ -213,7 +213,7 @@ int fetch_comb_binlog_user_add (void *extra) { int fetch_comb_binlog_user_delete (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); U->flags |= FLAG_DELETED; @@ -225,7 +225,7 @@ int fetch_comb_binlog_user_delete (void *extra) { int fetch_comb_binlog_user_set_access_hash (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); U->user.access_hash = fetch_long (); @@ -237,7 +237,7 @@ int fetch_comb_binlog_user_set_access_hash (void *extra) { int fetch_comb_binlog_user_set_phone (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); if (U->user.phone) { tfree_str (U->user.phone); @@ -252,7 +252,7 @@ int fetch_comb_binlog_user_set_phone (void *extra) { int fetch_comb_binlog_user_set_friend (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); if (U->user.phone) { tfree_str (U->user.phone); @@ -269,7 +269,7 @@ int fetch_comb_binlog_user_set_friend (void *extra) { int fetch_comb_binlog_user_set_full_photo (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); if (U->flags & FLAG_HAS_PHOTO) { free_photo (&U->user.photo); @@ -284,7 +284,7 @@ int fetch_comb_binlog_user_set_full_photo (void *extra) { int fetch_comb_binlog_user_set_blocked (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); U->user.blocked = fetch_int (); @@ -297,7 +297,7 @@ int fetch_comb_binlog_user_set_blocked (void *extra) { int fetch_comb_binlog_user_set_real_name (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); if (U->user.real_first_name) { tfree_str (U->user.real_first_name); } @@ -313,7 +313,7 @@ int fetch_comb_binlog_user_set_real_name (void *extra) { int fetch_comb_binlog_user_set_name (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); if (U->user.first_name) { tfree_str (U->user.first_name); } @@ -335,7 +335,7 @@ int fetch_comb_binlog_user_set_name (void *extra) { int fetch_comb_binlog_user_set_photo (void *extra) { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); @@ -359,7 +359,7 @@ int fetch_comb_binlog_user_set_photo (void *extra) { int fetch_comb_binlog_encr_chat_delete (void *extra) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *_U = user_chat_get (id); + peer_t *_U = peer_get (id); assert (_U); struct secret_chat *U = &_U->encr_chat; memset (U->key, 0, sizeof (U->key)); @@ -382,7 +382,7 @@ int fetch_comb_binlog_encr_chat_delete (void *extra) { int fetch_comb_binlog_encr_chat_requested (void *extra) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *_U = user_chat_get (id); + peer_t *_U = peer_get (id); if (!_U) { _U = talloc0 (sizeof (*_U)); _U->id = id; @@ -396,7 +396,7 @@ int fetch_comb_binlog_encr_chat_requested (void *extra) { U->admin_id = fetch_int (); U->user_id = fetch_int (); - peer_t *Us = user_chat_get (MK_USER (U->user_id)); + peer_t *Us = peer_get (MK_USER (U->user_id)); assert (!U->print_name); if (Us) { U->print_name = create_print_name (id, "!", Us->user.first_name, Us->user.last_name, 0); @@ -422,7 +422,7 @@ int fetch_comb_binlog_encr_chat_requested (void *extra) { int fetch_comb_binlog_encr_chat_set_access_hash (void *extra) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); U->encr_chat.access_hash = fetch_long (); @@ -434,7 +434,7 @@ int fetch_comb_binlog_encr_chat_set_access_hash (void *extra) { int fetch_comb_binlog_encr_chat_set_date (void *extra) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); U->encr_chat.date = fetch_int (); @@ -446,7 +446,7 @@ int fetch_comb_binlog_encr_chat_set_date (void *extra) { int fetch_comb_binlog_encr_chat_set_state (void *extra) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); assert (U); U->encr_chat.state = fetch_int (); @@ -458,7 +458,7 @@ int fetch_comb_binlog_encr_chat_set_state (void *extra) { int fetch_comb_binlog_encr_chat_accepted (void *extra) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *_U = user_chat_get (id); + peer_t *_U = peer_get (id); assert (_U); struct secret_chat *U = &_U->encr_chat; if (!U->g_key) { @@ -485,7 +485,7 @@ int fetch_comb_binlog_encr_chat_accepted (void *extra) { int fetch_comb_binlog_encr_chat_set_key (void *extra) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *_U = user_chat_get (id); + peer_t *_U = peer_get (id); assert (_U); struct secret_chat *U = &_U->encr_chat; fetch_ints (U->key, 64); @@ -500,11 +500,11 @@ int fetch_comb_binlog_encr_chat_set_key (void *extra) { int fetch_comb_binlog_encr_chat_init (void *extra) { peer_t *P = talloc0 (sizeof (*P)); P->id = MK_ENCR_CHAT (fetch_int ()); - assert (!user_chat_get (P->id)); + assert (!peer_get (P->id)); P->encr_chat.user_id = fetch_int (); P->encr_chat.admin_id = our_id; insert_encrypted_chat (P); - peer_t *Us = user_chat_get (MK_USER (P->encr_chat.user_id)); + peer_t *Us = peer_get (MK_USER (P->encr_chat.user_id)); assert (Us); P->print_name = create_print_name (P->id, "!", Us->user.first_name, Us->user.last_name, 0); peer_insert_name (P); @@ -522,7 +522,7 @@ int fetch_comb_binlog_encr_chat_init (void *extra) { int fetch_comb_binlog_chat_create (void *extra) { peer_id_t id = MK_CHAT (fetch_int ()); - peer_t *_C = user_chat_get (id); + peer_t *_C = peer_get (id); if (!_C) { _C = talloc0 (sizeof (*_C)); _C->id = id; @@ -550,7 +550,7 @@ int fetch_comb_binlog_chat_create (void *extra) { } int fetch_comb_binlog_chat_change_flags (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); C->chat.flags |= fetch_int (); C->chat.flags &= ~fetch_int (); @@ -562,7 +562,7 @@ int fetch_comb_binlog_chat_change_flags (void *extra) { } int fetch_comb_binlog_chat_set_title (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); if (C->chat.title) { tfree_str (C->chat.title); } @@ -581,7 +581,7 @@ int fetch_comb_binlog_chat_set_title (void *extra) { } int fetch_comb_binlog_chat_set_photo (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); fetch_data (&C->photo_big, sizeof (struct file_location)); fetch_data (&C->photo_small, sizeof (struct file_location)); @@ -593,7 +593,7 @@ int fetch_comb_binlog_chat_set_photo (void *extra) { } int fetch_comb_binlog_chat_set_date (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); C->chat.date = fetch_int (); @@ -604,7 +604,7 @@ int fetch_comb_binlog_chat_set_date (void *extra) { } int fetch_comb_binlog_chat_set_version (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); C->chat.version = fetch_int (); C->chat.users_num = fetch_int (); @@ -616,7 +616,7 @@ int fetch_comb_binlog_chat_set_version (void *extra) { } int fetch_comb_binlog_chat_set_admin (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); C->chat.admin_id = fetch_int (); @@ -627,7 +627,7 @@ int fetch_comb_binlog_chat_set_admin (void *extra) { } int fetch_comb_binlog_chat_set_participants (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); C->chat.user_list_version = fetch_int (); if (C->chat.user_list) { tfree (C->chat.user_list, 12 * C->chat.user_list_size); } @@ -642,7 +642,7 @@ int fetch_comb_binlog_chat_set_participants (void *extra) { } int fetch_comb_binlog_chat_set_full_photo (void *extra) { - peer_t *C = user_chat_get (MK_CHAT (fetch_int ())); + peer_t *C = peer_get (MK_CHAT (fetch_int ())); assert (C && (C->flags & FLAG_CREATED)); assert (C && (C->flags & FLAG_CREATED)); @@ -659,7 +659,7 @@ int fetch_comb_binlog_chat_set_full_photo (void *extra) { int fetch_comb_binlog_chat_add_participant (void *extra) { peer_id_t id = MK_CHAT (fetch_int ()); - peer_t *_C = user_chat_get (id); + peer_t *_C = peer_get (id); assert (_C && (_C->flags & FLAG_CREATED)); struct chat *C = &_C->chat; @@ -689,7 +689,7 @@ int fetch_comb_binlog_chat_add_participant (void *extra) { int fetch_comb_binlog_chat_del_participant (void *extra) { peer_id_t id = MK_CHAT (fetch_int ()); - peer_t *_C = user_chat_get (id); + peer_t *_C = peer_get (id); assert (_C && (_C->flags & FLAG_CREATED)); struct chat *C = &_C->chat; @@ -832,7 +832,7 @@ int fetch_comb_binlog_send_message_action_encr (void *extra) { M->date = fetch_int (); M->media.type = CODE_decrypted_message_media_empty; - fetch_message_action_encrypted ((void *)user_chat_get (M->to_id), &M->action); + fetch_message_action_encrypted ((void *)peer_get (M->to_id), &M->action); M->unread = 1; M->out = get_peer_id (M->from_id) == our_id; @@ -1050,7 +1050,7 @@ int fetch_comb_binlog_create_message_service_encr (void *extra) { M->to_id = set_peer_id (t, fetch_int ()); M->date = fetch_int (); - struct secret_chat *E = (void *)user_chat_get (M->to_id); + struct secret_chat *E = (void *)peer_get (M->to_id); assert (E); fetch_message_action_encrypted (0, &M->action); diff --git a/interface.c b/interface.c index 9aed2ab..39a32db 100644 --- a/interface.c +++ b/interface.c @@ -230,7 +230,7 @@ char *get_default_prompt (void) { static char buf[1000]; int l = 0; if (in_chat_mode) { - peer_t *U = user_chat_get (chat_mode_id); + peer_t *U = peer_get (chat_mode_id); assert (U && U->print_name); l += tsnprintf (buf + l, 999 - l, COLOR_RED "%.*s " COLOR_NORMAL, 100, U->print_name); } @@ -856,7 +856,7 @@ void interpreter (char *line UU) { do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 0); } else if (IS_WORD ("rename_contact")) { GET_PEER_USER; - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); if (!U) { printf ("No such user\n"); RET; @@ -1407,13 +1407,13 @@ void print_service_message (struct message *M) { pop_color (); printf (" "); if (get_peer_type (M->to_id) == PEER_CHAT) { - print_chat_name (M->to_id, user_chat_get (M->to_id)); + print_chat_name (M->to_id, peer_get (M->to_id)); } else { assert (get_peer_type (M->to_id) == PEER_ENCR_CHAT); - print_encr_chat_name (M->to_id, user_chat_get (M->to_id)); + print_encr_chat_name (M->to_id, peer_get (M->to_id)); } printf (" "); - print_user_name (M->from_id, user_chat_get (M->from_id)); + print_user_name (M->from_id, peer_get (M->from_id)); switch (M->action.type) { case CODE_message_action_empty: @@ -1440,12 +1440,12 @@ void print_service_message (struct message *M) { break; case CODE_message_action_chat_add_user: printf (" added user "); - print_user_name (set_peer_id (PEER_USER, M->action.user), user_chat_get (set_peer_id (PEER_USER, M->action.user))); + print_user_name (set_peer_id (PEER_USER, M->action.user), peer_get (set_peer_id (PEER_USER, M->action.user))); printf ("\n"); break; case CODE_message_action_chat_delete_user: printf (" deleted user "); - print_user_name (set_peer_id (PEER_USER, M->action.user), user_chat_get (set_peer_id (PEER_USER, M->action.user))); + print_user_name (set_peer_id (PEER_USER, M->action.user), peer_get (set_peer_id (PEER_USER, M->action.user))); printf ("\n"); break; case CODE_decrypted_message_action_set_message_t_t_l: @@ -1504,7 +1504,7 @@ void print_message (struct message *M) { print_date (M->date); pop_color (); printf (" "); - print_user_name (M->to_id, user_chat_get (M->to_id)); + print_user_name (M->to_id, peer_get (M->to_id)); push_color (COLOR_GREEN); if (M->unread) { printf (" <<< "); @@ -1519,7 +1519,7 @@ void print_message (struct message *M) { print_date (M->date); pop_color (); printf (" "); - print_user_name (M->from_id, user_chat_get (M->from_id)); + print_user_name (M->from_id, peer_get (M->from_id)); push_color (COLOR_BLUE); if (M->unread) { printf (" >>> "); @@ -1531,7 +1531,7 @@ void print_message (struct message *M) { } } } else if (get_peer_type (M->to_id) == PEER_ENCR_CHAT) { - peer_t *P = user_chat_get (M->to_id); + peer_t *P = peer_get (M->to_id); assert (P); if (M->out) { push_color (COLOR_GREEN); @@ -1575,9 +1575,9 @@ void print_message (struct message *M) { print_date (M->date); pop_color (); printf (" "); - print_chat_name (M->to_id, user_chat_get (M->to_id)); + print_chat_name (M->to_id, peer_get (M->to_id)); printf (" "); - print_user_name (M->from_id, user_chat_get (M->from_id)); + print_user_name (M->from_id, peer_get (M->from_id)); if ((get_peer_type (M->from_id) == PEER_USER) && (get_peer_id (M->from_id) == our_id)) { push_color (COLOR_GREEN); } else { @@ -1591,7 +1591,7 @@ void print_message (struct message *M) { } if (get_peer_type (M->fwd_from_id) == PEER_USER) { printf ("[fwd from "); - print_user_name (M->fwd_from_id, user_chat_get (M->fwd_from_id)); + print_user_name (M->fwd_from_id, peer_get (M->fwd_from_id)); printf ("] "); } if (M->message && strlen (M->message)) { diff --git a/lua-tg.c b/lua-tg.c index fd9a12d..b956cf4 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -82,7 +82,7 @@ void push_chat (peer_t *P) { void push_encr_chat (peer_t *P) { my_lua_checkstack (luaState, 4); lua_pushstring (luaState, "user"); - push_peer (MK_USER (P->encr_chat.user_id), user_chat_get (MK_USER (P->encr_chat.user_id))); + push_peer (MK_USER (P->encr_chat.user_id), peer_get (MK_USER (P->encr_chat.user_id))); lua_settable (luaState, -3); } @@ -188,18 +188,18 @@ void push_message (struct message *M) { if (get_peer_type (M->fwd_from_id)) { lua_pushstring (luaState, "fwd_from"); - push_peer (M->fwd_from_id, user_chat_get (M->fwd_from_id)); + push_peer (M->fwd_from_id, peer_get (M->fwd_from_id)); lua_settable (luaState, -3); // fwd_from lua_add_num_field ("fwd_date", M->fwd_date); } lua_pushstring (luaState, "from"); - push_peer (M->from_id, user_chat_get (M->from_id)); + push_peer (M->from_id, peer_get (M->from_id)); lua_settable (luaState, -3); lua_pushstring (luaState, "to"); - push_peer (M->to_id, user_chat_get (M->to_id)); + push_peer (M->to_id, peer_get (M->to_id)); lua_settable (luaState, -3); lua_pushstring (luaState, "out"); diff --git a/mtproto-client.c b/mtproto-client.c index 2aebe5a..d58391f 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -846,7 +846,7 @@ void work_update_binlog (void) { case CODE_update_user_name: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *UC = user_chat_get (user_id); + peer_t *UC = peer_get (user_id); if (UC) { struct user *U = &UC->user; if (U->first_name) { tfree_str (U->first_name); } @@ -868,7 +868,7 @@ void work_update_binlog (void) { case CODE_update_user_photo: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *UC = user_chat_get (user_id); + peer_t *UC = peer_get (user_id); fetch_date (); if (UC) { struct user *U = &UC->user; @@ -952,7 +952,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_user_typing: { peer_id_t id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); if (log_level >= 2) { print_start (); push_color (COLOR_YELLOW); @@ -969,8 +969,8 @@ void work_update (struct connection *c UU, long long msg_id UU) { { peer_id_t chat_id = MK_CHAT (fetch_int ()); peer_id_t id = MK_USER (fetch_int ()); - peer_t *C = user_chat_get (chat_id); - peer_t *U = user_chat_get (id); + peer_t *C = peer_get (chat_id); + peer_t *U = peer_get (id); if (log_level >= 2) { print_start (); push_color (COLOR_YELLOW); @@ -988,7 +988,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_user_status: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (user_id); + peer_t *U = peer_get (user_id); if (U) { fetch_user_status (&U->user.status); if (log_level >= 3) { @@ -1011,7 +1011,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_user_name: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *UC = user_chat_get (user_id); + peer_t *UC = peer_get (user_id); if (UC && (UC->flags & FLAG_CREATED)) { int l1 = prefetch_strlen (); char *f = fetch_str (l1); @@ -1038,7 +1038,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_user_photo: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *UC = user_chat_get (user_id); + peer_t *UC = peer_get (user_id); fetch_date (); if (UC && (UC->flags & FLAG_CREATED)) { struct user *U = &UC->user; @@ -1116,7 +1116,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { assert (x == CODE_chat_participants || x == CODE_chat_participants_forbidden); peer_id_t chat_id = MK_CHAT (fetch_int ()); int n = 0; - peer_t *C = user_chat_get (chat_id); + peer_t *C = peer_get (chat_id); if (C && (C->flags & FLAG_CREATED)) { if (x == CODE_chat_participants) { bl_do_chat_set_admin (&C->chat, fetch_int ()); @@ -1159,7 +1159,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_contact_registered: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (user_id); + peer_t *U = peer_get (user_id); fetch_int (); // date print_start (); push_color (COLOR_YELLOW); @@ -1174,7 +1174,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_contact_link: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (user_id); + peer_t *U = peer_get (user_id); print_start (); push_color (COLOR_YELLOW); print_date (time (0)); @@ -1198,7 +1198,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_activation: { peer_id_t user_id = MK_USER (fetch_int ()); - peer_t *U = user_chat_get (user_id); + peer_t *U = peer_get (user_id); print_start (); push_color (COLOR_YELLOW); print_date (time (0)); @@ -1290,14 +1290,14 @@ void work_update (struct connection *c UU, long long msg_id UU) { case CODE_update_encrypted_chat_typing: { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); print_start (); push_color (COLOR_YELLOW); print_date (time (0)); if (P) { printf (" User "); peer_id_t user_id = MK_USER (P->encr_chat.user_id); - print_user_name (user_id, user_chat_get (user_id)); + print_user_name (user_id, peer_get (user_id)); printf (" typing in secret chat "); print_encr_chat_name (id, P); printf ("\n"); @@ -1313,7 +1313,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_id_t id = MK_ENCR_CHAT (fetch_int ()); // chat_id fetch_int (); // max_date fetch_int (); // date - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); int x = -1; if (P && P->last) { x = 0; @@ -1331,7 +1331,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { push_color (COLOR_YELLOW); print_date (time (0)); printf (" Encrypted chat "); - print_encr_chat_name_full (id, user_chat_get (id)); + print_encr_chat_name_full (id, peer_get (id)); printf (": %d messages marked read \n", x); pop_color (); print_end (); @@ -1345,7 +1345,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_id_t inviter_id = MK_USER (fetch_int ()); int version = fetch_int (); - peer_t *C = user_chat_get (chat_id); + peer_t *C = peer_get (chat_id); if (C && (C->flags & FLAG_CREATED)) { bl_do_chat_add_user (&C->chat, version, get_peer_id (user_id), get_peer_id (inviter_id), time (0)); } @@ -1354,11 +1354,11 @@ void work_update (struct connection *c UU, long long msg_id UU) { push_color (COLOR_YELLOW); print_date (time (0)); printf (" Chat "); - print_chat_name (chat_id, user_chat_get (chat_id)); + print_chat_name (chat_id, peer_get (chat_id)); printf (": user "); - print_user_name (user_id, user_chat_get (user_id)); + print_user_name (user_id, peer_get (user_id)); printf (" added by user "); - print_user_name (inviter_id, user_chat_get (inviter_id)); + print_user_name (inviter_id, peer_get (inviter_id)); printf ("\n"); pop_color (); print_end (); @@ -1370,7 +1370,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { peer_id_t user_id = MK_USER (fetch_int ()); int version = fetch_int (); - peer_t *C = user_chat_get (chat_id); + peer_t *C = peer_get (chat_id); if (C && (C->flags & FLAG_CREATED)) { bl_do_chat_del_user (&C->chat, version, get_peer_id (user_id)); } @@ -1379,9 +1379,9 @@ void work_update (struct connection *c UU, long long msg_id UU) { push_color (COLOR_YELLOW); print_date (time (0)); printf (" Chat "); - print_chat_name (chat_id, user_chat_get (chat_id)); + print_chat_name (chat_id, peer_get (chat_id)); printf (": user "); - print_user_name (user_id, user_chat_get (user_id)); + print_user_name (user_id, peer_get (user_id)); printf (" deleted\n"); pop_color (); print_end (); @@ -1402,7 +1402,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { { int id = fetch_int (); int blocked = fetch_bool (); - peer_t *P = user_chat_get (MK_USER (id)); + peer_t *P = peer_get (MK_USER (id)); if (P && (P->flags & FLAG_CREATED)) { bl_do_user_set_blocked (&P->user, blocked); } diff --git a/queries.c b/queries.c index 1c05c40..6948129 100644 --- a/queries.c +++ b/queries.c @@ -940,7 +940,7 @@ int out_message_num; int our_id; void do_send_encr_msg_action (struct message *M) { - peer_t *P = user_chat_get (M->to_id); + peer_t *P = peer_get (M->to_id); if (!P || P->encr_chat.state != sc_ok) { return; } clear_packet (); @@ -974,7 +974,7 @@ void do_send_encr_msg (struct message *M) { do_send_encr_msg_action (M); return; } - peer_t *P = user_chat_get (M->to_id); + peer_t *P = peer_get (M->to_id); if (!P || P->encr_chat.state != sc_ok) { return; } clear_packet (); @@ -1011,7 +1011,7 @@ void do_send_msg (struct message *M) { void do_send_message (peer_id_t id, const char *msg, int len) { if (get_peer_type (id) == PEER_ENCR_CHAT) { - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); if (!P) { logprintf ("Can not send to unknown encrypted chat\n"); return; @@ -1100,7 +1100,7 @@ void do_messages_mark_read_encr (peer_id_t id, long long access_hash, int last_t } void do_mark_read (peer_id_t id) { - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); if (!P) { rprintf ("Unknown peer\n"); return; @@ -1169,7 +1169,7 @@ struct query_methods get_history_methods = { }; void do_get_local_history (peer_id_t id, int limit) { - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); if (!P || !P->last) { return; } struct message *M = P->last; int count = 1; @@ -1248,13 +1248,13 @@ int get_dialogs_on_answer (struct query *q UU) { peer_t *UC; switch (get_peer_type (plist[i])) { case PEER_USER: - UC = user_chat_get (plist[i]); + UC = peer_get (plist[i]); printf ("User "); print_user_name (plist[i], UC); printf (": %d unread\n", dlist[2 * i + 1]); break; case PEER_CHAT: - UC = user_chat_get (plist[i]); + UC = peer_get (plist[i]); printf ("Chat "); print_chat_name (plist[i], UC); printf (": %d unread\n", dlist[2 * i + 1]); @@ -1312,7 +1312,7 @@ void out_peer_id (peer_id_t id) { out_int (get_peer_id (id)); break; case PEER_USER: - U = user_chat_get (id); + U = peer_get (id); if (U && U->user.access_hash) { out_int (CODE_input_peer_foreign); out_int (get_peer_id (id)); @@ -1487,7 +1487,7 @@ void send_part (struct send_file *f) { out_int (CODE_messages_send_encrypted_file); out_int (CODE_input_encrypted_chat); out_int (get_peer_id (f->to_id)); - peer_t *P = user_chat_get (f->to_id); + peer_t *P = peer_get (f->to_id); assert (P); out_long (P->encr_chat.access_hash); long long r = -lrand48 () * (1ll << 32) - lrand48 (); @@ -1737,9 +1737,9 @@ void print_chat_info (struct chat *C) { int i; for (i = 0; i < C->user_list_size; i++) { printf ("\t\t"); - print_user_name (MK_USER (C->user_list[i].user_id), user_chat_get (MK_USER (C->user_list[i].user_id))); + print_user_name (MK_USER (C->user_list[i].user_id), peer_get (MK_USER (C->user_list[i].user_id))); printf (" invited by "); - print_user_name (MK_USER (C->user_list[i].inviter_id), user_chat_get (MK_USER (C->user_list[i].inviter_id))); + print_user_name (MK_USER (C->user_list[i].inviter_id), peer_get (MK_USER (C->user_list[i].inviter_id))); printf (" at "); print_date_full (C->user_list[i].date); if (C->user_list[i].user_id == C->admin_id) { @@ -1764,7 +1764,7 @@ struct query_methods chat_info_methods = { void do_get_chat_info (peer_id_t id) { if (offline_mode) { - peer_t *C = user_chat_get (id); + peer_t *C = peer_get (id); if (!C) { rprintf ("No such chat\n"); } else { @@ -1815,7 +1815,7 @@ struct query_methods user_info_methods = { void do_get_user_info (peer_id_t id) { if (offline_mode) { - peer_t *C = user_chat_get (id); + peer_t *C = peer_get (id); if (!C) { rprintf ("No such user\n"); } else { @@ -1826,7 +1826,7 @@ void do_get_user_info (peer_id_t id) { clear_packet (); out_int (CODE_users_get_full_user); assert (get_peer_type (id) == PEER_USER); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); if (U && U->user.access_hash) { out_int (CODE_input_user_foreign); out_int (get_peer_id (id)); @@ -2557,18 +2557,18 @@ void do_send_create_encr_chat (void *x, unsigned char *random) { BN_bn2bin (r, (void *)g_a); int t = lrand48 (); - while (user_chat_get (MK_ENCR_CHAT (t))) { + while (peer_get (MK_ENCR_CHAT (t))) { t = lrand48 (); } bl_do_encr_chat_init (t, user_id, (void *)random, (void *)g_a); - peer_t *_E = user_chat_get (MK_ENCR_CHAT (t)); + peer_t *_E = peer_get (MK_ENCR_CHAT (t)); assert (_E); struct secret_chat *E = &_E->encr_chat; clear_packet (); out_int (CODE_messages_request_encryption); - peer_t *U = user_chat_get (MK_USER (E->user_id)); + peer_t *U = peer_get (MK_USER (E->user_id)); assert (U); if (U && U->user.access_hash) { out_int (CODE_input_user_foreign); @@ -2768,7 +2768,7 @@ char *colors[4] = {COLOR_GREY, COLOR_CYAN, COLOR_BLUE, COLOR_GREEN}; void do_visualize_key (peer_id_t id) { assert (get_peer_type (id) == PEER_ENCR_CHAT); - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); assert (P); if (P->encr_chat.state != sc_ok) { rprintf ("Chat is not initialized yet\n"); @@ -2851,7 +2851,7 @@ void do_add_user_to_chat (peer_id_t chat_id, peer_id_t id, int limit) { out_int (get_peer_id (chat_id)); assert (get_peer_type (id) == PEER_USER); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); if (U && U->user.access_hash) { out_int (CODE_input_user_foreign); out_int (get_peer_id (id)); @@ -2870,7 +2870,7 @@ void do_del_user_from_chat (peer_id_t chat_id, peer_id_t id) { out_int (get_peer_id (chat_id)); assert (get_peer_type (id) == PEER_USER); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); if (U && U->user.access_hash) { out_int (CODE_input_user_foreign); out_int (get_peer_id (id)); @@ -2888,7 +2888,7 @@ char *create_print_name (peer_id_t id, const char *a1, const char *a2, const cha void do_create_secret_chat (peer_id_t id) { assert (get_peer_type (id) == PEER_USER); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); if (!U) { rprintf ("Can not create chat with unknown user\n"); return; @@ -2906,7 +2906,7 @@ struct query_methods create_group_chat_methods = { void do_create_group_chat (peer_id_t id, char *chat_topic) { assert (get_peer_type (id) == PEER_USER); - peer_t *U = user_chat_get (id); + peer_t *U = peer_get (id); if (!U) { rprintf ("Can not create chat with unknown user\n"); return; diff --git a/structures.c b/structures.c index 8713710..fa1f316 100644 --- a/structures.c +++ b/structures.c @@ -1108,7 +1108,7 @@ void fetch_encrypted_message (struct message *M) { peer_id_t chat = MK_ENCR_CHAT (to_id); int date = fetch_int (); - peer_t *P = user_chat_get (chat); + peer_t *P = peer_get (chat); if (!P) { logprintf ("Encrypted message to unknown chat. Dropping\n"); M->flags |= FLAG_MESSAGE_EMPTY; @@ -1218,7 +1218,7 @@ static int id_cmp (struct message *M1, struct message *M2) { struct user *fetch_alloc_user (void) { int data[2]; prefetch_data (data, 8); - peer_t *U = user_chat_get (MK_USER (data[1])); + peer_t *U = peer_get (MK_USER (data[1])); if (!U) { users_allocated ++; U = talloc0 (sizeof (*U)); @@ -1234,7 +1234,7 @@ struct user *fetch_alloc_user (void) { struct secret_chat *fetch_alloc_encrypted_chat (void) { int data[2]; prefetch_data (data, 8); - peer_t *U = user_chat_get (MK_ENCR_CHAT (data[1])); + peer_t *U = peer_get (MK_ENCR_CHAT (data[1])); if (!U) { U = talloc0 (sizeof (*U)); U->id = MK_ENCR_CHAT (data[1]); @@ -1271,7 +1271,7 @@ void insert_chat (peer_t *P) { struct user *fetch_alloc_user_full (void) { int data[3]; prefetch_data (data, 12); - peer_t *U = user_chat_get (MK_USER (data[2])); + peer_t *U = peer_get (MK_USER (data[2])); if (U) { fetch_user_full (&U->user); return &U->user; @@ -1419,7 +1419,7 @@ void message_add_peer (struct message *M) { } else { id = M->to_id; } - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); if (!P) { P = talloc0 (sizeof (*P)); P->id = id; @@ -1477,7 +1477,7 @@ void message_del_peer (struct message *M) { } else { id = M->to_id; } - peer_t *P = user_chat_get (id); + peer_t *P = peer_get (id); if (M->prev) { M->prev->next = M->next; } @@ -1576,7 +1576,7 @@ struct message *fetch_alloc_message_short_chat (void) { struct chat *fetch_alloc_chat (void) { int data[2]; prefetch_data (data, 8); - peer_t *U = user_chat_get (MK_CHAT (data[1])); + peer_t *U = peer_get (MK_CHAT (data[1])); if (!U) { chats_allocated ++; U = talloc0 (sizeof (*U)); @@ -1592,7 +1592,7 @@ struct chat *fetch_alloc_chat (void) { struct chat *fetch_alloc_chat_full (void) { int data[3]; prefetch_data (data, 12); - peer_t *U = user_chat_get (MK_CHAT (data[2])); + peer_t *U = peer_get (MK_CHAT (data[2])); if (U) { fetch_chat_full (&U->chat); return &U->chat; @@ -1628,7 +1628,7 @@ int print_stat (char *s, int len) { ); } -peer_t *user_chat_get (peer_id_t id) { +peer_t *peer_get (peer_id_t id) { static peer_t U; U.id = id; return tree_lookup_peer (peer_tree, &U); diff --git a/structures.h b/structures.h index 0072e02..f986037 100644 --- a/structures.h +++ b/structures.h @@ -367,7 +367,7 @@ void free_chat (struct chat *U); char *create_print_name (peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4); int print_stat (char *s, int len); -peer_t *user_chat_get (peer_id_t id); +peer_t *peer_get (peer_id_t id); struct message *message_get (long long id); void update_message_id (struct message *M, long long id); void message_insert (struct message *M);