diff --git a/auto-static.c b/auto-static.c index 3df955e..8e678da 100644 --- a/auto-static.c +++ b/auto-static.c @@ -27,20 +27,18 @@ int skip_string (void) { unsigned len = *(unsigned char *)in_ptr; if (len == 0xff) { return -1; } if (len < 0xfe) { - int size = len + 1; - size += (-size) & 3; - if (in_ptr + (size / 4) <= in_end) { - in_ptr += (size / 4); + unsigned size = (len + 4) >> 2; + if (in_ptr + size <= in_end) { + in_ptr += size; return 0; } else { return -1; } } else { - len = (*in_ptr) >> 8; - int size = len + 4; - size += (-size) & 3; - if (in_ptr + (size / 4) <= in_end) { - in_ptr += (size / 4); + len = (*(unsigned *)in_ptr) >> 8; + unsigned size = (len + 7) >> 2; + if (in_ptr + size <= in_end) { + in_ptr += size; return 0; } else { return -1; diff --git a/auto.h b/auto.h index 3c0d055..0c1695e 100644 --- a/auto.h +++ b/auto.h @@ -20,8 +20,6 @@ struct paramed_type { #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 9cd3723..1292a94 100644 --- a/binlog.c +++ b/binlog.c @@ -178,7 +178,7 @@ int fetch_comb_binlog_set_seq (void *extra) { return 0; } -int fetch_comb_binlog_new_user (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); if (!_U) { @@ -223,7 +223,7 @@ int fetch_comb_binlog_user_delete (void *extra) { return 0; } -int fetch_comb_binlog_set_user_access_token (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); assert (U); @@ -235,7 +235,7 @@ int fetch_comb_binlog_set_user_access_token (void *extra) { return 0; } -int fetch_comb_binlog_set_user_phone (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); assert (U); @@ -250,7 +250,7 @@ int fetch_comb_binlog_set_user_phone (void *extra) { return 0; } -int fetch_comb_binlog_set_user_friend (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); assert (U); @@ -267,7 +267,7 @@ int fetch_comb_binlog_set_user_friend (void *extra) { return 0; } -int fetch_comb_binlog_user_full_photo (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); assert (U); @@ -282,7 +282,7 @@ int fetch_comb_binlog_user_full_photo (void *extra) { return 0; } -int fetch_comb_binlog_user_blocked (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); assert (U); @@ -295,7 +295,7 @@ int fetch_comb_binlog_user_blocked (void *extra) { return 0; } -int fetch_comb_binlog_set_user_full_name (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); assert (U); @@ -311,6 +311,52 @@ int fetch_comb_binlog_set_user_full_name (void *extra) { return 0; } +int fetch_comb_binlog_user_set_name (void *extra) { + peer_id_t id = MK_USER (fetch_int ()); + peer_t *U = user_chat_get (id); + assert (U); + + if (U->user.first_name) { tfree_str (U->user.first_name); } + if (U->user.last_name) { tfree_str (U->user.last_name); } + U->user.first_name = fetch_str_dup (); + U->user.last_name = fetch_str_dup (); + if (U->print_name) { + peer_delete_name (U); + tfree_str (U->print_name); + } + U->print_name = create_print_name (U->id, U->user.first_name, U->user.last_name, 0, 0); + peer_insert_name ((void *)U); + + #ifdef USE_LUA + lua_user_update (&U->user); + #endif + return 0; +} + +int fetch_comb_binlog_user_set_photo (void *extra) { + peer_id_t id = MK_USER (fetch_int ()); + peer_t *U = user_chat_get (id); + assert (U); + + + unsigned y = fetch_int (); + if (y == CODE_user_profile_photo_empty) { + U->user.photo_id = 0; + U->user.photo_big.dc = -2; + U->user.photo_small.dc = -2; + } else { + assert (y == CODE_user_profile_photo); + U->user.photo_id = fetch_long (); + fetch_file_location (&U->user.photo_small); + fetch_file_location (&U->user.photo_big); + } + + #ifdef USE_LUA + lua_user_update (&U->user); + #endif + return 0; +} + 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); @@ -882,57 +928,199 @@ int fetch_comb_binlog_create_message_media_encr (void *extra) { 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) +int fetch_comb_binlog_create_message_media_fwd (void *extra) { + int id = fetch_int (); + struct message *M = message_get (id); + if (!M) { + M = talloc0 (sizeof (*M)); + M->id = id; + message_insert_tree (M); + messages_allocated ++; + } else { + assert (!(M->flags & FLAG_CREATED)); + } + M->flags |= FLAG_CREATED; + M->from_id = MK_USER (fetch_int ()); + int t = fetch_int (); + M->to_id = set_peer_id (t, fetch_int ()); + M->date = fetch_int (); + + M->fwd_from_id = MK_USER (fetch_int ()); + M->fwd_date = fetch_int (); + + int l = prefetch_strlen (); + M->message = talloc (l + 1); + memcpy (M->message, fetch_str (l), l); + M->message[l] = 0; + M->message_len = l; -FETCH_COMBINATOR_FUNCTION (binlog_set_dh_params) -FETCH_COMBINATOR_FUNCTION (binlog_set_pts) -FETCH_COMBINATOR_FUNCTION (binlog_set_qts) -FETCH_COMBINATOR_FUNCTION (binlog_set_date) -FETCH_COMBINATOR_FUNCTION (binlog_set_seq) + fetch_message_media (&M->media); + M->unread = 1; + M->out = get_peer_id (M->from_id) == our_id; -FETCH_COMBINATOR_FUNCTION (binlog_new_user) -FETCH_COMBINATOR_FUNCTION (binlog_user_delete) -FETCH_COMBINATOR_FUNCTION (binlog_set_user_access_token) -FETCH_COMBINATOR_FUNCTION (binlog_set_user_phone) -FETCH_COMBINATOR_FUNCTION (binlog_set_user_friend) -FETCH_COMBINATOR_FUNCTION (binlog_user_full_photo) -FETCH_COMBINATOR_FUNCTION (binlog_user_blocked) + message_insert (M); + #ifdef USE_LUA + lua_new_msg (M); + #endif + return 0; +} -FETCH_COMBINATOR_FUNCTION (binlog_set_user_full_name) -FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_delete) -FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_requested) -FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_access_hash) -FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_date) -FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_state) -FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_accepted) -FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_key) -FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_init) +int fetch_comb_binlog_create_message_service (void *extra) { + int id = fetch_int (); + struct message *M = message_get (id); + if (!M) { + M = talloc0 (sizeof (*M)); + M->id = id; + message_insert_tree (M); + messages_allocated ++; + } else { + assert (!(M->flags & FLAG_CREATED)); + } + M->flags |= FLAG_CREATED; + M->from_id = MK_USER (fetch_int ()); + int t = fetch_int (); + M->to_id = set_peer_id (t, fetch_int ()); + M->date = fetch_int (); + + fetch_message_action (&M->action); + M->unread = 1; + M->out = get_peer_id (M->from_id) == our_id; + M->service = 1; -FETCH_COMBINATOR_FUNCTION (binlog_chat_create) -FETCH_COMBINATOR_FUNCTION (binlog_chat_change_flags) -FETCH_COMBINATOR_FUNCTION (binlog_set_chat_title) -FETCH_COMBINATOR_FUNCTION (binlog_set_chat_photo) -FETCH_COMBINATOR_FUNCTION (binlog_set_chat_date) -FETCH_COMBINATOR_FUNCTION (binlog_set_chat_version) -FETCH_COMBINATOR_FUNCTION (binlog_set_chat_admin) -FETCH_COMBINATOR_FUNCTION (binlog_set_chat_participants) -FETCH_COMBINATOR_FUNCTION (binlog_chat_full_photo) -FETCH_COMBINATOR_FUNCTION (binlog_add_chat_participant) -FETCH_COMBINATOR_FUNCTION (binlog_del_chat_participant) + message_insert (M); + #ifdef USE_LUA + lua_new_msg (M); + #endif + return 0; +} -FETCH_COMBINATOR_FUNCTION (binlog_create_message_text) -FETCH_COMBINATOR_FUNCTION (binlog_send_message_text) -FETCH_COMBINATOR_FUNCTION (binlog_create_message_text_fwd) -FETCH_COMBINATOR_FUNCTION (binlog_create_message_media) +int fetch_comb_binlog_create_message_service_encr (void *extra) { + int id = fetch_int (); + struct message *M = message_get (id); + if (!M) { + M = talloc0 (sizeof (*M)); + M->id = id; + message_insert_tree (M); + messages_allocated ++; + } else { + assert (!(M->flags & FLAG_CREATED)); + } + M->flags |= FLAG_CREATED | FLAG_ENCRYPTED; + M->from_id = MK_USER (fetch_int ()); + int t = fetch_int (); + M->to_id = set_peer_id (t, fetch_int ()); + M->date = fetch_int (); + + fetch_message_action_encrypted (&M->action); + M->unread = 1; + M->out = get_peer_id (M->from_id) == our_id; + M->service = 1; + + message_insert (M); + #ifdef USE_LUA + lua_new_msg (M); + #endif + return 0; +} + +int fetch_comb_binlog_create_message_service_fwd (void *extra) { + int id = fetch_int (); + struct message *M = message_get (id); + if (!M) { + M = talloc0 (sizeof (*M)); + M->id = id; + message_insert_tree (M); + messages_allocated ++; + } else { + assert (!(M->flags & FLAG_CREATED)); + } + M->flags |= FLAG_CREATED; + M->from_id = MK_USER (fetch_int ()); + int t = fetch_int (); + M->to_id = set_peer_id (t, fetch_int ()); + M->date = fetch_int (); + + M->fwd_from_id = MK_USER (fetch_int ()); + M->fwd_date = fetch_int (); + + fetch_message_action (&M->action); + M->unread = 1; + M->out = get_peer_id (M->from_id) == our_id; + M->service = 1; + + message_insert (M); + #ifdef USE_LUA + lua_new_msg (M); + #endif + return 0; +} + +int fetch_comb_binlog_message_set_unread (void *extra) { + struct message *M = message_get (fetch_int ()); + assert (M); + M->unread = 0; + #ifdef USE_LUA + lua_update_msg (M); + #endif + return 0; +} + +int fetch_comb_binlog_set_message_sent (void *extra) { + struct message *M = message_get (fetch_long ()); + assert (M); + message_remove_unsent (M); + M->flags &= ~FLAG_PENDING; + #ifdef USE_LUA + lua_update_msg (M); + #endif + return 0; +} + +int fetch_comb_binlog_set_msg_id (void *extra) { + struct message *M = message_get (fetch_long ()); + assert (M); + if (M->flags & FLAG_PENDING) { + message_remove_unsent (M); + M->flags &= ~FLAG_PENDING; + } + message_remove_tree (M); + message_del_peer (M); + M->id = fetch_int (); + if (message_get (M->id)) { + free_message (M); + tfree (M, sizeof (*M)); + } else { + message_insert_tree (M); + message_add_peer (M); + } + #ifdef USE_LUA + lua_update_msg (M); + #endif + return 0; +} + +int fetch_comb_binlog_delete_msg (void *extra) { + struct message *M = message_get (fetch_long ()); + assert (M); + if (M->flags & FLAG_PENDING) { + message_remove_unsent (M); + M->flags &= ~FLAG_PENDING; + } + message_remove_tree (M); + message_del_peer (M); + message_del_use (M); + free_message (M); + tfree (M, sizeof (*M)); + return 0; +} + +#define FETCH_COMBINATOR_FUNCTION(NAME) \ + case CODE_ ## NAME:\ + ok = fetch_comb_ ## NAME (0); \ + break; \ + void replay_log_event (void) { - int *start = rptr; in_replay_log = 1; assert (rptr < wptr); int op = *rptr; @@ -943,224 +1131,95 @@ void replay_log_event (void) { in_ptr = rptr; in_end = wptr; + assert (skip_type_any (TYPE_TO_PARAM(binlog_update)) >= 0); + in_end = in_ptr; + in_ptr = rptr; + + int ok = -1; + in_ptr ++; + switch (op) { - case CODE_binlog_create_message_media_fwd: - in_ptr ++; - { - int id = fetch_int (); - struct message *M = message_get (id); - if (!M) { - M = talloc0 (sizeof (*M)); - M->id = id; - message_insert_tree (M); - messages_allocated ++; - } else { - assert (!(M->flags & FLAG_CREATED)); - } - M->flags |= FLAG_CREATED; - M->from_id = MK_USER (fetch_int ()); - int t = fetch_int (); - M->to_id = set_peer_id (t, fetch_int ()); - M->date = fetch_int (); - M->fwd_from_id = MK_USER (fetch_int ()); - M->fwd_date = fetch_int (); - - int l = prefetch_strlen (); - M->message = talloc (l + 1); - memcpy (M->message, fetch_str (l), l); - M->message[l] = 0; - M->message_len = l; + 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_message_media (&M->media); - M->unread = 1; - M->out = get_peer_id (M->from_id) == our_id; + FETCH_COMBINATOR_FUNCTION (binlog_set_dh_params) + FETCH_COMBINATOR_FUNCTION (binlog_set_pts) + FETCH_COMBINATOR_FUNCTION (binlog_set_qts) + FETCH_COMBINATOR_FUNCTION (binlog_set_date) + FETCH_COMBINATOR_FUNCTION (binlog_set_seq) - message_insert (M); - #ifdef USE_LUA - lua_new_msg (M); - #endif - } - rptr = in_ptr; - break; - case CODE_binlog_create_message_service: - in_ptr ++; - { - int id = fetch_int (); - struct message *M = message_get (id); - if (!M) { - M = talloc0 (sizeof (*M)); - M->id = id; - message_insert_tree (M); - messages_allocated ++; - } else { - assert (!(M->flags & FLAG_CREATED)); - } - M->flags |= FLAG_CREATED; - M->from_id = MK_USER (fetch_int ()); - int t = fetch_int (); - M->to_id = set_peer_id (t, fetch_int ()); - M->date = fetch_int (); + FETCH_COMBINATOR_FUNCTION (binlog_user_add) + FETCH_COMBINATOR_FUNCTION (binlog_user_delete) + FETCH_COMBINATOR_FUNCTION (binlog_user_set_access_hash) + FETCH_COMBINATOR_FUNCTION (binlog_user_set_phone) + FETCH_COMBINATOR_FUNCTION (binlog_user_set_friend) + FETCH_COMBINATOR_FUNCTION (binlog_user_set_full_photo) + FETCH_COMBINATOR_FUNCTION (binlog_user_set_blocked) + FETCH_COMBINATOR_FUNCTION (binlog_user_set_name) + FETCH_COMBINATOR_FUNCTION (binlog_user_set_photo) - fetch_message_action (&M->action); - M->unread = 1; - M->out = get_peer_id (M->from_id) == our_id; - M->service = 1; + FETCH_COMBINATOR_FUNCTION (binlog_user_set_real_name) + FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_delete) + FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_requested) + FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_access_hash) + FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_date) + FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_state) + FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_accepted) + FETCH_COMBINATOR_FUNCTION (binlog_set_encr_chat_key) + FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_init) - message_insert (M); - #ifdef USE_LUA - lua_new_msg (M); - #endif - } - rptr = in_ptr; - break; - case CODE_binlog_create_message_service_encr: - in_ptr ++; - { - long long id = fetch_long (); - struct message *M = message_get (id); - if (!M) { - M = talloc0 (sizeof (*M)); - M->id = id; - message_insert_tree (M); - messages_allocated ++; - } else { - assert (!(M->flags & FLAG_CREATED)); - } - M->flags |= FLAG_CREATED | FLAG_ENCRYPTED; - M->from_id = MK_USER (fetch_int ()); - int t = fetch_int (); - M->to_id = set_peer_id (t, fetch_int ()); - M->date = fetch_int (); + FETCH_COMBINATOR_FUNCTION (binlog_chat_create) + FETCH_COMBINATOR_FUNCTION (binlog_chat_change_flags) + FETCH_COMBINATOR_FUNCTION (binlog_set_chat_title) + FETCH_COMBINATOR_FUNCTION (binlog_set_chat_photo) + FETCH_COMBINATOR_FUNCTION (binlog_set_chat_date) + FETCH_COMBINATOR_FUNCTION (binlog_set_chat_version) + FETCH_COMBINATOR_FUNCTION (binlog_set_chat_admin) + FETCH_COMBINATOR_FUNCTION (binlog_set_chat_participants) + FETCH_COMBINATOR_FUNCTION (binlog_chat_full_photo) + FETCH_COMBINATOR_FUNCTION (binlog_add_chat_participant) + FETCH_COMBINATOR_FUNCTION (binlog_del_chat_participant) - fetch_message_action_encrypted (&M->action); - - M->unread = 1; - M->out = get_peer_id (M->from_id) == our_id; - M->service = 1; - - message_insert (M); - #ifdef USE_LUA - lua_new_msg (M); - #endif - } - rptr = in_ptr; - break; - case CODE_binlog_create_message_service_fwd: - in_ptr ++; - { - int id = fetch_int (); - struct message *M = message_get (id); - if (!M) { - M = talloc0 (sizeof (*M)); - M->id = id; - message_insert_tree (M); - messages_allocated ++; - } else { - assert (!(M->flags & FLAG_CREATED)); - } - M->flags |= FLAG_CREATED; - M->from_id = MK_USER (fetch_int ()); - int t = fetch_int (); - M->to_id = set_peer_id (t, fetch_int ()); - M->date = fetch_int (); - M->fwd_from_id = MK_USER (fetch_int ()); - M->fwd_date = fetch_int (); - fetch_message_action (&M->action); - M->unread = 1; - M->out = get_peer_id (M->from_id) == our_id; - M->service = 1; - - message_insert (M); - #ifdef USE_LUA - lua_new_msg (M); - #endif - } - rptr = in_ptr; - break; - case CODE_binlog_set_unread: - rptr ++; - { - struct message *M = message_get (*(rptr ++)); - assert (M); - M->unread = 0; - } - break; - case CODE_binlog_set_message_sent: - rptr ++; - { - struct message *M = message_get (*(long long *)rptr); - rptr += 2; - assert (M); - message_remove_unsent (M); - M->flags &= ~FLAG_PENDING; - } - break; - case CODE_binlog_set_msg_id: - rptr ++; - { - struct message *M = message_get (*(long long *)rptr); - rptr += 2; - assert (M); - if (M->flags & FLAG_PENDING) { - message_remove_unsent (M); - M->flags &= ~FLAG_PENDING; - } - message_remove_tree (M); - message_del_peer (M); - M->id = *(rptr ++); - if (message_get (M->id)) { - free_message (M); - tfree (M, sizeof (*M)); - } else { - message_insert_tree (M); - message_add_peer (M); - } - } - break; - case CODE_binlog_delete_msg: - rptr ++; - { - struct message *M = message_get (*(long long *)rptr); - rptr += 2; - assert (M); - if (M->flags & FLAG_PENDING) { - message_remove_unsent (M); - M->flags &= ~FLAG_PENDING; - } - message_remove_tree (M); - message_del_peer (M); - message_del_use (M); - free_message (M); - tfree (M, sizeof (*M)); - } - break; - case CODE_update_user_photo: - case CODE_update_user_name: - work_update_binlog (); - rptr = in_ptr; - break; + FETCH_COMBINATOR_FUNCTION (binlog_create_message_text) + FETCH_COMBINATOR_FUNCTION (binlog_send_message_text) + FETCH_COMBINATOR_FUNCTION (binlog_create_message_text_fwd) + FETCH_COMBINATOR_FUNCTION (binlog_create_message_media) + FETCH_COMBINATOR_FUNCTION (binlog_create_message_media_encr) + FETCH_COMBINATOR_FUNCTION (binlog_create_message_media_fwd) + FETCH_COMBINATOR_FUNCTION (binlog_create_message_service) + FETCH_COMBINATOR_FUNCTION (binlog_create_message_service_encr) + FETCH_COMBINATOR_FUNCTION (binlog_create_message_service_fwd) + FETCH_COMBINATOR_FUNCTION (binlog_message_set_unread) + FETCH_COMBINATOR_FUNCTION (binlog_set_message_sent) + FETCH_COMBINATOR_FUNCTION (binlog_set_msg_id) + FETCH_COMBINATOR_FUNCTION (binlog_delete_msg) default: - logprintf ("Unknown logevent [0x%08x] 0x%08x [0x%08x] at %lld\n", *(rptr - 1), op, *(rptr + 1), binlog_pos); - + logprintf ("Unknown op 0x%08x\n", op); assert (0); } - if (verbosity >= 2) { - logprintf ("Event end\n"); - } + assert (ok >= 0); + + assert (in_ptr == in_end); in_replay_log = 0; - binlog_pos += (rptr - start) * 4; + binlog_pos += (in_ptr - rptr) * 4; + rptr = in_ptr; } void create_new_binlog (void) { static int s[1000]; packet_ptr = s; - out_int (LOG_START); + out_int (CODE_binlog_start); out_int (CODE_binlog_dc_option); out_int (1); out_string (""); out_string (test_dc ? TG_SERVER_TEST : TG_SERVER); out_int (443); - out_int (LOG_DEFAULT_DC); + out_int (CODE_binlog_default_dc); out_int (1); int fd = open (get_binlog_file_name (), O_WRONLY | O_EXCL | O_CREAT, 0600); @@ -1255,7 +1314,7 @@ void bl_do_set_auth_key_id (int num, unsigned char *buf) { SHA1 (buf, 256, sha1_buffer); long long fingerprint = *(long long *)(sha1_buffer + 12); int *ev = alloc_log_event (8 + 8 + 256); - ev[0] = LOG_AUTH_KEY; + ev[0] = CODE_binlog_auth_key; ev[1] = num; *(long long *)(ev + 2) = fingerprint; memcpy (ev + 4, buf, 256); @@ -1264,14 +1323,14 @@ void bl_do_set_auth_key_id (int num, unsigned char *buf) { void bl_do_set_our_id (int id) { int *ev = alloc_log_event (8); - ev[0] = LOG_OUR_ID; + ev[0] = CODE_binlog_our_id; ev[1] = id; add_log_event (ev, 8); } -void bl_do_new_user (int id, const char *f, int fl, const char *l, int ll, long long access_token, const char *p, int pl, int contact) { +void bl_do_user_add (int id, const char *f, int fl, const char *l, int ll, long long access_token, const char *p, int pl, int contact) { clear_packet (); - out_int (CODE_binlog_new_user); + out_int (CODE_binlog_user_add); out_int (id); out_cstring (f ? f : "", fl); out_cstring (l ? l : "", ll); @@ -1289,22 +1348,18 @@ void bl_do_user_delete (struct user *U) { add_log_event (ev, 8); } -extern int last_date; void bl_do_set_user_profile_photo (struct user *U, long long photo_id, struct file_location *big, struct file_location *small) { if (photo_id == U->photo_id) { return; } if (!photo_id) { - int *ev = alloc_log_event (20); - ev[0] = CODE_update_user_photo; + int *ev = alloc_log_event (12); + ev[0] = CODE_binlog_user_set_photo; ev[1] = get_peer_id (U->id); - ev[2] = last_date; - ev[3] = CODE_user_profile_photo_empty; - ev[4] = CODE_bool_false; - add_log_event (ev, 20); + ev[2] = CODE_user_profile_photo_empty; + add_log_event (ev, 12); } else { clear_packet (); - out_int (CODE_update_user_photo); + out_int (CODE_binlog_user_set_photo); out_int (get_peer_id (U->id)); - out_int (last_date); out_int (CODE_user_profile_photo); out_long (photo_id); if (small->dc >= 0) { @@ -1331,48 +1386,47 @@ void bl_do_set_user_profile_photo (struct user *U, long long photo_id, struct fi out_int (big->local_id); out_long (big->secret); } - out_int (CODE_bool_false); add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer)); } } -void bl_do_set_user_name (struct user *U, const char *f, int fl, const char *l, int ll) { +void bl_do_user_set_name (struct user *U, const char *f, int fl, const char *l, int ll) { if ((U->first_name && (int)strlen (U->first_name) == fl && !strncmp (U->first_name, f, fl)) && (U->last_name && (int)strlen (U->last_name) == ll && !strncmp (U->last_name, l, ll))) { return; } clear_packet (); - out_int (CODE_update_user_name); + out_int (CODE_binlog_user_set_name); out_int (get_peer_id (U->id)); out_cstring (f, fl); out_cstring (l, ll); add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer)); } -void bl_do_set_user_access_token (struct user *U, long long access_token) { +void bl_do_user_set_access_hash (struct user *U, long long access_token) { if (U->access_hash == access_token) { return; } int *ev = alloc_log_event (16); - ev[0] = CODE_binlog_set_user_access_token; + ev[0] = CODE_binlog_user_set_access_hash; ev[1] = get_peer_id (U->id); *(long long *)(ev + 2) = access_token; add_log_event (ev, 16); } -void bl_do_set_user_phone (struct user *U, const char *p, int pl) { +void bl_do_user_set_phone (struct user *U, const char *p, int pl) { if (U->phone && (int)strlen (U->phone) == pl && !strncmp (U->phone, p, pl)) { return; } clear_packet (); - out_int (CODE_binlog_set_user_phone); + out_int (CODE_binlog_user_set_phone); out_int (get_peer_id (U->id)); out_cstring (p, pl); add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer)); } -void bl_do_set_user_friend (struct user *U, int friend) { +void bl_do_user_set_friend (struct user *U, int friend) { if (friend == ((U->flags & FLAG_USER_CONTACT) != 0)) { return ; } int *ev = alloc_log_event (12); - ev[0] = CODE_binlog_set_user_friend; + ev[0] = CODE_binlog_user_set_friend; ev[1] = get_peer_id (U->id); ev[2] = friend; add_log_event (ev, 12); @@ -1394,43 +1448,43 @@ void bl_do_dc_option (int id, int l1, const char *name, int l2, const char *ip, void bl_do_dc_signed (int id) { int *ev = alloc_log_event (8); - ev[0] = LOG_DC_SIGNED; + ev[0] = CODE_binlog_dc_signed; ev[1] = id; add_log_event (ev, 8); } void bl_do_set_working_dc (int num) { int *ev = alloc_log_event (8); - ev[0] = LOG_DEFAULT_DC; + ev[0] = CODE_binlog_default_dc; ev[1] = num; add_log_event (ev, 8); } -void bl_do_set_user_full_photo (struct user *U, const int *start, int len) { +void bl_do_user_set_full_photo (struct user *U, const int *start, int len) { if (U->photo.id == *(long long *)(start + 1)) { return; } int *ev = alloc_log_event (len + 8); - ev[0] = CODE_binlog_user_full_photo; + ev[0] = CODE_binlog_user_set_full_photo; ev[1] = get_peer_id (U->id); memcpy (ev + 2, start, len); add_log_event (ev, len + 8); } -void bl_do_set_user_blocked (struct user *U, int blocked) { +void bl_do_user_set_blocked (struct user *U, int blocked) { if (U->blocked == blocked) { return; } int *ev = alloc_log_event (12); - ev[0] = CODE_binlog_user_blocked; + ev[0] = CODE_binlog_user_set_blocked; ev[1] = get_peer_id (U->id); ev[2] = blocked; add_log_event (ev, 12); } -void bl_do_set_user_real_name (struct user *U, const char *f, int fl, const char *l, int ll) { +void bl_do_user_set_real_name (struct user *U, const char *f, int fl, const char *l, int ll) { if ((U->real_first_name && (int)strlen (U->real_first_name) == fl && !strncmp (U->real_first_name, f, fl)) && (U->real_last_name && (int)strlen (U->real_last_name) == ll && !strncmp (U->real_last_name, l, ll))) { return; } clear_packet (); - out_int (CODE_binlog_set_user_full_name); + out_int (CODE_binlog_user_set_real_name); out_int (get_peer_id (U->id)); out_cstring (f, fl); out_cstring (l, ll); @@ -1817,7 +1871,7 @@ void bl_do_create_message_service_fwd (int msg_id, int from_id, int to_type, int void bl_do_set_unread (struct message *M, int unread) { if (unread || !M->unread) { return; } clear_packet (); - out_int (CODE_binlog_set_unread); + out_int (CODE_binlog_message_set_unread); out_int (M->id); add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer)); } diff --git a/binlog.h b/binlog.h index 580c0b8..75b126e 100644 --- a/binlog.h +++ b/binlog.h @@ -21,30 +21,6 @@ #include "structures.h" -#define LOG_START 0x8948329a -#define LOG_AUTH_KEY 0x984932aa -#define LOG_DEFAULT_DC 0x95382908 -#define LOG_OUR_ID 0x8943211a -#define LOG_DC_SIGNED 0x234f9893 -#define LOG_DC_SALT 0x92192ffa -#define LOG_DH_CONFIG 0x8983402b -#define LOG_ENCR_CHAT_KEY 0x894320aa -#define LOG_ENCR_CHAT_SEND_ACCEPT 0x12ab01c4 -#define LOG_ENCR_CHAT_SEND_CREATE 0xab091e24 -#define LOG_ENCR_CHAT_DELETED 0x99481230 -#define LOG_ENCR_CHAT_WAITING 0x7102100a -#define LOG_ENCR_CHAT_REQUESTED 0x9011011a -#define LOG_ENCR_CHAT_OK 0x7612ce13 - -#define CODE_binlog_create_message_service 0xbbe5e94b -#define CODE_binlog_create_message_service_fwd 0xea9c57ae -#define CODE_binlog_create_message_media_fwd 0xbefdc462 -#define CODE_binlog_set_unread 0x21d4c909 -#define CODE_binlog_set_message_sent 0xc335282b -#define CODE_binlog_set_msg_id 0xf3285b6a -#define CODE_binlog_create_message_service_encr 0x8b4b9395 -#define CODE_binlog_delete_msg 0xa1d6ab6d - void *alloc_log_event (int l); void replay_log (void); void add_log_event (const int *data, int l); @@ -54,16 +30,16 @@ void bl_do_set_auth_key_id (int num, unsigned char *buf); void bl_do_dc_option (int id, int l1, const char *name, int l2, const char *ip, int port); void bl_do_set_our_id (int id); -void bl_do_new_user (int id, const char *f, int fl, const char *l, int ll, long long access_token, const char *p, int pl, int contact); +void bl_do_user_add (int id, const char *f, int fl, const char *l, int ll, long long access_token, const char *p, int pl, int contact); void bl_do_user_delete (struct user *U); void bl_do_set_user_profile_photo (struct user *U, long long photo_id, struct file_location *big, struct file_location *small); -void bl_do_set_user_name (struct user *U, const char *f, int fl, const char *l, int ll); -void bl_do_set_user_access_token (struct user *U, long long access_token); -void bl_do_set_user_phone (struct user *U, const char *p, int pl); -void bl_do_set_user_friend (struct user *U, int friend); -void bl_do_set_user_full_photo (struct user *U, const int *start, int len); -void bl_do_set_user_blocked (struct user *U, int blocked); -void bl_do_set_user_real_name (struct user *U, const char *f, int fl, const char *l, int ll); +void bl_do_user_set_name (struct user *U, const char *f, int fl, const char *l, int ll); +void bl_do_user_set_access_hash (struct user *U, long long access_token); +void bl_do_user_set_phone (struct user *U, const char *p, int pl); +void bl_do_user_set_friend (struct user *U, int friend); +void bl_do_user_set_full_photo (struct user *U, const int *start, int len); +void bl_do_user_set_blocked (struct user *U, int blocked); +void bl_do_user_set_real_name (struct user *U, const char *f, int fl, const char *l, int ll); void bl_do_encr_chat_delete (struct secret_chat *U); void bl_do_encr_chat_requested (struct secret_chat *U, long long access_hash, int date, int admin_id, int user_id, unsigned char g_key[], unsigned char nonce[]); diff --git a/binlog.tl b/binlog.tl index 5c1de43..c81c60d 100644 --- a/binlog.tl +++ b/binlog.tl @@ -3,6 +3,7 @@ binlog.fileLocation dc:int volume:long local_id:int secret:long = binlog.FileLoc binlog.chatParticipant user:int inviter:int date:int = binlog.ChatParticipant; binlog.start = binlog.Update; + binlog.dcOption 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; @@ -16,14 +17,16 @@ binlog.setQts qts:int = binlog.Update; binlog.setDate date:int = binlog.Update; binlog.setSeq seq:int = binlog.Update; -binlog.newUser id:int first_name:string last_name:string hash:long phone:string is_contact:int = binlog.Update; +binlog.userAdd id:int first_name:string last_name:string hash:long phone:string is_contact:int = binlog.Update; binlog.userDelete id:int = binlog.Update; -binlog.setUserAccessToken id:int hash:long = binlog.Update; -binlog.setUserPhone id:int phone:string = binlog.Update; -binlog.setUserFriend id:int friend:int = binlog.Update; -binlog.userFullPhoto id:int photo:Photo = binlog.Update; -binlog.userBlocked id:int blocked:int = binlog.Update; -binlog.setUserFullName id:int real_first_name:string real_last_name:string = binlog.Update; +binlog.userSetAccessHash id:int hash:long = binlog.Update; +binlog.userSetPhone id:int phone:string = binlog.Update; +binlog.userSetFriend id:int friend:int = binlog.Update; +binlog.userSetFullPhoto id:int photo:Photo = binlog.Update; +binlog.userSetBlocked id:int blocked:int = binlog.Update; +binlog.userSetRealName id:int real_first_name:string real_last_name:string = binlog.Update; +binlog.userSetName id:int first_name:string last_name:string = binlog.Update; +binlog.userSetPhoto id:int photo:UserProfilePhoto = binlog.Update; binlog.encrChatDelete id:int = binlog.Update; binlog.encrChatRequested id:int hash:long date:int admin:int user:int key:64*[int] nonce:64*[int] = binlog.Update; @@ -34,7 +37,6 @@ binlog.encrChatAccepted id:int key:64*[int] nonce:64*[int] fingerprint:long = bi binlog.setEncrChatKey id:int key:64*[int] fingerprint:long = binlog.Update; binlog.encrChatInit id:int user:int key:64*[int] g_key:64*[int] = binlog.Update; - binlog.chatCreate id:int flags:int title:string user_num:int date:int version:int photo_big:%binlog.FileLocation photo_small:%binlog.FileLocation = binlog.Update; binlog.chatChangeFlags id:int set_flags:int clear_flags:int = binlog.Update; binlog.setChatTitle id:int title:string = binlog.Update; @@ -52,3 +54,11 @@ binlog.sendMessageText id:long from_id:int to_type:int to_id:int date:int text:s binlog.createMessageTextFwd id:int from_id:int to_type:int to_id:int date:int fwd_from_id:int fwd_date:int text:string = binlog.Update; binlog.createMessageMedia id:int from_id:int to_type:int to_id:int date:int text:string media:MessageMedia = binlog.Update; binlog.createMessageMediaEncr id:int from_id:int to_type:int to_id:int date:int text:string media:DecryptedMessageMedia file:EncryptedFile = binlog.Update; +binlog.createMessageMediaFwd id:int from_id:int to_type:int to_id:int date:int fwd_from_id:int fwd_date:int text:string media:MessageMedia = binlog.Update; +binlog.createMessageService id:int from_id:int to_type:int to_id:int date:int action:MessageAction = binlog.Update; +binlog.createMessageServiceEncr id:int from_id:int to_type:int to_id:int date:int action:DecryptedMessageAction = binlog.Update; +binlog.createMessageServiceFwd id:int from_id:int to_type:int to_id:int date:int fwd_from_id:int fwd_date:int action:MessageAction = binlog.Update; +binlog.messageSetUnread id:int = binlog.Update; +binlog.setMessageSent id:long = binlog.Update; +binlog.setMsgId old_id:long new_id:int = binlog.Update; +binlog.deleteMsg id:long = binlog.Update; diff --git a/generate.c b/generate.c index 71810e4..19d2c6a 100644 --- a/generate.c +++ b/generate.c @@ -376,9 +376,9 @@ int gen_field_fetch (struct arg *arg, int *vars, int num) { bare = ((struct tl_tree_type *)arg->type)->self.flags & FLAG_BARE; } if (!bare) { - printf ("%sif (skip_type_%s (field%d) < 0) { return -1;}\n", offset, t == NODE_TYPE_VAR_TYPE ? "any" : ((struct tl_tree_type *)arg->type)->type->id, num); + printf ("%sif (skip_type_%s (field%d) < 0) { return -1;}\n", offset, t == NODE_TYPE_VAR_TYPE ? "any" : ((struct tl_tree_type *)arg->type)->type->print_id, num); } else { - printf ("%sif (skip_type_bare_%s (field%d) < 0) { return -1;}\n", offset, t == NODE_TYPE_VAR_TYPE ? "any" : ((struct tl_tree_type *)arg->type)->type->id, num); + printf ("%sif (skip_type_bare_%s (field%d) < 0) { return -1;}\n", offset, t == NODE_TYPE_VAR_TYPE ? "any" : ((struct tl_tree_type *)arg->type)->type->print_id, num); } } else { assert (t == NODE_TYPE_ARRAY); @@ -400,7 +400,7 @@ int gen_field_fetch (struct arg *arg, int *vars, int num) { } void gen_constructor_fetch (struct tl_combinator *c) { - printf ("int skip_constructor_%s (struct paramed_type *T) {\n", c->id); + printf ("int skip_constructor_%s (struct paramed_type *T) {\n", c->print_id); static char s[10000]; sprintf (s, "T"); @@ -439,21 +439,21 @@ void gen_constructor_fetch (struct tl_combinator *c) { } void gen_type_fetch (struct tl_type *t) { - printf ("int skip_type_%s (struct paramed_type *T) {\n", t->id); + printf ("int skip_type_%s (struct paramed_type *T) {\n", t->print_id); printf (" int magic = *in_ptr;\n"); printf (" if (skip_int () < 0) { return -1; }\n"); printf (" switch (magic) {\n"); int i; for (i = 0; i < t->constructors_num; i++) { - printf (" case 0x%08x: return skip_constructor_%s (T);\n", t->constructors[i]->name, t->constructors[i]->id); + printf (" case 0x%08x: return skip_constructor_%s (T);\n", t->constructors[i]->name, t->constructors[i]->print_id); } printf (" default: return -1;\n"); printf (" }\n"); printf ("}\n"); - printf ("int skip_type_bare_%s (struct paramed_type *T) {\n", t->id); + printf ("int skip_type_bare_%s (struct paramed_type *T) {\n", t->print_id); printf (" int *save = in_ptr;\n"); for (i = 0; i < t->constructors_num; i++) { - printf (" if (skip_constructor_%s (T) >= 0) { return 0; }\n", t->constructors[i]->id); + printf (" if (skip_constructor_%s (T) >= 0) { return 0; }\n", t->constructors[i]->print_id); printf (" in_ptr = save;\n"); } printf (" return -1;\n"); @@ -694,12 +694,35 @@ int read_combinator_left (struct tl_combinator *c) { } } +char *gen_print_id (const char *id) { + static char s[1000]; + char *ptr = s; + int first = 1; + while (*id) { + if (*id == '.') { + *(ptr ++) = '_'; + } else if (*id >= 'A' && *id <= 'Z') { + if (!first && *(ptr - 1) != '_') { + *(ptr ++) = '_'; + } + *(ptr ++) = *id - 'A' + 'a'; + } else { + *(ptr ++) = *id; + } + id ++; + first = 0; + } + *ptr = 0; + return s; +} + struct tl_combinator *read_combinators (int v) { struct tl_combinator *c = malloc0 (sizeof (*c)); c->name = get_int (); c->id = get_string (); - char *s = c->id; - while (*s) { if (*s == '.') { *s = '_'; } ; s ++;} + c->print_id = strdup (gen_print_id (c->id)); + //char *s = c->id; + //while (*s) { if (*s == '.') { *s = '_'; } ; s ++;} int x = get_int (); struct tl_type *t = tl_type_get_by_name (x); assert (t || (!x && v == 3)); @@ -722,8 +745,7 @@ struct tl_type *read_types (void) { struct tl_type *t = malloc0 (sizeof (*t)); t->name = get_int (); t->id = get_string (); - char *s = t->id; - while (*s) { if (*s == '.') { *s = '_'; } ; s++; } + t->print_id = strdup (gen_print_id (t->id)); t->constructors_num = get_int (); assert (t->constructors_num >= 0 && t->constructors_num <= 1000); @@ -870,20 +892,20 @@ int parse_tlo_file (void) { printf ("int skip_type_any (struct paramed_type *T) {\n"); printf (" switch (T->type->name) {\n"); for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type")) { - printf (" case 0x%08x: return skip_type_%s (T);\n", tps[i]->name, tps[i]->id); - printf (" case 0x%08x: return skip_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->id); + printf (" case 0x%08x: return skip_type_%s (T);\n", tps[i]->name, tps[i]->print_id); + printf (" case 0x%08x: return skip_type_bare_%s (T);\n", ~tps[i]->name, tps[i]->print_id); } printf (" default: return -1; }\n"); printf ("}\n"); } else { for (i = 0; i < tn; i++) { for (j = 0; j < tps[i]->constructors_num; j ++) { - printf ("int skip_constructor_%s (struct paramed_type *T);\n", tps[i]->constructors[j]->id); + printf ("int skip_constructor_%s (struct paramed_type *T);\n", tps[i]->constructors[j]->print_id); } } for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type")) { - printf ("int skip_type_%s (struct paramed_type *T);\n", tps[i]->id); - printf ("int skip_type_bare_%s (struct paramed_type *T);\n", tps[i]->id); + printf ("int skip_type_%s (struct paramed_type *T);\n", tps[i]->print_id); + printf ("int skip_type_bare_%s (struct paramed_type *T);\n", tps[i]->print_id); } printf ("int skip_type_any (struct paramed_type *T);\n"); @@ -891,13 +913,13 @@ int parse_tlo_file (void) { printf ("extern struct tl_type tl_type_%s;\n", tps[i]->id); }*/ for (i = 0; i < tn; i++) if (tps[i]->id[0] != '#' && strcmp (tps[i]->id, "Type")) { - printf ("static struct tl_type tl_type_%s __attribute__ ((unused));\n", tps[i]->id); - printf ("static struct tl_type tl_type_%s = {\n", tps[i]->id); + printf ("static struct tl_type tl_type_%s __attribute__ ((unused));\n", tps[i]->print_id); + printf ("static struct tl_type tl_type_%s = {\n", tps[i]->print_id); printf (" .name = 0x%08x,\n", tps[i]->name); printf (" .id = \"%s\"\n", tps[i]->id); printf ("};\n"); - printf ("static struct tl_type tl_type_bare_%s __attribute__ ((unused));\n", tps[i]->id); - printf ("static struct tl_type tl_type_bare_%s = {\n", tps[i]->id); + printf ("static struct tl_type tl_type_bare_%s __attribute__ ((unused));\n", tps[i]->print_id); + printf ("static struct tl_type tl_type_bare_%s = {\n", tps[i]->print_id); printf (" .name = 0x%08x,\n", ~tps[i]->name); printf (" .id = \"Bare_%s\"\n", tps[i]->id); printf ("};\n"); diff --git a/generate.h b/generate.h index 8e42e0f..240faa4 100644 --- a/generate.h +++ b/generate.h @@ -6,6 +6,7 @@ struct tl_combinator; struct tl_type { // struct tl_type_methods *methods; char *id; + char *print_id; unsigned name; int arity; int flags; @@ -131,6 +132,7 @@ struct arg { struct tl_combinator { //struct tl_combinator_methods *methods; char *id; + char *print_id; unsigned name; int is_fun; int var_num; diff --git a/lua-tg.h b/lua-tg.h index cf07768..0878860 100644 --- a/lua-tg.h +++ b/lua-tg.h @@ -14,4 +14,5 @@ void lua_binlog_end (void); void lua_diff_end (void); void lua_do_all (void); #define lua_secret_chat_update(x) +#define lua_update_msg(x) #endif diff --git a/mtproto-client.c b/mtproto-client.c index be22d01..ec3ec6f 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -839,7 +839,7 @@ void fetch_seq (void) { bl_do_set_seq (seq); } } - +/* void work_update_binlog (void) { unsigned op = fetch_int (); switch (op) { @@ -901,7 +901,7 @@ void work_update_binlog (void) { default: assert (0); } -} +}*/ void work_update (struct connection *c UU, long long msg_id UU) { unsigned op = fetch_int (); @@ -1018,7 +1018,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { int l2 = prefetch_strlen (); char *l = fetch_str (l2); struct user *U = &UC->user; - bl_do_set_user_real_name (U, f, l1, l, l2); + bl_do_user_set_real_name (U, f, l1, l, l2); print_start (); push_color (COLOR_YELLOW); print_date (time (0)); @@ -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 (TYPE_TO_PARAM (Updates))); + assert (!skip_type_any (TYPE_TO_PARAM (updates))); int *save_end = in_ptr; in_ptr = save; assert (fetch_int () == CODE_updates); diff --git a/queries.c b/queries.c index 2a258dd..52b84fa 100644 --- a/queries.c +++ b/queries.c @@ -388,11 +388,12 @@ int help_get_config_on_answer (struct query *q UU) { struct query_methods help_get_config_methods = { .on_answer = help_get_config_on_answer, - .type = TYPE_TO_PARAM(Config) + .type = TYPE_TO_PARAM(config) }; void do_help_get_config (void) { clear_packet (); + do_insert_header (); out_int (CODE_help_get_config); send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &help_get_config_methods, 0); } @@ -434,7 +435,7 @@ int send_code_on_error (struct query *q UU, int error_code, int l, char *error) struct query_methods send_code_methods = { .on_answer = send_code_on_answer, .on_error = send_code_on_error, - .type = TYPE_TO_PARAM(auth_SentCode) + .type = TYPE_TO_PARAM(auth_sent_code) }; int code_is_sent (void) { @@ -504,7 +505,7 @@ int phone_call_on_error (struct query *q UU, int error_code, int l, char *error) struct query_methods phone_call_methods = { .on_answer = phone_call_on_answer, .on_error = phone_call_on_error, - .type = TYPE_TO_PARAM(Bool) + .type = TYPE_TO_PARAM(bool) }; void do_phone_call (const char *user) { @@ -569,7 +570,7 @@ int check_phone_on_error (struct query *q UU, int error_code, int l, char *error struct query_methods check_phone_methods = { .on_answer = check_phone_on_answer, .on_error = check_phone_on_error, - .type = TYPE_TO_PARAM(auth_CheckedPhone) + .type = TYPE_TO_PARAM(auth_checked_phone) }; int do_auth_check_phone (const char *user) { @@ -614,7 +615,7 @@ int fail_on_error (struct query *q UU, int error_code UU, int l UU, char *error struct query_methods nearest_dc_methods = { .on_answer = nearest_dc_on_answer, .on_error = fail_on_error, - .type = TYPE_TO_PARAM(NearestDc) + .type = TYPE_TO_PARAM(nearest_dc) }; int do_get_nearest_dc (void) { @@ -666,7 +667,7 @@ int sign_in_on_error (struct query *q UU, int error_code, int l, char *error) { struct query_methods sign_in_methods = { .on_answer = sign_in_on_answer, .on_error = sign_in_on_error, - .type = TYPE_TO_PARAM(auth_Authorization) + .type = TYPE_TO_PARAM(auth_authorization) }; int do_send_code_result (const char *code) { @@ -746,7 +747,7 @@ int get_contacts_on_answer (struct query *q UU) { struct query_methods get_contacts_methods = { .on_answer = get_contacts_on_answer, - .type = TYPE_TO_PARAM(contacts_Contacts) + .type = TYPE_TO_PARAM(contacts_contacts) }; @@ -913,12 +914,12 @@ int msg_send_on_error (struct query *q, int error_code, int error_len, char *err struct query_methods msg_send_methods = { .on_answer = msg_send_on_answer, .on_error = msg_send_on_error, - .type = TYPE_TO_PARAM(messages_SentMessage) + .type = TYPE_TO_PARAM(messages_sent_message) }; struct query_methods msg_send_encr_methods = { .on_answer = msg_send_encr_on_answer, - .type = TYPE_TO_PARAM(messages_SentEncryptedMessage) + .type = TYPE_TO_PARAM(messages_sent_encrypted_message) }; int out_message_num; @@ -1023,12 +1024,12 @@ int mark_read_encr_on_receive (struct query *q UU) { struct query_methods mark_read_methods = { .on_answer = mark_read_on_receive, - .type = TYPE_TO_PARAM(messages_AffectedHistory) + .type = TYPE_TO_PARAM(messages_affected_history) }; struct query_methods mark_read_encr_methods = { .on_answer = mark_read_encr_on_receive, - .type = TYPE_TO_PARAM(Bool) + .type = TYPE_TO_PARAM(bool) }; void do_messages_mark_read (peer_id_t id, int max_id) { @@ -1116,7 +1117,7 @@ int get_history_on_answer (struct query *q UU) { struct query_methods get_history_methods = { .on_answer = get_history_on_answer, - .type = TYPE_TO_PARAM(messages_Messages) + .type = TYPE_TO_PARAM(messages_messages) }; void do_get_local_history (peer_id_t id, int limit) { @@ -1220,7 +1221,7 @@ int get_dialogs_on_answer (struct query *q UU) { struct query_methods get_dialogs_methods = { .on_answer = get_dialogs_on_answer, - .type = TYPE_TO_PARAM(messages_Dialogs) + .type = TYPE_TO_PARAM(messages_dialogs) }; @@ -1325,17 +1326,17 @@ int send_encr_file_on_answer (struct query *q UU) { struct query_methods send_file_part_methods = { .on_answer = send_file_part_on_answer, - .type = TYPE_TO_PARAM(Bool) + .type = TYPE_TO_PARAM(bool) }; struct query_methods send_file_methods = { .on_answer = send_file_on_answer, - .type = TYPE_TO_PARAM(messages_StatedMessage) + .type = TYPE_TO_PARAM(messages_stated_message) }; struct query_methods send_encr_file_methods = { .on_answer = send_encr_file_on_answer, - .type = TYPE_TO_PARAM(messages_SentEncryptedMessage) + .type = TYPE_TO_PARAM(messages_sent_encrypted_message) }; void send_part (struct send_file *f) { @@ -1618,7 +1619,7 @@ int fwd_msg_on_answer (struct query *q UU) { struct query_methods fwd_msg_methods = { .on_answer = fwd_msg_on_answer, - .type = TYPE_TO_PARAM(messages_StatedMessage) + .type = TYPE_TO_PARAM(messages_stated_message) }; void do_forward_message (peer_id_t id, int n) { @@ -1658,7 +1659,7 @@ int rename_chat_on_answer (struct query *q UU) { struct query_methods rename_chat_methods = { .on_answer = rename_chat_on_answer, - .type = TYPE_TO_PARAM(messages_StatedMessage) + .type = TYPE_TO_PARAM(messages_stated_message) }; void do_rename_chat (peer_id_t id, char *name UU) { @@ -1704,7 +1705,7 @@ int chat_info_on_answer (struct query *q UU) { struct query_methods chat_info_methods = { .on_answer = chat_info_on_answer, - .type = TYPE_TO_PARAM(messages_ChatFull) + .type = TYPE_TO_PARAM(messages_chat_full) }; void do_get_chat_info (peer_id_t id) { @@ -1755,7 +1756,7 @@ int user_info_on_answer (struct query *q UU) { struct query_methods user_info_methods = { .on_answer = user_info_on_answer, - .type = TYPE_TO_PARAM(UserFull) + .type = TYPE_TO_PARAM(user_full) }; void do_get_user_info (peer_id_t id) { @@ -1797,7 +1798,7 @@ 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, - .type = TYPE_TO_PARAM_1(Vector, TYPE_TO_PARAM(User)) + .type = TYPE_TO_PARAM_1(vector, TYPE_TO_PARAM(user)) }; void do_get_user_list_info_silent (int num, int *list) { @@ -1900,7 +1901,7 @@ int download_on_answer (struct query *q) { struct query_methods download_methods = { .on_answer = download_on_answer, - .type = TYPE_TO_PARAM(upload_File) + .type = TYPE_TO_PARAM(upload_file) }; void load_next_part (struct download *D) { @@ -2102,7 +2103,7 @@ 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, - .type = TYPE_TO_PARAM(auth_ExportedAuthorization) + .type = TYPE_TO_PARAM(auth_exported_authorization) }; void do_export_auth (int num) { @@ -2128,11 +2129,12 @@ 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, - .type = TYPE_TO_PARAM(auth_Authorization) + .type = TYPE_TO_PARAM(auth_authorization) }; void do_import_auth (int num) { clear_packet (); + do_insert_header (); out_int (CODE_auth_import_authorization); out_int (our_id); out_cstring (export_auth_str, export_auth_str_len); @@ -2194,7 +2196,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) + .type = TYPE_TO_PARAM(contacts_imported_contacts) }; 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) { @@ -2219,7 +2221,7 @@ int msg_search_on_answer (struct query *q UU) { struct query_methods msg_search_methods = { .on_answer = msg_search_on_answer, - .type = TYPE_TO_PARAM(messages_Messages) + .type = TYPE_TO_PARAM(messages_messages) }; void do_msg_search (peer_id_t id, int from, int to, int limit, const char *s) { @@ -2274,7 +2276,7 @@ int contacts_search_on_answer (struct query *q UU) { struct query_methods contacts_search_methods = { .on_answer = contacts_search_on_answer, - .type = TYPE_TO_PARAM(contacts_Found) + .type = TYPE_TO_PARAM(contacts_found) }; void do_contacts_search (int limit, const char *s) { @@ -2336,12 +2338,12 @@ int send_encr_request_on_answer (struct query *q UU) { struct query_methods send_encr_accept_methods = { .on_answer = send_encr_accept_on_answer, - .type = TYPE_TO_PARAM(EncryptedChat) + .type = TYPE_TO_PARAM(encrypted_chat) }; struct query_methods send_encr_request_methods = { .on_answer = send_encr_request_on_answer, - .type = TYPE_TO_PARAM(EncryptedChat) + .type = TYPE_TO_PARAM(encrypted_chat) }; int encr_root; @@ -2529,8 +2531,8 @@ void do_send_create_encr_chat (void *x, unsigned char *random) { int get_dh_config_on_answer (struct query *q UU) { unsigned x = fetch_int (); - assert (x == CODE_messages_dh_config || x == CODE_messages_dh_config_not_modified || LOG_DH_CONFIG); - if (x == CODE_messages_dh_config || x == LOG_DH_CONFIG) { + assert (x == CODE_messages_dh_config || x == CODE_messages_dh_config_not_modified); + if (x == CODE_messages_dh_config) { int a = fetch_int (); int l = prefetch_strlen (); assert (l == 256); @@ -2543,7 +2545,6 @@ int get_dh_config_on_answer (struct query *q UU) { assert (check_DH_params (p, a) >= 0); BN_free (p); } - if (x == LOG_DH_CONFIG) { return 0; } int l = prefetch_strlen (); assert (l == 256); unsigned char *random = talloc (256); @@ -2561,7 +2562,7 @@ int get_dh_config_on_answer (struct query *q UU) { struct query_methods get_dh_config_methods = { .on_answer = get_dh_config_on_answer, - .type = TYPE_TO_PARAM(messages_DhConfig) + .type = TYPE_TO_PARAM(messages_dh_config) }; void do_accept_encr_chat_request (struct secret_chat *E) { @@ -2673,12 +2674,12 @@ int get_difference_on_answer (struct query *q UU) { struct query_methods get_state_methods = { .on_answer = get_state_on_answer, - .type = TYPE_TO_PARAM(updates_State) + .type = TYPE_TO_PARAM(updates_state) }; struct query_methods get_difference_methods = { .on_answer = get_difference_on_answer, - .type = TYPE_TO_PARAM(updates_Difference) + .type = TYPE_TO_PARAM(updates_difference) }; void do_get_difference (void) { @@ -2766,7 +2767,7 @@ int get_suggested_on_answer (struct query *q UU) { struct query_methods get_suggested_methods = { .on_answer = get_suggested_on_answer, - .type = TYPE_TO_PARAM(contacts_Suggested) + .type = TYPE_TO_PARAM(contacts_suggested) }; void do_get_suggested (void) { @@ -2781,7 +2782,7 @@ void do_get_suggested (void) { struct query_methods add_user_to_chat_methods = { .on_answer = fwd_msg_on_answer, - .type = TYPE_TO_PARAM(MessageAction) + .type = TYPE_TO_PARAM(message_action) }; void do_add_user_to_chat (peer_id_t chat_id, peer_id_t id, int limit) { @@ -2840,7 +2841,7 @@ 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, - .type = TYPE_TO_PARAM(MessageAction) + .type = TYPE_TO_PARAM(message_action) }; void do_create_group_chat (peer_id_t id, char *chat_topic) { @@ -2880,7 +2881,7 @@ int delete_msg_on_answer (struct query *q UU) { struct query_methods delete_msg_methods = { .on_answer = delete_msg_on_answer, - .type = TYPE_TO_PARAM_1(Vector, TYPE_TO_PARAM (bare_Int)) + .type = TYPE_TO_PARAM_1(vector, TYPE_TO_PARAM (bare_int)) }; void do_delete_msg (long long id) { @@ -2905,7 +2906,7 @@ int restore_msg_on_answer (struct query *q UU) { struct query_methods restore_msg_methods = { .on_answer = restore_msg_on_answer, - .type = TYPE_TO_PARAM_1(Vector, TYPE_TO_PARAM (bare_Int)) + .type = TYPE_TO_PARAM_1(vector, TYPE_TO_PARAM (bare_int)) }; void do_restore_msg (long long id) { @@ -2924,7 +2925,7 @@ int update_status_on_answer (struct query *q UU) { struct query_methods update_status_methods = { .on_answer = update_status_on_answer, - .type = TYPE_TO_PARAM(Bool) + .type = TYPE_TO_PARAM(bool) }; void do_update_status (int online UU) { diff --git a/structures.c b/structures.c index 6586ffd..080d21c 100644 --- a/structures.c +++ b/structures.c @@ -198,7 +198,7 @@ int fetch_user (struct user *U) { char *s2 = fetch_str (l2); if (x == CODE_user_deleted && !(U->flags & FLAG_DELETED)) { - bl_do_new_user (get_peer_id (U->id), s1, l1, s2, l2, 0, 0, 0, 0); + bl_do_user_add (get_peer_id (U->id), s1, l1, s2, l2, 0, 0, 0, 0); bl_do_user_delete (U); } if (x != CODE_user_deleted) { @@ -213,7 +213,7 @@ int fetch_user (struct user *U) { 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); + bl_do_user_add (get_peer_id (U->id), s1, l1, s2, l2, access_token, phone, phone_len, x == CODE_user_contact); if (fetch_user_photo (U) < 0) { return -1; } if (fetch_user_status (&U->status) < 0) { return -1; } @@ -227,19 +227,19 @@ int fetch_user (struct user *U) { int l2 = prefetch_strlen (); char *s2 = fetch_str (l2); - bl_do_set_user_name (U, s1, l1, s2, l2); + bl_do_user_set_name (U, s1, l1, s2, l2); if (x == CODE_user_deleted && !(U->flags & FLAG_DELETED)) { bl_do_user_delete (U); } if (x != CODE_user_deleted) { if (x != CODE_user_self) { - bl_do_set_user_access_token (U, fetch_long ()); + bl_do_user_set_access_hash (U, fetch_long ()); } if (x != CODE_user_foreign) { int l = prefetch_strlen (); char *s = fetch_str (l); - bl_do_set_user_phone (U, s, l); + bl_do_user_set_phone (U, s, l); } assert (fetch_user_photo (U) >= 0); @@ -249,9 +249,9 @@ int fetch_user (struct user *U) { } if (x == CODE_user_contact) { - bl_do_set_user_friend (U, 1); + bl_do_user_set_friend (U, 1); } else { - bl_do_set_user_friend (U, 0); + bl_do_user_set_friend (U, 0); } } } @@ -340,20 +340,20 @@ void fetch_encrypted_chat (struct secret_chat *U) { void fetch_user_full (struct user *U) { assert (fetch_int () == CODE_user_full); fetch_alloc_user (); - assert (skip_type_any (TYPE_TO_PARAM (contacts_Link)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (contacts_link)) >= 0); int *start = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (Photo)) >= 0); - bl_do_set_user_full_photo (U, start, 4 * (in_ptr - start)); + assert (skip_type_any (TYPE_TO_PARAM (photo)) >= 0); + bl_do_user_set_full_photo (U, start, 4 * (in_ptr - start)); - assert (skip_type_any (TYPE_TO_PARAM (PeerNotifySettings)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (peer_notify_settings)) >= 0); - bl_do_set_user_blocked (U, fetch_bool ()); + bl_do_user_set_blocked (U, fetch_bool ()); int l1 = prefetch_strlen (); char *s1 = fetch_str (l1); int l2 = prefetch_strlen (); char *s2 = fetch_str (l2); - bl_do_set_user_real_name (U, s1, l1, s2, l2); + bl_do_user_set_real_name (U, s1, l1, s2, l2); } void fetch_chat (struct chat *C) { @@ -470,9 +470,9 @@ void fetch_chat_full (struct chat *C) { version = fetch_int (); } int *start = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (Photo)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (photo)) >= 0); int *end = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (PeerNotifySettings)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (peer_notify_settings)) >= 0); int n, i; assert (fetch_int () == CODE_vector); @@ -932,7 +932,7 @@ void fetch_message (struct message *M) { if (x == CODE_message_service) { int *start = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (MessageAction)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (message_action)) >= 0); if (new) { if (fwd_from_id) { @@ -946,7 +946,7 @@ void fetch_message (struct message *M) { char *s = fetch_str (l); int *start = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (MessageMedia)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (message_media)) >= 0); if (new) { if (fwd_from_id) { @@ -1097,11 +1097,11 @@ void fetch_encrypted_message (struct message *M) { l = prefetch_strlen (); s = fetch_str (l); start = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (DecryptedMessageMedia)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (decrypted_message_media)) >= 0); end = in_ptr; } else { start = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (DecryptedMessageAction)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (decrypted_message_action)) >= 0); end = in_ptr; } in_ptr = save_in_ptr; @@ -1111,7 +1111,7 @@ void fetch_encrypted_message (struct message *M) { if (sx == CODE_encrypted_message) { if (ok) { int *start_file = in_ptr; - assert (skip_type_any (TYPE_TO_PARAM (EncryptedFile)) >= 0); + assert (skip_type_any (TYPE_TO_PARAM (encrypted_file)) >= 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); } diff --git a/structures.h b/structures.h index ad4360f..bc5f19f 100644 --- a/structures.h +++ b/structures.h @@ -39,13 +39,14 @@ typedef struct { int type; int id; } peer_id_t; #define FLAG_ENCRYPTED 4096 #define FLAG_PENDING 8192 - +#pragma pack(push,4) struct file_location { int dc; long long volume; int local_id; long long secret; }; +#pragma pack(pop) struct photo_size { char *type; diff --git a/telegram.h b/telegram.h index d72da12..f8645c6 100644 --- a/telegram.h +++ b/telegram.h @@ -20,5 +20,5 @@ #define MAX_PEER_NUM 100000 #ifndef PROG_NAME -#define PROG_NAME "telegram" +#define PROG_NAME "telegram-cli" #endif