2014-08-21 18:02:43 -04:00
|
|
|
/*
|
|
|
|
This file is part of tgl-library
|
2013-11-30 05:12:51 -05:00
|
|
|
|
2014-08-21 18:02:43 -04:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2013-11-30 05:12:51 -05:00
|
|
|
|
2014-08-21 18:02:43 -04:00
|
|
|
This library is distributed in the hope that it will be useful,
|
2013-11-30 05:12:51 -05:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-08-21 18:02:43 -04:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2013-11-30 05:12:51 -05:00
|
|
|
|
2014-08-21 18:02:43 -04:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2013-11-30 05:12:51 -05:00
|
|
|
|
2014-08-21 18:02:43 -04:00
|
|
|
Copyright Vitaly Valtman 2013-2014
|
2013-11-30 05:12:51 -05:00
|
|
|
*/
|
2014-01-13 08:05:25 -05:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-08-13 08:56:55 -04:00
|
|
|
# include "config.h"
|
2014-01-13 08:05:25 -05:00
|
|
|
#endif
|
|
|
|
|
2013-11-12 19:11:25 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2013-11-29 18:15:10 -05:00
|
|
|
#include <sys/file.h>
|
2013-11-12 19:11:25 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2013-12-23 06:10:53 -05:00
|
|
|
#include <openssl/bn.h>
|
2013-11-12 19:11:25 -05:00
|
|
|
|
|
|
|
#include "binlog.h"
|
|
|
|
#include "mtproto-common.h"
|
2014-10-24 13:43:08 -04:00
|
|
|
//#include "net.h"
|
2013-11-14 19:08:24 -05:00
|
|
|
#include "include.h"
|
2013-11-21 14:35:49 -05:00
|
|
|
#include "mtproto-client.h"
|
2014-08-13 08:56:55 -04:00
|
|
|
|
|
|
|
#include "tgl.h"
|
2014-08-14 14:03:33 -04:00
|
|
|
#include "auto.h"
|
2013-11-21 14:35:49 -05:00
|
|
|
|
2014-08-14 18:16:01 -04:00
|
|
|
#include "structures.h"
|
|
|
|
|
2013-11-21 14:35:49 -05:00
|
|
|
#include <openssl/sha.h>
|
2013-11-12 19:11:25 -05:00
|
|
|
|
|
|
|
#define BINLOG_BUFFER_SIZE (1 << 20)
|
2014-08-13 08:56:55 -04:00
|
|
|
static int binlog_buffer[BINLOG_BUFFER_SIZE];
|
|
|
|
static int *rptr;
|
|
|
|
static int *wptr;
|
2014-10-24 13:43:08 -04:00
|
|
|
//static int TLS->binlog_fd;
|
2014-08-27 11:12:45 -04:00
|
|
|
static int in_replay_log; // should be used ONLY for DEBUG
|
2014-08-13 08:56:55 -04:00
|
|
|
|
2013-11-21 16:40:31 -05:00
|
|
|
|
2013-11-12 19:11:25 -05:00
|
|
|
#define MAX_LOG_EVENT_SIZE (1 << 17)
|
|
|
|
|
|
|
|
char *get_binlog_file_name (void);
|
2014-08-13 11:55:16 -04:00
|
|
|
|
|
|
|
static void *alloc_log_event (int l UU) {
|
2013-11-14 19:08:24 -05:00
|
|
|
return binlog_buffer;
|
|
|
|
}
|
2013-11-12 19:11:25 -05:00
|
|
|
|
2014-08-13 08:56:55 -04:00
|
|
|
static long long binlog_pos;
|
2013-11-21 14:35:49 -05:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_start (struct tgl_state *TLS, void *extra) {
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_dc_option (struct tgl_state *TLS, void *extra) {
|
2014-08-12 11:15:04 -04:00
|
|
|
int id = fetch_int ();
|
|
|
|
int l1 = prefetch_strlen ();
|
|
|
|
assert (l1 >= 0);
|
|
|
|
char *name = fetch_str (l1);
|
|
|
|
int l2 = prefetch_strlen ();
|
|
|
|
assert (l2 >= 0);
|
|
|
|
char *ip = fetch_str (l2);
|
|
|
|
int port = fetch_int ();
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
vlogprintf (E_NOTICE, "DC%d '%.*s' update: %.*s:%d\n", id, l1, name, l2, ip, port);
|
2014-08-12 11:15:04 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglmp_alloc_dc (TLS, id, tstrndup (ip, l2), port);
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_auth_key (struct tgl_state *TLS, void *extra) {
|
2014-08-12 11:15:04 -04:00
|
|
|
int num = fetch_int ();
|
|
|
|
assert (num >= 0 && num <= MAX_DC_ID);
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (TLS->DC_list[num]);
|
|
|
|
TLS->DC_list[num]->auth_key_id = fetch_long ();
|
|
|
|
fetch_ints (TLS->DC_list[num]->auth_key, 64);
|
|
|
|
TLS->DC_list[num]->flags |= 1;
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_default_dc (struct tgl_state *TLS, void *extra) {
|
2014-08-12 11:15:04 -04:00
|
|
|
int num = fetch_int ();
|
|
|
|
assert (num >= 0 && num <= MAX_DC_ID);
|
2014-10-24 13:43:08 -04:00
|
|
|
TLS->DC_working = TLS->DC_list[num];
|
|
|
|
TLS->dc_working_num = num;
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_our_id (struct tgl_state *TLS, void *extra) {
|
|
|
|
TLS->our_id = fetch_int ();
|
|
|
|
if (TLS->callback.our_id) {
|
|
|
|
TLS->callback.our_id (TLS, TLS->our_id);
|
2014-08-21 11:38:51 -04:00
|
|
|
}
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_dc_signed (struct tgl_state *TLS, void *extra) {
|
2014-08-12 11:15:04 -04:00
|
|
|
int num = fetch_int ();
|
|
|
|
assert (num >= 0 && num <= MAX_DC_ID);
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (TLS->DC_list[num]);
|
|
|
|
TLS->DC_list[num]->has_auth = 1;
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_dc_salt (struct tgl_state *TLS, void *extra) {
|
2014-08-12 11:15:04 -04:00
|
|
|
int num = fetch_int ();
|
|
|
|
assert (num >= 0 && num <= MAX_DC_ID);
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (TLS->DC_list[num]);
|
|
|
|
TLS->DC_list[num]->server_salt = fetch_long ();
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_set_dh_params (struct tgl_state *TLS, void *extra) {
|
|
|
|
if (TLS->encr_prime) { tfree (TLS->encr_prime, 256); }
|
|
|
|
TLS->encr_root = fetch_int ();
|
|
|
|
TLS->encr_prime = talloc (256);
|
|
|
|
fetch_ints (TLS->encr_prime, 64);
|
|
|
|
TLS->encr_param_version = fetch_int ();
|
2014-08-12 14:05:18 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_set_pts (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
int new_pts = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (new_pts >= TLS->pts);
|
|
|
|
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "pts %d=>%d\n", TLS->pts, new_pts);
|
|
|
|
TLS->pts = new_pts;
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_set_qts (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
int new_qts = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (new_qts >= TLS->qts);
|
|
|
|
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "qts %d=>%d\n", TLS->qts, new_qts);
|
|
|
|
TLS->qts = new_qts;
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_set_date (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
int new_date = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
if (new_date < TLS->date) { return 0; }
|
|
|
|
assert (new_date >= TLS->date);
|
|
|
|
TLS->date = new_date;
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_set_seq (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
int new_seq = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
if (new_seq < TLS->seq) {
|
|
|
|
vlogprintf (E_ERROR, "Error: old_seq = %d, new_seq = %d\n", TLS->seq, new_seq);
|
2014-08-26 18:02:19 -04:00
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (new_seq >= TLS->seq);
|
|
|
|
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "seq %d=>%d\n", TLS->seq, new_seq);
|
|
|
|
TLS->seq = new_seq;
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2014-08-12 11:15:04 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_add (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_U = tgl_peer_get (TLS, id);
|
2014-08-12 11:15:04 -04:00
|
|
|
if (!_U) {
|
|
|
|
_U = talloc0 (sizeof (*_U));
|
|
|
|
_U->id = id;
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_insert_user (TLS, _U);
|
2014-08-12 11:15:04 -04:00
|
|
|
} else {
|
|
|
|
assert (!(_U->flags & FLAG_CREATED));
|
|
|
|
}
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_user *U = (void *)_U;
|
2014-08-12 11:15:04 -04:00
|
|
|
U->flags |= FLAG_CREATED;
|
2014-10-24 13:43:08 -04:00
|
|
|
if (tgl_get_peer_id (id) == TLS->our_id) {
|
2014-08-12 11:15:04 -04:00
|
|
|
U->flags |= FLAG_USER_SELF;
|
|
|
|
}
|
|
|
|
U->first_name = fetch_str_dup ();
|
|
|
|
U->last_name = fetch_str_dup ();
|
|
|
|
assert (!U->print_name);
|
2014-10-24 13:43:08 -04:00
|
|
|
U->print_name = TLS->callback.create_print_name (TLS, U->id, U->first_name, U->last_name, 0, 0);
|
2014-08-12 11:15:04 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_peer_insert_name (TLS, (void *)U);
|
2014-08-12 11:15:04 -04:00
|
|
|
U->access_hash = fetch_long ();
|
|
|
|
U->phone = fetch_str_dup ();
|
|
|
|
if (fetch_int ()) {
|
|
|
|
U->flags |= FLAG_USER_CONTACT;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, U, TGL_UPDATE_CREATED);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_delete (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-12 11:15:04 -04:00
|
|
|
assert (U);
|
|
|
|
U->flags |= FLAG_DELETED;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_DELETED);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_access_hash (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
U->user.access_hash = fetch_long ();
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_ACCESS_HASH);
|
2014-08-21 11:38:51 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_phone (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
if (U->user.phone) {
|
|
|
|
tfree_str (U->user.phone);
|
|
|
|
}
|
|
|
|
U->user.phone = fetch_str_dup ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_PHONE);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_friend (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
int friend = fetch_int ();
|
|
|
|
if (friend) { U->flags |= FLAG_USER_CONTACT; }
|
|
|
|
else { U->flags &= ~FLAG_USER_CONTACT; }
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_CONTACT);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_full_photo (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
if (U->flags & FLAG_HAS_PHOTO) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tgls_free_photo (TLS, &U->user.photo);
|
2014-08-11 17:15:22 -04:00
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_photo (TLS, &U->user.photo);
|
2014-09-18 06:11:23 -04:00
|
|
|
U->flags |= FLAG_HAS_PHOTO;
|
2014-08-11 17:15:22 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_PHOTO);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_blocked (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
|
|
|
|
U->user.blocked = fetch_int ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_BLOCKED);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_real_name (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
2014-08-21 11:38:51 -04:00
|
|
|
assert (U->flags & FLAG_CREATED);
|
2014-08-11 17:15:22 -04:00
|
|
|
|
|
|
|
if (U->user.real_first_name) { tfree_str (U->user.real_first_name); }
|
|
|
|
if (U->user.real_last_name) { tfree_str (U->user.real_last_name); }
|
|
|
|
U->user.real_first_name = fetch_str_dup ();
|
|
|
|
U->user.real_last_name = fetch_str_dup ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_REAL_NAME);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_name (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
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) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_peer_delete_name (TLS, U);
|
2014-08-12 17:32:11 -04:00
|
|
|
tfree_str (U->print_name);
|
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
U->print_name = TLS->callback.create_print_name (TLS, U->id, U->user.first_name, U->user.last_name, 0, 0);
|
|
|
|
tglp_peer_insert_name (TLS, (void *)U);
|
2014-08-12 17:32:11 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_NAME);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_username (struct tgl_state *TLS, void *extra) {
|
2014-10-12 11:53:57 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-10-12 11:53:57 -04:00
|
|
|
assert (U);
|
|
|
|
|
|
|
|
if (U->user.username) { tfree_str (U->user.username); }
|
|
|
|
U->user.username = fetch_str_dup ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_USERNAME);
|
2014-10-12 11:53:57 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_user_set_photo (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
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 ();
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_file_location (TLS, &U->user.photo_small);
|
|
|
|
tglf_fetch_file_location (TLS, &U->user.photo_big);
|
2014-08-12 17:32:11 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.user_update) {
|
|
|
|
TLS->callback.user_update (TLS, (void *)U, TGL_UPDATE_PHOTO);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_delete (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (_U);
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_secret_chat *U = &_U->encr_chat;
|
2014-08-11 17:15:22 -04:00
|
|
|
memset (U->key, 0, sizeof (U->key));
|
|
|
|
U->flags |= FLAG_DELETED;
|
|
|
|
U->state = sc_deleted;
|
|
|
|
if (U->nonce) {
|
|
|
|
tfree_secure (U->nonce, 256);
|
|
|
|
U->nonce = 0;
|
|
|
|
}
|
|
|
|
if (U->g_key) {
|
|
|
|
tfree_secure (U->g_key, 256);
|
|
|
|
U->g_key = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.secret_chat_update) {
|
|
|
|
TLS->callback.secret_chat_update (TLS, U, TGL_UPDATE_DELETED);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_requested (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
if (!_U) {
|
|
|
|
_U = talloc0 (sizeof (*_U));
|
|
|
|
_U->id = id;
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_insert_encrypted_chat (TLS, _U);
|
2014-08-11 17:15:22 -04:00
|
|
|
} else {
|
|
|
|
assert (!(_U->flags & FLAG_CREATED));
|
|
|
|
}
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_secret_chat *U = (void *)_U;
|
2014-08-11 17:15:22 -04:00
|
|
|
U->access_hash = fetch_long ();
|
|
|
|
U->date = fetch_int ();
|
|
|
|
U->admin_id = fetch_int ();
|
|
|
|
U->user_id = fetch_int ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *Us = tgl_peer_get (TLS, TGL_MK_USER (U->user_id));
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (!U->print_name);
|
|
|
|
if (Us) {
|
2014-10-24 13:43:08 -04:00
|
|
|
U->print_name = TLS->callback.create_print_name (TLS, id, "!", Us->user.first_name, Us->user.last_name, 0);
|
2014-08-11 17:15:22 -04:00
|
|
|
} else {
|
|
|
|
static char buf[100];
|
|
|
|
tsnprintf (buf, 99, "user#%d", U->user_id);
|
2014-10-24 13:43:08 -04:00
|
|
|
U->print_name = TLS->callback.create_print_name (TLS, id, "!", buf, 0, 0);
|
2014-08-11 17:15:22 -04:00
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_peer_insert_name (TLS, (void *)U);
|
2014-08-11 17:15:22 -04:00
|
|
|
U->g_key = talloc (256);
|
|
|
|
U->nonce = talloc (256);
|
|
|
|
fetch_ints (U->g_key, 64);
|
|
|
|
fetch_ints (U->nonce, 64);
|
|
|
|
|
|
|
|
U->flags |= FLAG_CREATED;
|
|
|
|
U->state = sc_request;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.secret_chat_update) {
|
|
|
|
TLS->callback.secret_chat_update (TLS, U, TGL_UPDATE_REQUESTED);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_set_access_hash (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
U->encr_chat.access_hash = fetch_long ();
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.secret_chat_update) {
|
|
|
|
TLS->callback.secret_chat_update (TLS, (void *)U, TGL_UPDATE_ACCESS_HASH);
|
2014-08-21 11:38:51 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_set_date (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
U->encr_chat.date = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_set_ttl (struct tgl_state *TLS, void *extra) {
|
2014-08-31 10:18:19 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-31 10:18:19 -04:00
|
|
|
assert (U);
|
|
|
|
U->encr_chat.ttl = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_set_layer (struct tgl_state *TLS, void *extra) {
|
2014-08-31 10:18:19 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-31 10:18:19 -04:00
|
|
|
assert (U);
|
|
|
|
U->encr_chat.layer = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_set_state (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (U);
|
|
|
|
U->encr_chat.state = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_accepted (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (_U);
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_secret_chat *U = &_U->encr_chat;
|
2014-08-11 17:15:22 -04:00
|
|
|
if (!U->g_key) {
|
|
|
|
U->g_key = talloc (256);
|
|
|
|
}
|
|
|
|
if (!U->nonce) {
|
|
|
|
U->nonce = talloc (256);
|
|
|
|
}
|
|
|
|
|
2014-08-12 21:22:15 -04:00
|
|
|
fetch_ints (U->g_key, 64);
|
|
|
|
fetch_ints (U->nonce, 64);
|
2014-08-11 17:15:22 -04:00
|
|
|
U->key_fingerprint = fetch_long ();
|
|
|
|
|
|
|
|
if (U->state == sc_waiting) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_do_create_keys_end (TLS, U);
|
2014-08-11 17:15:22 -04:00
|
|
|
}
|
|
|
|
U->state = sc_ok;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.secret_chat_update) {
|
|
|
|
TLS->callback.secret_chat_update (TLS, U, TGL_UPDATE_WORKING);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-11 17:15:22 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_set_key (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_U = tgl_peer_get (TLS, id);
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (_U);
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_secret_chat *U = &_U->encr_chat;
|
2014-08-11 17:15:22 -04:00
|
|
|
fetch_ints (U->key, 64);
|
|
|
|
U->key_fingerprint = fetch_long ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_update_seq (struct tgl_state *TLS, void *extra) {
|
2014-10-14 16:20:03 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_U = tgl_peer_get (TLS, id);
|
2014-10-14 16:20:03 -04:00
|
|
|
assert (_U);
|
|
|
|
_U->encr_chat.in_seq_no = fetch_int ();
|
|
|
|
_U->encr_chat.last_in_seq_no = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_set_seq (struct tgl_state *TLS, void *extra) {
|
2014-10-23 12:39:58 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_U = tgl_peer_get (TLS, id);
|
2014-10-23 12:39:58 -04:00
|
|
|
assert (_U);
|
|
|
|
_U->encr_chat.in_seq_no = fetch_int ();
|
|
|
|
_U->encr_chat.last_in_seq_no = fetch_int ();
|
|
|
|
_U->encr_chat.out_seq_no = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_init (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_t *P = talloc0 (sizeof (*P));
|
|
|
|
P->id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (!tgl_peer_get (TLS, P->id));
|
2014-08-11 17:15:22 -04:00
|
|
|
P->encr_chat.user_id = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
P->encr_chat.admin_id = TLS->our_id;
|
|
|
|
tglp_insert_encrypted_chat (TLS, P);
|
|
|
|
tgl_peer_t *Us = tgl_peer_get (TLS, TGL_MK_USER (P->encr_chat.user_id));
|
2014-08-11 17:15:22 -04:00
|
|
|
assert (Us);
|
2014-10-24 13:43:08 -04:00
|
|
|
P->print_name = TLS->callback.create_print_name (TLS, P->id, "!", Us->user.first_name, Us->user.last_name, 0);
|
|
|
|
tglp_peer_insert_name (TLS, P);
|
2014-08-11 17:15:22 -04:00
|
|
|
|
2014-08-12 21:22:15 -04:00
|
|
|
P->encr_chat.g_key = talloc (256);
|
2014-08-11 17:15:22 -04:00
|
|
|
fetch_ints (P->encr_chat.key, 64);
|
|
|
|
fetch_ints (P->encr_chat.g_key, 64);
|
|
|
|
P->flags |= FLAG_CREATED;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.secret_chat_update) {
|
|
|
|
TLS->callback.secret_chat_update (TLS, (void *)P, TGL_UPDATE_CREATED);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 11:15:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_encr_chat_create (struct tgl_state *TLS, void *extra) {
|
2014-08-31 10:18:19 -04:00
|
|
|
tgl_peer_t *P = talloc0 (sizeof (*P));
|
|
|
|
P->id = TGL_MK_ENCR_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (!tgl_peer_get (TLS, P->id));
|
2014-08-31 10:18:19 -04:00
|
|
|
P->encr_chat.user_id = fetch_int ();
|
|
|
|
P->encr_chat.admin_id = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_insert_encrypted_chat (TLS, P);
|
2014-08-31 10:18:19 -04:00
|
|
|
P->print_name = fetch_str_dup ();
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_peer_insert_name (TLS, P);
|
2014-08-31 10:18:19 -04:00
|
|
|
|
|
|
|
P->flags |= FLAG_CREATED;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.secret_chat_update) {
|
|
|
|
TLS->callback.secret_chat_update (TLS, (void *)P, TGL_UPDATE_CREATED);
|
2014-08-31 10:18:19 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_create (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_C = tgl_peer_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
if (!_C) {
|
|
|
|
_C = talloc0 (sizeof (*_C));
|
|
|
|
_C->id = id;
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_insert_chat (TLS, _C);
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
|
|
|
assert (!(_C->flags & FLAG_CREATED));
|
|
|
|
}
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_chat *C = &_C->chat;
|
2014-08-12 14:05:18 -04:00
|
|
|
C->flags = FLAG_CREATED | fetch_int ();
|
|
|
|
C->title = fetch_str_dup ();
|
|
|
|
assert (!C->print_title);
|
2014-10-24 13:43:08 -04:00
|
|
|
C->print_title = TLS->callback.create_print_name (TLS, id, C->title, 0, 0, 0);
|
|
|
|
tglp_peer_insert_name (TLS, (void *)C);
|
2014-08-12 14:05:18 -04:00
|
|
|
C->users_num = fetch_int ();
|
|
|
|
C->date = fetch_int ();
|
|
|
|
C->version = fetch_int ();
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
fetch_data (&C->photo_big, sizeof (struct tgl_file_location));
|
|
|
|
fetch_data (&C->photo_small, sizeof (struct tgl_file_location));
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, C, TGL_UPDATE_CREATED);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_change_flags (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
|
|
|
C->chat.flags |= fetch_int ();
|
|
|
|
C->chat.flags &= ~fetch_int ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, (void *)C, TGL_UPDATE_FLAGS);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_set_title (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
|
|
|
|
|
|
|
if (C->chat.title) { tfree_str (C->chat.title); }
|
|
|
|
C->chat.title = fetch_str_dup ();
|
|
|
|
if (C->print_name) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tglp_peer_delete_name (TLS, (void *)C);
|
2014-08-12 14:05:18 -04:00
|
|
|
tfree_str (C->print_name);
|
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
C->print_name = TLS->callback.create_print_name (TLS, C->id, C->chat.title, 0, 0, 0);
|
|
|
|
tglp_peer_insert_name (TLS, (void *)C);
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, (void *)C, TGL_UPDATE_TITLE);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_set_photo (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
2014-08-13 11:55:16 -04:00
|
|
|
fetch_data (&C->photo_big, sizeof (struct tgl_file_location));
|
|
|
|
fetch_data (&C->photo_small, sizeof (struct tgl_file_location));
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, (void *)C, TGL_UPDATE_PHOTO);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_set_date (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
|
|
|
C->chat.date = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_set_version (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
|
|
|
C->chat.version = fetch_int ();
|
|
|
|
C->chat.users_num = fetch_int ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_set_admin (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
|
|
|
C->chat.admin_id = fetch_int ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, (void *)C, TGL_UPDATE_ADMIN);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_set_participants (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
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); }
|
|
|
|
C->chat.user_list_size = fetch_int ();
|
|
|
|
C->chat.user_list = talloc (12 * C->chat.user_list_size);
|
|
|
|
fetch_ints (C->chat.user_list, 3 * C->chat.user_list_size);
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, (void *)C, TGL_UPDATE_MEMBERS);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_set_full_photo (struct tgl_state *TLS, void *extra) {
|
|
|
|
tgl_peer_t *C = tgl_peer_get (TLS, TGL_MK_CHAT (fetch_int ()));
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
|
|
|
|
|
|
|
assert (C && (C->flags & FLAG_CREATED));
|
|
|
|
if (C->flags & FLAG_HAS_PHOTO) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tgls_free_photo (TLS, &C->chat.photo);
|
2014-08-12 14:05:18 -04:00
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_photo (TLS, &C->chat.photo);
|
2014-09-18 06:11:23 -04:00
|
|
|
C->flags |= FLAG_HAS_PHOTO;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, (void *)C, TGL_UPDATE_PHOTO);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_add_participant (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_C = tgl_peer_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (_C && (_C->flags & FLAG_CREATED));
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_chat *C = &_C->chat;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
|
|
|
int version = fetch_int ();
|
|
|
|
int user = fetch_int ();
|
|
|
|
int inviter = fetch_int ();
|
|
|
|
int date = fetch_int ();
|
|
|
|
assert (C->user_list_version < version);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < C->user_list_size; i++) {
|
|
|
|
assert (C->user_list[i].user_id != user);
|
|
|
|
}
|
|
|
|
|
|
|
|
C->user_list_size ++;
|
|
|
|
C->user_list = trealloc (C->user_list, 12 * C->user_list_size - 12, 12 * C->user_list_size);
|
|
|
|
C->user_list[C->user_list_size - 1].user_id = user;
|
|
|
|
C->user_list[C->user_list_size - 1].inviter_id = inviter;
|
|
|
|
C->user_list[C->user_list_size - 1].date = date;
|
|
|
|
C->user_list_version = version;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, C, TGL_UPDATE_MEMBERS);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_chat_del_participant (struct tgl_state *TLS, void *extra) {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id = TGL_MK_CHAT (fetch_int ());
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *_C = tgl_peer_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
assert (_C && (_C->flags & FLAG_CREATED));
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_chat *C = &_C->chat;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
|
|
|
int version = fetch_int ();
|
|
|
|
int user = fetch_int ();
|
|
|
|
assert (C->user_list_version < version);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < C->user_list_size; i++) {
|
|
|
|
if (C->user_list[i].user_id == user) {
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_chat_user t;
|
2014-08-12 14:05:18 -04:00
|
|
|
t = C->user_list[i];
|
|
|
|
C->user_list[i] = C->user_list[C->user_list_size - 1];
|
|
|
|
C->user_list[C->user_list_size - 1] = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert (C->user_list[C->user_list_size - 1].user_id == user);
|
|
|
|
C->user_list_size --;
|
|
|
|
C->user_list = trealloc (C->user_list, 12 * C->user_list_size + 12, 12 * C->user_list_size);
|
|
|
|
C->user_list_version = version;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.chat_update) {
|
|
|
|
TLS->callback.chat_update (TLS, C, TGL_UPDATE_MEMBERS);
|
2014-08-18 12:39:04 -04:00
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_text (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
long long id = fetch_int ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
|
|
|
|
M->flags |= FLAG_CREATED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
if (t == TGL_PEER_ENCR_CHAT) {
|
2014-08-12 14:05:18 -04:00
|
|
|
M->flags |= FLAG_ENCRYPTED;
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
M->date = fetch_int ();
|
2014-08-21 16:35:27 -04:00
|
|
|
M->unread = fetch_int ();
|
2014-08-12 14:05:18 -04:00
|
|
|
|
|
|
|
int l = prefetch_strlen ();
|
|
|
|
M->message = talloc (l + 1);
|
|
|
|
memcpy (M->message, fetch_str (l), l);
|
|
|
|
M->message[l] = 0;
|
|
|
|
M->message_len = l;
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
if (t == TGL_PEER_ENCR_CHAT) {
|
2014-08-18 12:39:04 -04:00
|
|
|
M->media.type = tgl_message_media_none;
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
2014-08-18 12:39:04 -04:00
|
|
|
M->media.type = tgl_message_media_none;
|
2014-08-12 14:05:18 -04:00
|
|
|
}
|
|
|
|
|
2014-08-21 16:35:27 -04:00
|
|
|
//M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_send_message_text (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
long long id = fetch_long ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
|
|
|
|
M->flags |= FLAG_CREATED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
if (t == TGL_PEER_ENCR_CHAT) {
|
2014-08-12 14:05:18 -04:00
|
|
|
M->flags |= FLAG_ENCRYPTED;
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-09-29 08:11:48 -04:00
|
|
|
if (t == TGL_PEER_ENCR_CHAT) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *P = tgl_peer_get (TLS, M->to_id);
|
2014-10-14 16:20:03 -04:00
|
|
|
if (P && P->encr_chat.layer >= 17) {
|
2014-09-29 08:11:48 -04:00
|
|
|
P->encr_chat.out_seq_no ++;
|
|
|
|
}
|
|
|
|
}
|
2014-08-12 14:05:18 -04:00
|
|
|
M->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;
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
if (t == TGL_PEER_ENCR_CHAT) {
|
2014-08-18 12:39:04 -04:00
|
|
|
M->media.type = tgl_message_media_none;
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
2014-08-18 12:39:04 -04:00
|
|
|
M->media.type = tgl_message_media_none;
|
2014-08-12 14:05:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
|
|
|
tglm_message_insert_unsent (TLS, M);
|
2014-08-12 14:05:18 -04:00
|
|
|
M->flags |= FLAG_PENDING;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_send_message_action_encr (struct tgl_state *TLS, void *extra) {
|
2014-08-12 21:22:15 -04:00
|
|
|
long long id = fetch_long ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 21:22:15 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 21:22:15 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
|
|
|
|
M->flags |= FLAG_CREATED | FLAG_ENCRYPTED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 21:22:15 -04:00
|
|
|
|
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 21:22:15 -04:00
|
|
|
M->date = fetch_int ();
|
|
|
|
|
2014-08-18 12:39:04 -04:00
|
|
|
M->media.type = tgl_message_media_none;
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_action_encrypted (TLS, &M->action);
|
2014-09-29 08:11:48 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *P = tgl_peer_get (TLS, M->to_id);
|
2014-09-29 08:11:48 -04:00
|
|
|
if (P) {
|
2014-10-14 16:20:03 -04:00
|
|
|
if (P->encr_chat.layer >= 17) {
|
|
|
|
P->encr_chat.out_seq_no ++;
|
|
|
|
}
|
2014-09-29 08:11:48 -04:00
|
|
|
}
|
2014-08-12 21:22:15 -04:00
|
|
|
|
|
|
|
M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 21:22:15 -04:00
|
|
|
M->service = 1;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
|
|
|
tglm_message_insert_unsent (TLS, M);
|
2014-08-12 21:22:15 -04:00
|
|
|
M->flags |= FLAG_PENDING;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_text_fwd (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
long long id = fetch_int ();
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
|
|
|
|
M->flags |= FLAG_CREATED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
if (t == TGL_PEER_ENCR_CHAT) {
|
2014-08-12 14:05:18 -04:00
|
|
|
M->flags |= FLAG_ENCRYPTED;
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
M->date = fetch_int ();
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
M->fwd_from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
M->fwd_date = fetch_int ();
|
2014-08-21 16:35:27 -04:00
|
|
|
|
|
|
|
M->unread = fetch_int ();
|
2014-08-12 14:05:18 -04:00
|
|
|
|
|
|
|
int l = prefetch_strlen ();
|
|
|
|
M->message = talloc (l + 1);
|
|
|
|
memcpy (M->message, fetch_str (l), l);
|
|
|
|
M->message[l] = 0;
|
|
|
|
M->message_len = l;
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
if (t == TGL_PEER_ENCR_CHAT) {
|
2014-08-18 12:39:04 -04:00
|
|
|
M->media.type = tgl_message_media_none;
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
2014-08-18 12:39:04 -04:00
|
|
|
M->media.type = tgl_message_media_none;
|
2014-08-12 14:05:18 -04:00
|
|
|
}
|
|
|
|
|
2014-08-21 16:35:27 -04:00
|
|
|
//M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-12 14:05:18 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_media (struct tgl_state *TLS, void *extra) {
|
2014-08-12 14:05:18 -04:00
|
|
|
int id = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
M->flags |= FLAG_CREATED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
M->date = fetch_int ();
|
2014-08-21 16:35:27 -04:00
|
|
|
|
|
|
|
M->unread = fetch_int ();
|
2014-08-12 14:05:18 -04:00
|
|
|
|
|
|
|
int l = prefetch_strlen ();
|
|
|
|
M->message = talloc (l + 1);
|
|
|
|
memcpy (M->message, fetch_str (l), l);
|
|
|
|
M->message[l] = 0;
|
|
|
|
M->message_len = l;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_media (TLS, &M->media);
|
2014-08-21 16:35:27 -04:00
|
|
|
//M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_media_encr (struct tgl_state *TLS, void *extra) {
|
2014-08-12 21:22:15 -04:00
|
|
|
long long id = fetch_long ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 14:05:18 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
M->flags |= FLAG_CREATED | FLAG_ENCRYPTED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 14:05:18 -04:00
|
|
|
M->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;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_media_encrypted (TLS, &M->media);
|
|
|
|
tglf_fetch_encrypted_message_file (TLS, &M->media);
|
2014-08-12 14:05:18 -04:00
|
|
|
M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-12 14:05:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_media_encr_pending (struct tgl_state *TLS, void *extra) {
|
2014-09-11 16:57:59 -04:00
|
|
|
long long id = fetch_long ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-09-11 16:57:59 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-09-11 16:57:59 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
M->flags |= FLAG_CREATED | FLAG_ENCRYPTED;
|
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
|
|
|
int t = fetch_int ();
|
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
|
|
|
M->date = fetch_int ();
|
2014-09-29 08:11:48 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tgl_peer_t *P = tgl_peer_get (TLS, M->to_id);
|
2014-09-29 08:11:48 -04:00
|
|
|
if (P) {
|
2014-10-14 16:20:03 -04:00
|
|
|
if (P->encr_chat.layer >= 17) {
|
|
|
|
P->encr_chat.out_seq_no ++;
|
|
|
|
}
|
2014-09-29 08:11:48 -04:00
|
|
|
}
|
2014-09-11 16:57:59 -04:00
|
|
|
|
|
|
|
int l = prefetch_strlen ();
|
|
|
|
M->message = talloc (l + 1);
|
|
|
|
memcpy (M->message, fetch_str (l), l);
|
|
|
|
M->message[l] = 0;
|
|
|
|
M->message_len = l;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_media_encrypted (TLS, &M->media);
|
2014-09-11 16:57:59 -04:00
|
|
|
M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-09-11 16:57:59 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
|
|
|
tglm_message_insert_unsent (TLS, M);
|
2014-09-11 16:57:59 -04:00
|
|
|
M->flags |= FLAG_PENDING;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_media_encr_sent (struct tgl_state *TLS, void *extra) {
|
2014-09-11 16:57:59 -04:00
|
|
|
long long id = fetch_long ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-09-11 16:57:59 -04:00
|
|
|
assert (M && (M->flags & FLAG_CREATED));
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_encrypted_message_file (TLS, &M->media);
|
|
|
|
tglm_message_remove_unsent (TLS, M);
|
2014-09-11 16:57:59 -04:00
|
|
|
M->flags &= ~FLAG_PENDING;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_media_fwd (struct tgl_state *TLS, void *extra) {
|
2014-08-12 17:32:11 -04:00
|
|
|
int id = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
M->flags |= FLAG_CREATED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
M->date = fetch_int ();
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
M->fwd_from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
M->fwd_date = fetch_int ();
|
2014-08-21 16:35:27 -04:00
|
|
|
|
|
|
|
M->unread = fetch_int ();
|
2014-08-12 17:32:11 -04:00
|
|
|
|
|
|
|
int l = prefetch_strlen ();
|
|
|
|
M->message = talloc (l + 1);
|
|
|
|
memcpy (M->message, fetch_str (l), l);
|
|
|
|
M->message[l] = 0;
|
|
|
|
M->message_len = l;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_media (TLS, &M->media);
|
2014-08-21 16:35:27 -04:00
|
|
|
//M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 17:32:11 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_service (struct tgl_state *TLS, void *extra) {
|
2014-08-12 17:32:11 -04:00
|
|
|
int id = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
M->flags |= FLAG_CREATED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
M->date = fetch_int ();
|
2014-08-21 16:35:27 -04:00
|
|
|
|
|
|
|
M->unread = fetch_int ();
|
2014-08-12 17:32:11 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_action (TLS, &M->action);
|
2014-08-21 16:35:27 -04:00
|
|
|
//M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 17:32:11 -04:00
|
|
|
M->service = 1;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_service_encr (struct tgl_state *TLS, void *extra) {
|
2014-08-12 21:22:15 -04:00
|
|
|
long long id = fetch_long ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
M->flags |= FLAG_CREATED | FLAG_ENCRYPTED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
assert (t == TGL_PEER_ENCR_CHAT);
|
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
M->date = fetch_int ();
|
2014-08-12 21:22:15 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_secret_chat *E = (void *)tgl_peer_get (TLS, M->to_id);
|
2014-08-12 21:22:15 -04:00
|
|
|
assert (E);
|
2014-08-12 17:32:11 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_action_encrypted (TLS, &M->action);
|
2014-08-12 17:32:11 -04:00
|
|
|
M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 17:32:11 -04:00
|
|
|
M->service = 1;
|
|
|
|
|
2014-08-22 08:30:28 -04:00
|
|
|
if (!M->out && M->action.type == tgl_message_action_notify_layer) {
|
2014-08-13 08:56:55 -04:00
|
|
|
E->layer = M->action.layer;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_create_message_service_fwd (struct tgl_state *TLS, void *extra) {
|
2014-08-12 17:32:11 -04:00
|
|
|
int id = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
struct tgl_message *M = tgl_message_get (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
if (!M) {
|
2014-10-24 13:43:08 -04:00
|
|
|
M = tglm_message_alloc (TLS, id);
|
2014-08-12 17:32:11 -04:00
|
|
|
} else {
|
|
|
|
assert (!(M->flags & FLAG_CREATED));
|
|
|
|
}
|
|
|
|
M->flags |= FLAG_CREATED;
|
2014-08-13 11:55:16 -04:00
|
|
|
M->from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
int t = fetch_int ();
|
2014-08-13 11:55:16 -04:00
|
|
|
M->to_id = tgl_set_peer_id (t, fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
M->date = fetch_int ();
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
M->fwd_from_id = TGL_MK_USER (fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
M->fwd_date = fetch_int ();
|
2014-08-21 16:35:27 -04:00
|
|
|
|
|
|
|
M->unread = fetch_int ();
|
2014-08-12 17:32:11 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglf_fetch_message_action (TLS, &M->action);
|
2014-08-21 16:35:27 -04:00
|
|
|
//M->unread = 1;
|
2014-10-24 13:43:08 -04:00
|
|
|
M->out = tgl_get_peer_id (M->from_id) == TLS->our_id;
|
2014-08-12 17:32:11 -04:00
|
|
|
M->service = 1;
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert (TLS, M);
|
2014-08-21 11:38:51 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_message_set_unread_long (struct tgl_state *TLS, void *extra) {
|
|
|
|
struct tgl_message *M = tgl_message_get (TLS, fetch_long ());
|
2014-08-21 11:38:51 -04:00
|
|
|
assert (M);
|
|
|
|
if (M->unread) {
|
|
|
|
M->unread = 0;
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.marked_read) {
|
|
|
|
TLS->callback.marked_read (TLS, 1, &M);
|
2014-08-21 11:38:51 -04:00
|
|
|
}
|
|
|
|
}
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_message_set_unread (struct tgl_state *TLS, void *extra) {
|
|
|
|
struct tgl_message *M = tgl_message_get (TLS, fetch_int ());
|
2014-08-12 17:32:11 -04:00
|
|
|
assert (M);
|
2014-08-21 11:38:51 -04:00
|
|
|
if (M->unread) {
|
|
|
|
M->unread = 0;
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.marked_read) {
|
|
|
|
TLS->callback.marked_read (TLS, 1, &M);
|
2014-08-21 11:38:51 -04:00
|
|
|
}
|
|
|
|
}
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_set_message_sent (struct tgl_state *TLS, void *extra) {
|
|
|
|
struct tgl_message *M = tgl_message_get (TLS, fetch_long ());
|
2014-08-12 17:32:11 -04:00
|
|
|
assert (M);
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_remove_unsent (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
M->flags &= ~FLAG_PENDING;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_set_msg_id (struct tgl_state *TLS, void *extra) {
|
|
|
|
struct tgl_message *M = tgl_message_get (TLS, fetch_long ());
|
2014-08-12 17:32:11 -04:00
|
|
|
assert (M);
|
|
|
|
if (M->flags & FLAG_PENDING) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_remove_unsent (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
M->flags &= ~FLAG_PENDING;
|
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_remove_tree (TLS, M);
|
|
|
|
tglm_message_del_peer (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
M->id = fetch_int ();
|
2014-10-24 13:43:08 -04:00
|
|
|
if (tgl_message_get (TLS, M->id)) {
|
|
|
|
tgls_free_message (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
} else {
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_insert_tree (TLS, M);
|
|
|
|
tglm_message_add_peer (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_delete_msg (struct tgl_state *TLS, void *extra) {
|
|
|
|
struct tgl_message *M = tgl_message_get (TLS, fetch_long ());
|
2014-08-12 17:32:11 -04:00
|
|
|
assert (M);
|
|
|
|
if (M->flags & FLAG_PENDING) {
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_remove_unsent (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
M->flags &= ~FLAG_PENDING;
|
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
tglm_message_remove_tree (TLS, M);
|
|
|
|
tglm_message_del_peer (TLS, M);
|
|
|
|
tglm_message_del_use (TLS, M);
|
|
|
|
tgls_free_message (TLS, M);
|
2014-08-12 17:32:11 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-20 12:36:45 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_msg_seq_update (struct tgl_state *TLS, void *extra) {
|
|
|
|
struct tgl_message *M = tgl_message_get (TLS, fetch_long ());
|
2014-08-20 12:36:45 -04:00
|
|
|
assert (M);
|
2014-10-24 13:43:08 -04:00
|
|
|
TLS->seq ++;
|
|
|
|
vlogprintf (E_DEBUG - 1 + 2 * in_replay_log, "seq %d=>%d\n", TLS->seq - 1, TLS->seq);
|
2014-08-20 12:36:45 -04:00
|
|
|
|
2014-09-03 09:05:48 -04:00
|
|
|
if (!(M->flags & FLAG_ENCRYPTED)) {
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->max_msg_id < M->id) {
|
|
|
|
TLS->max_msg_id = M->id;
|
2014-09-03 09:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.msg_receive) {
|
|
|
|
TLS->callback.msg_receive (TLS, M);
|
2014-08-20 12:36:45 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_msg_update (struct tgl_state *TLS, void *extra) {
|
|
|
|
struct tgl_message *M = tgl_message_get (TLS, fetch_long ());
|
2014-10-14 16:20:03 -04:00
|
|
|
if (!M) { return 0; }
|
2014-08-20 12:36:45 -04:00
|
|
|
assert (M);
|
2014-09-03 09:05:48 -04:00
|
|
|
|
|
|
|
if (!(M->flags & FLAG_ENCRYPTED)) {
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->max_msg_id < M->id) {
|
|
|
|
TLS->max_msg_id = M->id;
|
2014-09-03 09:05:48 -04:00
|
|
|
}
|
|
|
|
}
|
2014-08-20 12:36:45 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->callback.msg_receive) {
|
|
|
|
TLS->callback.msg_receive (TLS, M);
|
2014-08-20 12:36:45 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static int fetch_comb_binlog_reset_authorization (struct tgl_state *TLS, void *extra) {
|
2014-09-18 09:57:23 -04:00
|
|
|
int i;
|
2014-10-24 13:43:08 -04:00
|
|
|
for (i = 0; i <= TLS->max_dc_num; i++) if (TLS->DC_list[i]) {
|
|
|
|
struct tgl_dc *D = TLS->DC_list[i];
|
2014-09-18 09:57:23 -04:00
|
|
|
D->flags = 0;
|
|
|
|
D->state = st_init;
|
|
|
|
D->auth_key_id = D->temp_auth_key_id = 0;
|
|
|
|
D->has_auth = 0;
|
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
TLS->seq = 0;
|
|
|
|
TLS->qts = 0;
|
2014-09-18 09:57:23 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-12 17:32:11 -04:00
|
|
|
#define FETCH_COMBINATOR_FUNCTION(NAME) \
|
|
|
|
case CODE_ ## NAME:\
|
2014-10-24 13:43:08 -04:00
|
|
|
ok = fetch_comb_ ## NAME (TLS, 0); \
|
2014-08-12 17:32:11 -04:00
|
|
|
break; \
|
|
|
|
|
2014-08-12 14:05:18 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static void replay_log_event (struct tgl_state *TLS) {
|
2013-11-12 19:11:25 -05:00
|
|
|
assert (rptr < wptr);
|
|
|
|
int op = *rptr;
|
|
|
|
|
2014-08-13 21:31:24 -04:00
|
|
|
vlogprintf (E_DEBUG, "replay_log_event: log_pos=%lld, op=0x%08x\n", binlog_pos, op);
|
2013-11-29 16:43:56 -05:00
|
|
|
|
|
|
|
in_ptr = rptr;
|
|
|
|
in_end = wptr;
|
2014-08-12 17:32:11 -04:00
|
|
|
assert (skip_type_any (TYPE_TO_PARAM(binlog_update)) >= 0);
|
|
|
|
in_end = in_ptr;
|
|
|
|
in_ptr = rptr;
|
2013-11-29 16:43:56 -05:00
|
|
|
|
2014-08-12 17:32:11 -04:00
|
|
|
int ok = -1;
|
|
|
|
in_ptr ++;
|
2013-11-14 19:08:24 -05:00
|
|
|
|
2014-08-12 17:32:11 -04:00
|
|
|
switch (op) {
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_start)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_dc_option)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_auth_key)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_default_dc)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_our_id)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_dc_signed)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_dc_salt)
|
|
|
|
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_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_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)
|
2014-10-12 11:53:57 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_user_set_username)
|
2014-08-12 17:32:11 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_user_set_photo)
|
|
|
|
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_user_set_real_name)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_delete)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_requested)
|
2014-08-12 17:51:16 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_set_access_hash)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_set_date)
|
2014-08-31 10:18:19 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_set_ttl)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_set_layer)
|
2014-08-12 17:51:16 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_set_state)
|
2014-08-12 17:32:11 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_accepted)
|
2014-08-12 17:51:16 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_set_key)
|
2014-10-14 16:20:03 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_update_seq)
|
2014-10-23 12:39:58 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_set_seq)
|
2014-08-12 17:32:11 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_init)
|
2014-08-31 10:18:19 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_encr_chat_create)
|
2014-08-12 17:32:11 -04:00
|
|
|
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_create)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_change_flags)
|
2014-08-12 17:51:16 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_set_title)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_set_photo)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_set_date)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_set_version)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_set_admin)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_set_participants)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_set_full_photo)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_add_participant)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_chat_del_participant)
|
2014-08-12 17:32:11 -04:00
|
|
|
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_create_message_text)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_send_message_text)
|
2014-08-12 21:22:15 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_send_message_action_encr)
|
2014-08-12 17:32:11 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_create_message_text_fwd)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_create_message_media)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_create_message_media_encr)
|
2014-09-11 16:57:59 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_create_message_media_encr_pending)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_create_message_media_encr_sent)
|
2014-08-12 17:32:11 -04:00
|
|
|
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)
|
2014-08-21 11:38:51 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_message_set_unread_long)
|
2014-08-12 17:32:11 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_set_message_sent)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_set_msg_id)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_delete_msg)
|
2014-08-20 12:36:45 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_msg_seq_update)
|
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_msg_update)
|
2014-09-18 09:57:23 -04:00
|
|
|
FETCH_COMBINATOR_FUNCTION (binlog_reset_authorization)
|
2014-08-12 17:32:11 -04:00
|
|
|
default:
|
2014-08-13 21:31:24 -04:00
|
|
|
vlogprintf (E_ERROR, "Unknown op 0x%08x\n", op);
|
2013-11-14 19:08:24 -05:00
|
|
|
assert (0);
|
2013-11-12 19:11:25 -05:00
|
|
|
}
|
2014-08-12 17:32:11 -04:00
|
|
|
assert (ok >= 0);
|
|
|
|
|
|
|
|
assert (in_ptr == in_end);
|
|
|
|
binlog_pos += (in_ptr - rptr) * 4;
|
|
|
|
rptr = in_ptr;
|
2013-11-12 19:11:25 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static void create_new_binlog (struct tgl_state *TLS) {
|
2014-10-17 06:08:03 -04:00
|
|
|
clear_packet ();
|
|
|
|
//static int s[1000];
|
|
|
|
|
|
|
|
//packet_ptr = s;
|
2014-08-12 17:32:11 -04:00
|
|
|
out_int (CODE_binlog_start);
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->test_mode) {
|
2014-09-27 13:58:28 -04:00
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (1);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_TEST_1);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (2);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_TEST_2);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (3);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_TEST_3);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_default_dc);
|
|
|
|
out_int (2);
|
|
|
|
} else {
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (1);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_1);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (2);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_2);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (3);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_3);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (4);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_4);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (5);
|
|
|
|
out_string ("");
|
|
|
|
out_string (TG_SERVER_5);
|
|
|
|
out_int (443);
|
|
|
|
out_int (CODE_binlog_default_dc);
|
|
|
|
out_int (2);
|
|
|
|
}
|
2013-11-12 19:11:25 -05:00
|
|
|
|
2013-11-14 19:08:24 -05:00
|
|
|
int fd = open (get_binlog_file_name (), O_WRONLY | O_EXCL | O_CREAT, 0600);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror ("Write new binlog");
|
|
|
|
exit (2);
|
|
|
|
}
|
2014-10-17 06:08:03 -04:00
|
|
|
assert (write (fd, packet_buffer, (packet_ptr - packet_buffer) * 4) == (packet_ptr - packet_buffer) * 4);
|
2013-11-12 19:11:25 -05:00
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void tgl_replay_log (struct tgl_state *TLS) {
|
|
|
|
if (!TLS->binlog_enabled) { return; }
|
2013-11-12 19:11:25 -05:00
|
|
|
if (access (get_binlog_file_name (), F_OK) < 0) {
|
2013-11-14 19:08:24 -05:00
|
|
|
printf ("No binlog found. Creating new one\n");
|
2014-10-24 13:43:08 -04:00
|
|
|
create_new_binlog (TLS);
|
2013-11-12 19:11:25 -05:00
|
|
|
}
|
|
|
|
int fd = open (get_binlog_file_name (), O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror ("binlog open");
|
|
|
|
exit (2);
|
|
|
|
}
|
2013-11-14 19:08:24 -05:00
|
|
|
int end = 0;
|
2014-08-27 11:12:45 -04:00
|
|
|
in_replay_log = 1;
|
2013-11-12 19:11:25 -05:00
|
|
|
while (1) {
|
|
|
|
if (!end && wptr - rptr < MAX_LOG_EVENT_SIZE / 4) {
|
|
|
|
if (wptr == rptr) {
|
|
|
|
wptr = rptr = binlog_buffer;
|
|
|
|
} else {
|
|
|
|
int x = wptr - rptr;
|
|
|
|
memcpy (binlog_buffer, rptr, 4 * x);
|
2013-11-29 18:15:10 -05:00
|
|
|
wptr -= (rptr - binlog_buffer);
|
|
|
|
rptr = binlog_buffer;
|
2013-11-12 19:11:25 -05:00
|
|
|
}
|
|
|
|
int l = (binlog_buffer + BINLOG_BUFFER_SIZE - wptr) * 4;
|
|
|
|
int k = read (fd, wptr, l);
|
|
|
|
if (k < 0) {
|
|
|
|
perror ("read binlog");
|
|
|
|
exit (2);
|
|
|
|
}
|
|
|
|
assert (!(k & 3));
|
|
|
|
if (k < l) {
|
|
|
|
end = 1;
|
|
|
|
}
|
|
|
|
wptr += (k / 4);
|
|
|
|
}
|
|
|
|
if (wptr == rptr) { break; }
|
2014-10-24 13:43:08 -04:00
|
|
|
replay_log_event (TLS);
|
2013-11-12 19:11:25 -05:00
|
|
|
}
|
2014-08-27 11:12:45 -04:00
|
|
|
in_replay_log = 0;
|
2013-11-12 19:11:25 -05:00
|
|
|
close (fd);
|
2013-11-14 19:08:24 -05:00
|
|
|
}
|
|
|
|
|
2014-09-11 16:57:59 -04:00
|
|
|
static int b_packet_buffer[PACKET_BUFFER_SIZE];
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void tgl_reopen_binlog_for_writing (struct tgl_state *TLS) {
|
|
|
|
TLS->binlog_fd = open (get_binlog_file_name (), O_WRONLY);
|
|
|
|
if (TLS->binlog_fd < 0) {
|
2013-11-14 19:08:24 -05:00
|
|
|
perror ("binlog open");
|
|
|
|
exit (2);
|
|
|
|
}
|
2013-11-29 18:15:10 -05:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
assert (lseek (TLS->binlog_fd, binlog_pos, SEEK_SET) == binlog_pos);
|
|
|
|
if (flock (TLS->binlog_fd, LOCK_EX | LOCK_NB) < 0) {
|
2013-11-29 18:15:10 -05:00
|
|
|
perror ("get lock");
|
|
|
|
exit (2);
|
|
|
|
}
|
2013-11-14 19:08:24 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
static void add_log_event (struct tgl_state *TLS, const int *data, int len) {
|
2014-08-13 21:31:24 -04:00
|
|
|
vlogprintf (E_DEBUG, "Add log event: magic = 0x%08x, len = %d\n", data[0], len);
|
2013-11-21 14:35:49 -05:00
|
|
|
assert (!(len & 3));
|
|
|
|
rptr = (void *)data;
|
|
|
|
wptr = rptr + (len / 4);
|
|
|
|
int *in = in_ptr;
|
|
|
|
int *end = in_end;
|
2014-10-24 13:43:08 -04:00
|
|
|
replay_log_event (TLS);
|
2013-11-21 14:35:49 -05:00
|
|
|
if (rptr != wptr) {
|
2014-08-13 21:31:24 -04:00
|
|
|
vlogprintf (E_ERROR, "Unread %lld ints. Len = %d\n", (long long)(wptr - rptr), len);
|
2013-11-21 14:35:49 -05:00
|
|
|
assert (rptr == wptr);
|
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
if (TLS->binlog_enabled) {
|
|
|
|
assert (TLS->binlog_fd > 0);
|
|
|
|
assert (write (TLS->binlog_fd, data, len) == len);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
in_ptr = in;
|
|
|
|
in_end = end;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_auth_key_id (struct tgl_state *TLS, int num, unsigned char *buf) {
|
2013-11-21 14:35:49 -05:00
|
|
|
static unsigned char sha1_buffer[20];
|
|
|
|
SHA1 (buf, 256, sha1_buffer);
|
|
|
|
long long fingerprint = *(long long *)(sha1_buffer + 12);
|
|
|
|
int *ev = alloc_log_event (8 + 8 + 256);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_auth_key;
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[1] = num;
|
|
|
|
*(long long *)(ev + 2) = fingerprint;
|
|
|
|
memcpy (ev + 4, buf, 256);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8 + 8 + 256);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_our_id (struct tgl_state *TLS, int id) {
|
|
|
|
if (TLS->our_id) {
|
|
|
|
assert (TLS->our_id == id);
|
2014-08-13 08:56:55 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-11-21 14:35:49 -05:00
|
|
|
int *ev = alloc_log_event (8);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_our_id;
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[1] = id;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2014-08-14 18:16:01 -04:00
|
|
|
//write_auth_file ();
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_add (struct tgl_state *TLS, int id, const char *f, int fl, const char *l, int ll, long long access_token, const char *p, int pl, int contact) {
|
2013-11-21 14:35:49 -05:00
|
|
|
clear_packet ();
|
2014-08-12 17:32:11 -04:00
|
|
|
out_int (CODE_binlog_user_add);
|
2013-11-21 14:35:49 -05:00
|
|
|
out_int (id);
|
|
|
|
out_cstring (f ? f : "", fl);
|
|
|
|
out_cstring (l ? l : "", ll);
|
|
|
|
out_long (access_token);
|
|
|
|
out_cstring (p ? p : "", pl);
|
|
|
|
out_int (contact);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_delete (struct tgl_state *TLS, struct tgl_user *U) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->flags & FLAG_DELETED) { return; }
|
|
|
|
int *ev = alloc_log_event (8);
|
|
|
|
ev[0] = CODE_binlog_user_delete;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_user_profile_photo (struct tgl_state *TLS, struct tgl_user *U, long long photo_id, struct tgl_file_location *big, struct tgl_file_location *small) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (photo_id == U->photo_id) { return; }
|
|
|
|
if (!photo_id) {
|
2014-08-12 17:32:11 -04:00
|
|
|
int *ev = alloc_log_event (12);
|
|
|
|
ev[0] = CODE_binlog_user_set_photo;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[2] = CODE_user_profile_photo_empty;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2013-11-21 14:35:49 -05:00
|
|
|
} else {
|
|
|
|
clear_packet ();
|
2014-08-12 17:32:11 -04:00
|
|
|
out_int (CODE_binlog_user_set_photo);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_int (tgl_get_peer_id (U->id));
|
2013-11-21 14:35:49 -05:00
|
|
|
out_int (CODE_user_profile_photo);
|
|
|
|
out_long (photo_id);
|
|
|
|
if (small->dc >= 0) {
|
|
|
|
out_int (CODE_file_location);
|
|
|
|
out_int (small->dc);
|
|
|
|
out_long (small->volume);
|
|
|
|
out_int (small->local_id);
|
|
|
|
out_long (small->secret);
|
|
|
|
} else {
|
|
|
|
out_int (CODE_file_location_unavailable);
|
|
|
|
out_long (small->volume);
|
|
|
|
out_int (small->local_id);
|
|
|
|
out_long (small->secret);
|
|
|
|
}
|
|
|
|
if (big->dc >= 0) {
|
|
|
|
out_int (CODE_file_location);
|
|
|
|
out_int (big->dc);
|
|
|
|
out_long (big->volume);
|
|
|
|
out_int (big->local_id);
|
|
|
|
out_long (big->secret);
|
|
|
|
} else {
|
|
|
|
out_int (CODE_file_location_unavailable);
|
|
|
|
out_long (big->volume);
|
|
|
|
out_int (big->local_id);
|
|
|
|
out_long (big->secret);
|
|
|
|
}
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_name (struct tgl_state *TLS, struct tgl_user *U, const char *f, int fl, const char *l, int ll) {
|
2013-11-21 14:35:49 -05:00
|
|
|
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 ();
|
2014-08-12 17:32:11 -04:00
|
|
|
out_int (CODE_binlog_user_set_name);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_int (tgl_get_peer_id (U->id));
|
2013-11-21 14:35:49 -05:00
|
|
|
out_cstring (f, fl);
|
|
|
|
out_cstring (l, ll);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_username (struct tgl_state *TLS, struct tgl_user *U, const char *f, int l) {
|
2014-10-12 11:53:57 -04:00
|
|
|
if ((U->username && (int)strlen (U->username) == l && !strncmp (U->username, f, l)) ||
|
|
|
|
(!l && !U->username)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_user_set_username);
|
|
|
|
out_int (tgl_get_peer_id (U->id));
|
|
|
|
out_cstring (f, l);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-10-12 11:53:57 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_access_hash (struct tgl_state *TLS, struct tgl_user *U, long long access_token) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->access_hash == access_token) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_user_set_access_hash;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
*(long long *)(ev + 2) = access_token;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_phone (struct tgl_state *TLS, struct tgl_user *U, const char *p, int pl) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->phone && (int)strlen (U->phone) == pl && !strncmp (U->phone, p, pl)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clear_packet ();
|
2014-08-12 17:32:11 -04:00
|
|
|
out_int (CODE_binlog_user_set_phone);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_int (tgl_get_peer_id (U->id));
|
2013-11-21 14:35:49 -05:00
|
|
|
out_cstring (p, pl);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_friend (struct tgl_state *TLS, struct tgl_user *U, int friend) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (friend == ((U->flags & FLAG_USER_CONTACT) != 0)) { return ; }
|
|
|
|
int *ev = alloc_log_event (12);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_user_set_friend;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[2] = friend;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_dc_option (struct tgl_state *TLS, int id, int l1, const char *name, int l2, const char *ip, int port) {
|
|
|
|
struct tgl_dc *DC = TLS->DC_list[id];
|
2014-09-27 13:58:28 -04:00
|
|
|
if (DC && !strncmp (ip, DC->ip, l2)) { return; }
|
2013-11-21 14:35:49 -05:00
|
|
|
|
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_dc_option);
|
|
|
|
out_int (id);
|
|
|
|
out_cstring (name, l1);
|
|
|
|
out_cstring (ip, l2);
|
|
|
|
out_int (port);
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_dc_signed (struct tgl_state *TLS, int id) {
|
2013-11-21 14:35:49 -05:00
|
|
|
int *ev = alloc_log_event (8);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_dc_signed;
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[1] = id;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_working_dc (struct tgl_state *TLS, int num) {
|
2013-11-21 14:35:49 -05:00
|
|
|
int *ev = alloc_log_event (8);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_default_dc;
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[1] = num;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_full_photo (struct tgl_state *TLS, struct tgl_user *U, const int *start, int len) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->photo.id == *(long long *)(start + 1)) { return; }
|
|
|
|
int *ev = alloc_log_event (len + 8);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_user_set_full_photo;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
memcpy (ev + 2, start, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, len + 8);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_blocked (struct tgl_state *TLS, struct tgl_user *U, int blocked) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->blocked == blocked) { return; }
|
|
|
|
int *ev = alloc_log_event (12);
|
2014-08-12 17:32:11 -04:00
|
|
|
ev[0] = CODE_binlog_user_set_blocked;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[2] = blocked;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_user_set_real_name (struct tgl_state *TLS, struct tgl_user *U, const char *f, int fl, const char *l, int ll) {
|
2013-11-21 14:35:49 -05:00
|
|
|
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 ();
|
2014-08-12 17:32:11 -04:00
|
|
|
out_int (CODE_binlog_user_set_real_name);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_int (tgl_get_peer_id (U->id));
|
2013-11-21 14:35:49 -05:00
|
|
|
out_cstring (f, fl);
|
|
|
|
out_cstring (l, ll);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_delete (struct tgl_state *TLS, struct tgl_secret_chat *U) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (!(U->flags & FLAG_CREATED) || U->state == sc_deleted || U->state == sc_none) { return; }
|
|
|
|
int *ev = alloc_log_event (8);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_delete;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_requested (struct tgl_state *TLS, struct tgl_secret_chat *U, long long access_hash, int date, int admin_id, int user_id, unsigned char g_key[], unsigned char nonce[]) {
|
2013-11-29 16:43:56 -05:00
|
|
|
if (U->state != sc_none) { return; }
|
2013-11-21 14:35:49 -05:00
|
|
|
int *ev = alloc_log_event (540);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_requested;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
*(long long *)(ev + 2) = access_hash;
|
|
|
|
ev[4] = date;
|
|
|
|
ev[5] = admin_id;
|
|
|
|
ev[6] = user_id;
|
|
|
|
memcpy (ev + 7, g_key, 256);
|
|
|
|
memcpy (ev + 7 + 64, nonce, 256);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 540);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_set_access_hash (struct tgl_state *TLS, struct tgl_secret_chat *U, long long access_hash) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->access_hash == access_hash) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_encr_chat_set_access_hash;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
*(long long *)(ev + 2) = access_hash;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_set_date (struct tgl_state *TLS, struct tgl_secret_chat *U, int date) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->date == date) { return; }
|
|
|
|
int *ev = alloc_log_event (12);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_encr_chat_set_date;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[2] = date;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_set_ttl (struct tgl_state *TLS, struct tgl_secret_chat *U, int ttl) {
|
2014-08-31 10:18:19 -04:00
|
|
|
if (U->ttl == ttl) { return; }
|
|
|
|
int *ev = alloc_log_event (12);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_set_ttl;
|
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
|
|
|
ev[2] = ttl;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2014-08-31 10:18:19 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_set_layer (struct tgl_state *TLS, struct tgl_secret_chat *U, int layer) {
|
2014-10-14 16:20:03 -04:00
|
|
|
if (U->layer >= layer) { return; }
|
2014-08-31 10:18:19 -04:00
|
|
|
int *ev = alloc_log_event (12);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_set_layer;
|
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
|
|
|
ev[2] = layer;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2014-08-31 10:18:19 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_set_state (struct tgl_state *TLS, struct tgl_secret_chat *U, enum tgl_secret_chat_state state) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->state == state) { return; }
|
|
|
|
int *ev = alloc_log_event (12);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_encr_chat_set_state;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
ev[2] = state;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_accepted (struct tgl_state *TLS, struct tgl_secret_chat *U, const unsigned char g_key[], const unsigned char nonce[], long long key_fingerprint) {
|
2013-11-21 14:35:49 -05:00
|
|
|
if (U->state != sc_waiting && U->state != sc_request) { return; }
|
|
|
|
int *ev = alloc_log_event (528);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_accepted;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
memcpy (ev + 2, g_key, 256);
|
|
|
|
memcpy (ev + 66, nonce, 256);
|
|
|
|
*(long long *)(ev + 130) = key_fingerprint;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 528);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_create (struct tgl_state *TLS, int id, int user_id, int admin_id, char *name, int name_len) {
|
2014-08-31 10:18:19 -04:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_encr_chat_create);
|
|
|
|
out_int (id);
|
|
|
|
out_int (user_id);
|
|
|
|
out_int (admin_id);
|
|
|
|
out_cstring (name, name_len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-08-31 10:18:19 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_set_key (struct tgl_state *TLS, struct tgl_secret_chat *E, unsigned char key[], long long key_fingerprint) {
|
2013-11-21 14:35:49 -05:00
|
|
|
int *ev = alloc_log_event (272);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_encr_chat_set_key;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (E->id);
|
2013-11-21 14:35:49 -05:00
|
|
|
memcpy (ev + 2, key, 256);
|
|
|
|
*(long long *)(ev + 66) = key_fingerprint;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 272);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_update_seq (struct tgl_state *TLS, struct tgl_secret_chat *E, int in_seq_no, int out_seq_no) {
|
2014-10-14 16:20:03 -04:00
|
|
|
int *ev = alloc_log_event (16);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_update_seq;
|
|
|
|
ev[1] = tgl_get_peer_id (E->id);
|
|
|
|
ev[2] = in_seq_no;
|
|
|
|
ev[3] = out_seq_no;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2014-10-14 16:20:03 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_set_seq (struct tgl_state *TLS, struct tgl_secret_chat *E, int in_seq_no, int last_in_seq_no, int out_seq_no) {
|
2014-10-23 12:39:58 -04:00
|
|
|
int *ev = alloc_log_event (20);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_set_seq;
|
|
|
|
ev[1] = tgl_get_peer_id (E->id);
|
|
|
|
ev[2] = in_seq_no;
|
|
|
|
ev[3] = last_in_seq_no;
|
|
|
|
ev[4] = out_seq_no;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 20);
|
2014-10-23 12:39:58 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_dh_params (struct tgl_state *TLS, int root, unsigned char prime[], int version) {
|
2013-11-21 14:35:49 -05:00
|
|
|
int *ev = alloc_log_event (268);
|
|
|
|
ev[0] = CODE_binlog_set_dh_params;
|
|
|
|
ev[1] = root;
|
|
|
|
memcpy (ev + 2, prime, 256);
|
|
|
|
ev[66] = version;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 268);
|
2013-11-21 14:35:49 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_encr_chat_init (struct tgl_state *TLS, int id, int user_id, unsigned char random[], unsigned char g_a[]) {
|
2013-11-21 14:35:49 -05:00
|
|
|
int *ev = alloc_log_event (524);
|
|
|
|
ev[0] = CODE_binlog_encr_chat_init;
|
|
|
|
ev[1] = id;
|
|
|
|
ev[2] = user_id;
|
|
|
|
memcpy (ev + 3, random, 256);
|
|
|
|
memcpy (ev + 67, g_a, 256);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 524);
|
2013-11-12 19:11:25 -05:00
|
|
|
}
|
2013-11-21 16:40:31 -05:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_pts (struct tgl_state *TLS, int pts) {
|
|
|
|
if (TLS->locks & TGL_LOCK_DIFF) { return; }
|
|
|
|
if (pts <= TLS->pts) { return; }
|
2013-11-21 16:40:31 -05:00
|
|
|
int *ev = alloc_log_event (8);
|
|
|
|
ev[0] = CODE_binlog_set_pts;
|
|
|
|
ev[1] = pts;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 16:40:31 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_qts (struct tgl_state *TLS, int qts) {
|
|
|
|
if (TLS->locks & TGL_LOCK_DIFF) { return; }
|
|
|
|
if (qts <= TLS->qts) { return; }
|
2013-11-21 16:40:31 -05:00
|
|
|
int *ev = alloc_log_event (8);
|
|
|
|
ev[0] = CODE_binlog_set_qts;
|
|
|
|
ev[1] = qts;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 16:40:31 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_date (struct tgl_state *TLS, int date) {
|
|
|
|
if (TLS->locks & TGL_LOCK_DIFF) { return; }
|
|
|
|
if (date <= TLS->date) { return; }
|
2013-11-21 16:40:31 -05:00
|
|
|
int *ev = alloc_log_event (8);
|
|
|
|
ev[0] = CODE_binlog_set_date;
|
|
|
|
ev[1] = date;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 16:40:31 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_seq (struct tgl_state *TLS, int seq) {
|
|
|
|
if (TLS->locks & TGL_LOCK_DIFF) { return; }
|
|
|
|
if (seq == TLS->seq) { return; }
|
2013-11-21 16:40:31 -05:00
|
|
|
int *ev = alloc_log_event (8);
|
|
|
|
ev[0] = CODE_binlog_set_seq;
|
|
|
|
ev[1] = seq;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 8);
|
2013-11-21 16:40:31 -05:00
|
|
|
}
|
2013-11-22 18:26:35 -05:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_chat (struct tgl_state *TLS, struct tgl_chat *C, int y, const char *s, int l, int users_num, int date, int version, struct tgl_file_location *big, struct tgl_file_location *small) {
|
2013-11-22 18:26:35 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_chat_create);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_int (tgl_get_peer_id (C->id));
|
2013-11-22 18:26:35 -05:00
|
|
|
out_int (y);
|
|
|
|
out_cstring (s, l);
|
|
|
|
out_int (users_num);
|
|
|
|
out_int (date);
|
|
|
|
out_int (version);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_data (big, sizeof (struct tgl_file_location));
|
|
|
|
out_data (small, sizeof (struct tgl_file_location));
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-22 18:26:35 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_forbid (struct tgl_state *TLS, struct tgl_chat *C, int on) {
|
2013-11-22 18:26:35 -05:00
|
|
|
if (on) {
|
|
|
|
if (C->flags & FLAG_FORBIDDEN) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
|
|
|
ev[0] = CODE_binlog_chat_change_flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-22 18:26:35 -05:00
|
|
|
ev[2] = FLAG_FORBIDDEN;
|
|
|
|
ev[3] = 0;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-22 18:26:35 -05:00
|
|
|
} else {
|
|
|
|
if (!(C->flags & FLAG_FORBIDDEN)) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
|
|
|
ev[0] = CODE_binlog_chat_change_flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-22 18:26:35 -05:00
|
|
|
ev[2] = 0;
|
|
|
|
ev[3] = FLAG_FORBIDDEN;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-22 18:26:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_title (struct tgl_state *TLS, struct tgl_chat *C, const char *s, int l) {
|
2013-11-22 18:26:35 -05:00
|
|
|
if (C->title && (int)strlen (C->title) == l && !strncmp (C->title, s, l)) { return; }
|
|
|
|
clear_packet ();
|
2014-08-12 17:51:16 -04:00
|
|
|
out_int (CODE_binlog_chat_set_title);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_int (tgl_get_peer_id (C->id));
|
2013-11-22 18:26:35 -05:00
|
|
|
out_cstring (s, l);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-22 18:26:35 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_photo (struct tgl_state *TLS, struct tgl_chat *C, struct tgl_file_location *big, struct tgl_file_location *small) {
|
2014-08-13 11:55:16 -04:00
|
|
|
if (!memcmp (&C->photo_small, small, sizeof (struct tgl_file_location)) &&
|
|
|
|
!memcmp (&C->photo_big, big, sizeof (struct tgl_file_location))) { return; }
|
2013-11-22 18:26:35 -05:00
|
|
|
clear_packet ();
|
2014-08-12 17:51:16 -04:00
|
|
|
out_int (CODE_binlog_chat_set_photo);
|
2014-08-13 11:55:16 -04:00
|
|
|
out_int (tgl_get_peer_id (C->id));
|
|
|
|
out_data (big, sizeof (struct tgl_file_location));
|
|
|
|
out_data (small, sizeof (struct tgl_file_location));
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-22 18:26:35 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_date (struct tgl_state *TLS, struct tgl_chat *C, int date) {
|
2013-11-22 18:26:35 -05:00
|
|
|
if (C->date == date) { return; }
|
|
|
|
int *ev = alloc_log_event (12);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_chat_set_date;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-22 18:26:35 -05:00
|
|
|
ev[2] = date;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2013-11-22 18:26:35 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_set_in_chat (struct tgl_state *TLS, struct tgl_chat *C, int on) {
|
2013-11-22 18:26:35 -05:00
|
|
|
if (on) {
|
|
|
|
if (C->flags & FLAG_CHAT_IN_CHAT) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
|
|
|
ev[0] = CODE_binlog_chat_change_flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-22 18:26:35 -05:00
|
|
|
ev[2] = FLAG_CHAT_IN_CHAT;
|
|
|
|
ev[3] = 0;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-22 18:26:35 -05:00
|
|
|
} else {
|
|
|
|
if (!(C->flags & FLAG_CHAT_IN_CHAT)) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
|
|
|
ev[0] = CODE_binlog_chat_change_flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-22 18:26:35 -05:00
|
|
|
ev[2] = 0;
|
|
|
|
ev[3] = FLAG_CHAT_IN_CHAT;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-22 18:26:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_version (struct tgl_state *TLS, struct tgl_chat *C, int version, int user_num) {
|
2013-11-22 18:26:35 -05:00
|
|
|
if (C->version >= version) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_chat_set_version;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-22 18:26:35 -05:00
|
|
|
ev[2] = version;
|
|
|
|
ev[3] = user_num;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-22 18:26:35 -05:00
|
|
|
}
|
2013-11-25 11:13:36 -05:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_admin (struct tgl_state *TLS, struct tgl_chat *C, int admin) {
|
2013-11-25 11:13:36 -05:00
|
|
|
if (C->admin_id == admin) { return; }
|
|
|
|
int *ev = alloc_log_event (12);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_chat_set_admin;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-25 11:13:36 -05:00
|
|
|
ev[2] = admin;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12);
|
2013-11-25 11:13:36 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_participants (struct tgl_state *TLS, struct tgl_chat *C, int version, int user_num, struct tgl_chat_user *users) {
|
2013-11-25 11:13:36 -05:00
|
|
|
if (C->user_list_version >= version) { return; }
|
|
|
|
int *ev = alloc_log_event (12 * user_num + 16);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_chat_set_participants;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-25 11:13:36 -05:00
|
|
|
ev[2] = version;
|
|
|
|
ev[3] = user_num;
|
|
|
|
memcpy (ev + 4, users, 12 * user_num);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 12 * user_num + 16);
|
2013-11-25 11:13:36 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_set_full_photo (struct tgl_state *TLS, struct tgl_chat *U, const int *start, int len) {
|
2013-11-25 11:13:36 -05:00
|
|
|
if (U->photo.id == *(long long *)(start + 1)) { return; }
|
|
|
|
int *ev = alloc_log_event (len + 8);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_chat_set_full_photo;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (U->id);
|
2013-11-25 11:13:36 -05:00
|
|
|
memcpy (ev + 2, start, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, len + 8);
|
2013-11-25 11:13:36 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_add_user (struct tgl_state *TLS, struct tgl_chat *C, int version, int user, int inviter, int date) {
|
2013-11-25 11:13:36 -05:00
|
|
|
if (C->user_list_version >= version || !C->user_list_version) { return; }
|
|
|
|
int *ev = alloc_log_event (24);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_chat_add_participant;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-25 11:13:36 -05:00
|
|
|
ev[2] = version;
|
|
|
|
ev[3] = user;
|
|
|
|
ev[4] = inviter;
|
|
|
|
ev[5] = date;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 24);
|
2013-11-25 11:13:36 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_chat_del_user (struct tgl_state *TLS, struct tgl_chat *C, int version, int user) {
|
2013-11-25 11:13:36 -05:00
|
|
|
if (C->user_list_version >= version || !C->user_list_version) { return; }
|
|
|
|
int *ev = alloc_log_event (16);
|
2014-08-12 17:51:16 -04:00
|
|
|
ev[0] = CODE_binlog_chat_del_participant;
|
2014-08-13 11:55:16 -04:00
|
|
|
ev[1] = tgl_get_peer_id (C->id);
|
2013-11-25 11:13:36 -05:00
|
|
|
ev[2] = version;
|
|
|
|
ev[3] = user;
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, ev, 16);
|
2013-11-25 11:13:36 -05:00
|
|
|
}
|
2013-11-29 16:43:56 -05:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_text (struct tgl_state *TLS, int msg_id, int from_id, int to_type, int to_id, int date, int unread, int l, const char *s) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_text);
|
|
|
|
out_int (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
2014-08-21 16:35:27 -04:00
|
|
|
out_int (unread);
|
2013-11-29 16:43:56 -05:00
|
|
|
out_cstring (s, l);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_send_message_text (struct tgl_state *TLS, long long msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_send_message_text);
|
|
|
|
out_long (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_cstring (s, l);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_send_message_action_encr (struct tgl_state *TLS, long long msg_id, int from_id, int to_type, int to_id, int date, int l, const int *action) {
|
2014-08-12 21:22:15 -04:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_send_message_action_encr);
|
|
|
|
out_long (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_ints (action, l);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-08-12 21:22:15 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_text_fwd (struct tgl_state *TLS, int msg_id, int from_id, int to_type, int to_id, int date, int fwd, int fwd_date, int unread, int l, const char *s) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_text_fwd);
|
|
|
|
out_int (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_int (fwd);
|
|
|
|
out_int (fwd_date);
|
2014-08-21 16:35:27 -04:00
|
|
|
out_int (unread);
|
2013-11-29 16:43:56 -05:00
|
|
|
out_cstring (s, l);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_media (struct tgl_state *TLS, int msg_id, int from_id, int to_type, int to_id, int date, int unread, int l, const char *s, const int *data, int len) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_media);
|
|
|
|
out_int (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
2014-08-21 16:35:27 -04:00
|
|
|
out_int (unread);
|
2013-11-29 16:43:56 -05:00
|
|
|
out_cstring (s, l);
|
|
|
|
out_ints (data, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_media_encr (struct tgl_state *TLS, long long msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s, const int *data, int len, const int *data2, int len2) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_media_encr);
|
|
|
|
out_long (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_cstring (s, l);
|
|
|
|
out_ints (data, len);
|
|
|
|
out_ints (data2, len2);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_media_encr_pending (struct tgl_state *TLS, long long msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s, const int *data, int len) {
|
2014-09-11 16:57:59 -04:00
|
|
|
int *s_packet_buffer = packet_buffer;
|
|
|
|
int *s_packet_ptr = packet_ptr;
|
|
|
|
packet_buffer = b_packet_buffer;
|
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_media_encr_pending);
|
|
|
|
out_long (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_cstring (s, l);
|
|
|
|
out_ints (data, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-09-11 16:57:59 -04:00
|
|
|
packet_buffer = s_packet_buffer;
|
|
|
|
packet_ptr = s_packet_ptr;
|
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_media_encr_sent (struct tgl_state *TLS, long long msg_id, const int *data, int len) {
|
2014-09-11 16:57:59 -04:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_media_encr_sent);
|
|
|
|
out_long (msg_id);
|
|
|
|
out_ints (data, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-09-11 16:57:59 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_media_fwd (struct tgl_state *TLS, int msg_id, int from_id, int to_type, int to_id, int date, int fwd, int fwd_date, int unread, int l, const char *s, const int *data, int len) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_media_fwd);
|
|
|
|
out_int (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_int (fwd);
|
|
|
|
out_int (fwd_date);
|
2014-08-21 16:35:27 -04:00
|
|
|
out_int (unread);
|
2013-11-29 16:43:56 -05:00
|
|
|
out_cstring (s, l);
|
|
|
|
out_ints (data, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_service (struct tgl_state *TLS, int msg_id, int from_id, int to_type, int to_id, int date, int unread, const int *data, int len) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_service);
|
|
|
|
out_int (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
2014-08-21 16:35:27 -04:00
|
|
|
out_int (unread);
|
2013-11-29 16:43:56 -05:00
|
|
|
out_ints (data, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
2014-08-12 21:22:15 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_service_encr (struct tgl_state *TLS, long long msg_id, int from_id, int to_type, int to_id, int date, const int *data, int len) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_service_encr);
|
|
|
|
out_long (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_ints (data, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_create_message_service_fwd (struct tgl_state *TLS, int msg_id, int from_id, int to_type, int to_id, int date, int fwd, int fwd_date, int unread, const int *data, int len) {
|
2013-11-29 16:43:56 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_create_message_service_fwd);
|
|
|
|
out_int (msg_id);
|
|
|
|
out_int (from_id);
|
|
|
|
out_int (to_type);
|
|
|
|
out_int (to_id);
|
|
|
|
out_int (date);
|
|
|
|
out_int (fwd);
|
|
|
|
out_int (fwd_date);
|
2014-08-21 16:35:27 -04:00
|
|
|
out_int (unread);
|
2013-11-29 16:43:56 -05:00
|
|
|
out_ints (data, len);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_unread_long (struct tgl_state *TLS, struct tgl_message *M, int unread) {
|
2014-08-21 11:38:51 -04:00
|
|
|
if (unread || !M->unread) { return; }
|
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_message_set_unread_long);
|
|
|
|
out_long (M->id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-08-21 11:38:51 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_unread (struct tgl_state *TLS, struct tgl_message *M, int unread) {
|
|
|
|
if (M->id != (int)M->id) { bl_do_set_unread_long (TLS, M, unread); }
|
2013-11-29 16:43:56 -05:00
|
|
|
if (unread || !M->unread) { return; }
|
|
|
|
clear_packet ();
|
2014-08-12 17:32:11 -04:00
|
|
|
out_int (CODE_binlog_message_set_unread);
|
2013-11-29 16:43:56 -05:00
|
|
|
out_int (M->id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_message_sent (struct tgl_state *TLS, struct tgl_message *M) {
|
2013-11-29 16:43:56 -05:00
|
|
|
if (!(M->flags & FLAG_PENDING)) { return; }
|
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_set_message_sent);
|
|
|
|
out_long (M->id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_set_msg_id (struct tgl_state *TLS, struct tgl_message *M, int id) {
|
2013-11-29 16:43:56 -05:00
|
|
|
if (M->id == id) { return; }
|
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_set_msg_id);
|
|
|
|
out_long (M->id);
|
|
|
|
out_int (id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-11-29 16:43:56 -05:00
|
|
|
}
|
2013-12-06 12:14:41 -05:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_delete_msg (struct tgl_state *TLS, struct tgl_message *M) {
|
2013-12-06 12:14:41 -05:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_delete_msg);
|
|
|
|
out_long (M->id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2013-12-06 12:14:41 -05:00
|
|
|
}
|
2014-08-20 12:36:45 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_msg_seq_update (struct tgl_state *TLS, long long id) {
|
|
|
|
if (TLS->locks & TGL_LOCK_DIFF) {
|
2014-08-21 11:38:51 -04:00
|
|
|
return; // We will receive this update in get_difference, that works now
|
|
|
|
}
|
2014-08-20 12:36:45 -04:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_msg_seq_update);
|
|
|
|
out_long (id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-08-20 12:36:45 -04:00
|
|
|
}
|
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_msg_update (struct tgl_state *TLS, long long id) {
|
2014-08-20 12:36:45 -04:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_msg_update);
|
|
|
|
out_long (id);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-08-20 12:36:45 -04:00
|
|
|
}
|
2014-08-20 23:24:52 -04:00
|
|
|
|
2014-10-24 13:43:08 -04:00
|
|
|
void bl_do_reset_authorization (struct tgl_state *TLS) {
|
2014-09-18 09:57:23 -04:00
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_reset_authorization);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-09-18 09:57:23 -04:00
|
|
|
}
|
2014-08-20 23:24:52 -04:00
|
|
|
/*void bl_do_add_dc (int id, const char *ip, int l, int port, long long auth_key_id, const char *auth_key) {
|
|
|
|
clear_packet ();
|
|
|
|
out_int (CODE_binlog_add_dc);
|
|
|
|
out_long (id);
|
|
|
|
out_cstring (ip, l);
|
|
|
|
out_int (port);
|
|
|
|
out_long (auth_key_id);
|
|
|
|
out_ints ((void *)auth_key, 64);
|
2014-10-24 13:43:08 -04:00
|
|
|
add_log_event (TLS, packet_buffer, 4 * (packet_ptr - packet_buffer));
|
2014-08-20 23:24:52 -04:00
|
|
|
}*/
|