Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
f4ac638c
Commit
f4ac638c
authored
Nov 22, 2013
by
Vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed binlog. Added state file to binlog
parent
bfd53643
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
11 deletions
+141
-11
binlog.c
binlog.c
+50
-1
binlog.h
binlog.h
+9
-0
loop.c
loop.c
+2
-0
mtproto-client.c
mtproto-client.c
+68
-2
mtproto-client.h
mtproto-client.h
+1
-0
queries.c
queries.c
+11
-8
No files found.
binlog.c
View file @
f4ac638c
...
...
@@ -22,6 +22,11 @@ int *rptr;
int
*
wptr
;
extern
int
test_dc
;
extern
int
pts
;
extern
int
qts
;
extern
int
last_date
;
extern
int
seq
;
#define MAX_LOG_EVENT_SIZE (1 << 17)
char
*
get_binlog_file_name
(
void
);
...
...
@@ -522,9 +527,25 @@ void replay_log_event (void) {
P
->
flags
|=
FLAG_CREATED
;
}
break
;
case
CODE_binlog_set_pts
:
rptr
++
;
pts
=
*
(
rptr
++
);
break
;
case
CODE_binlog_set_qts
:
rptr
++
;
qts
=
*
(
rptr
++
);
break
;
case
CODE_binlog_set_date
:
rptr
++
;
last_date
=
*
(
rptr
++
);
break
;
case
CODE_binlog_set_seq
:
rptr
++
;
seq
=
*
(
rptr
++
);
break
;
case
CODE_update_user_photo
:
case
CODE_update_user_name
:
work_update
(
0
,
0
);
work_update
_binlog
(
);
rptr
=
in_ptr
;
break
;
default:
...
...
@@ -905,3 +926,31 @@ void bl_do_encr_chat_init (int id, int user_id, unsigned char random[], unsigned
memcpy
(
ev
+
67
,
g_a
,
256
);
add_log_event
(
ev
,
524
);
}
void
bl_do_set_pts
(
int
pts
)
{
int
*
ev
=
alloc_log_event
(
8
);
ev
[
0
]
=
CODE_binlog_set_pts
;
ev
[
1
]
=
pts
;
add_log_event
(
ev
,
8
);
}
void
bl_do_set_qts
(
int
qts
)
{
int
*
ev
=
alloc_log_event
(
8
);
ev
[
0
]
=
CODE_binlog_set_qts
;
ev
[
1
]
=
qts
;
add_log_event
(
ev
,
8
);
}
void
bl_do_set_date
(
int
date
)
{
int
*
ev
=
alloc_log_event
(
8
);
ev
[
0
]
=
CODE_binlog_set_date
;
ev
[
1
]
=
date
;
add_log_event
(
ev
,
8
);
}
void
bl_do_set_seq
(
int
seq
)
{
int
*
ev
=
alloc_log_event
(
8
);
ev
[
0
]
=
CODE_binlog_set_seq
;
ev
[
1
]
=
seq
;
add_log_event
(
ev
,
8
);
}
binlog.h
View file @
f4ac638c
...
...
@@ -36,6 +36,10 @@
#define CODE_binlog_set_encr_chat_key 0x179df2d4
#define CODE_binlog_set_dh_params 0x20ba46bc
#define CODE_binlog_encr_chat_init 0x939cd1c7
#define CODE_binlog_set_pts 0x844e4c1c
#define CODE_binlog_set_qts 0x3cf22b79
#define CODE_binlog_set_date 0x33dfe392
#define CODE_binlog_set_seq 0xb9294837
void
*
alloc_log_event
(
int
l
);
void
replay_log
(
void
);
...
...
@@ -69,4 +73,9 @@ void bl_do_encr_chat_init (int id, int user_id, unsigned char random[], unsigned
void
bl_do_dc_signed
(
int
id
);
void
bl_do_set_working_dc
(
int
num
);
void
bl_do_set_dh_params
(
int
root
,
unsigned
char
prime
[],
int
version
);
void
bl_do_set_pts
(
int
pts
);
void
bl_do_set_qts
(
int
qts
);
void
bl_do_set_seq
(
int
seq
);
void
bl_do_set_date
(
int
date
);
#endif
loop.c
View file @
f4ac638c
...
...
@@ -260,6 +260,7 @@ void read_auth_file (void) {
int
pts
,
qts
,
seq
,
last_date
;
void
read_state_file
(
void
)
{
if
(
binlog_enabled
)
{
return
;
}
int
state_file_fd
=
open
(
get_state_filename
(),
O_CREAT
|
O_RDWR
,
0600
);
if
(
state_file_fd
<
0
)
{
return
;
...
...
@@ -282,6 +283,7 @@ void read_state_file (void) {
}
void
write_state_file
(
void
)
{
if
(
binlog_enabled
)
{
return
;
}
static
int
wseq
;
static
int
wpts
;
static
int
wqts
;
...
...
mtproto-client.c
View file @
f4ac638c
...
...
@@ -669,6 +669,7 @@ void fetch_pts (void) {
}
else
{
pts
++
;
}
bl_do_set_pts
(
pts
);
}
void
fetch_qts
(
void
)
{
...
...
@@ -685,12 +686,14 @@ void fetch_qts (void) {
}
else
{
qts
++
;
}
bl_do_set_qts
(
qts
);
}
void
fetch_date
(
void
)
{
int
p
=
fetch_int
();
if
(
p
>
last_date
)
{
last_date
=
p
;
bl_do_set_date
(
last_date
);
}
}
...
...
@@ -699,9 +702,72 @@ void fetch_seq (void) {
if
(
x
>
seq
+
1
)
{
logprintf
(
"Hole in seq: seq = %d, x = %d
\n
"
,
seq
,
x
);
//do_get_difference ();
//seq = x;
}
else
if
(
x
==
seq
+
1
)
{
seq
=
x
;
}
else
if
(
x
>=
seq
+
1
)
{
seq
=
x
;
bl_do_set_seq
(
seq
);
}
}
void
work_update_binlog
(
void
)
{
unsigned
op
=
fetch_int
();
switch
(
op
)
{
case
CODE_update_user_name
:
{
peer_id_t
user_id
=
MK_USER
(
fetch_int
());
peer_t
*
UC
=
user_chat_get
(
user_id
);
if
(
UC
)
{
struct
user
*
U
=
&
UC
->
user
;
if
(
U
->
first_name
)
{
free
(
U
->
first_name
);
}
if
(
U
->
last_name
)
{
free
(
U
->
last_name
);
}
if
(
U
->
print_name
)
{
free
(
U
->
print_name
);
}
U
->
first_name
=
fetch_str_dup
();
U
->
last_name
=
fetch_str_dup
();
U
->
print_name
=
create_print_name
(
U
->
id
,
U
->
first_name
,
U
->
last_name
,
0
,
0
);
}
else
{
int
l
;
l
=
prefetch_strlen
();
fetch_str
(
l
);
l
=
prefetch_strlen
();
fetch_str
(
l
);
}
}
break
;
case
CODE_update_user_photo
:
{
peer_id_t
user_id
=
MK_USER
(
fetch_int
());
peer_t
*
UC
=
user_chat_get
(
user_id
);
fetch_date
();
if
(
UC
)
{
struct
user
*
U
=
&
UC
->
user
;
unsigned
y
=
fetch_int
();
if
(
y
==
CODE_user_profile_photo_empty
)
{
U
->
photo_id
=
0
;
U
->
photo_big
.
dc
=
-
2
;
U
->
photo_small
.
dc
=
-
2
;
}
else
{
assert
(
y
==
CODE_user_profile_photo
);
U
->
photo_id
=
fetch_long
();
fetch_file_location
(
&
U
->
photo_small
);
fetch_file_location
(
&
U
->
photo_big
);
}
}
else
{
struct
file_location
t
;
unsigned
y
=
fetch_int
();
if
(
y
==
CODE_user_profile_photo_empty
)
{
}
else
{
assert
(
y
==
CODE_user_profile_photo
);
fetch_long
();
// photo_id
fetch_file_location
(
&
t
);
fetch_file_location
(
&
t
);
}
}
fetch_bool
();
}
break
;
default:
assert
(
0
);
}
}
...
...
mtproto-client.h
View file @
f4ac638c
...
...
@@ -24,4 +24,5 @@ void on_start (void);
long
long
encrypt_send_message
(
struct
connection
*
c
,
int
*
msg
,
int
msg_ints
,
int
useful
);
void
dc_authorize
(
struct
dc
*
DC
);
void
work_update
(
struct
connection
*
c
,
long
long
msg_id
);
void
work_update_binlog
(
void
);
#endif
queries.c
View file @
f4ac638c
...
...
@@ -2409,17 +2409,19 @@ int difference_got;
int
seq
,
pts
,
qts
,
last_date
;
int
get_state_on_answer
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_updates_state
);
pts
=
fetch_int
(
);
qts
=
fetch_int
(
);
last_date
=
fetch_int
(
);
seq
=
fetch_int
(
);
bl_do_set_pts
(
fetch_int
()
);
bl_do_set_qts
(
fetch_int
()
);
bl_do_set_date
(
fetch_int
()
);
bl_do_set_seq
(
fetch_int
()
);
unread_messages
=
fetch_int
();
write_state_file
();
difference_got
=
1
;
return
0
;
}
int
get_difference_active
;
int
get_difference_on_answer
(
struct
query
*
q
UU
)
{
get_difference_active
=
0
;
unsigned
x
=
fetch_int
();
if
(
x
==
CODE_updates_difference_empty
)
{
fetch_date
();
...
...
@@ -2463,10 +2465,10 @@ int get_difference_on_answer (struct query *q UU) {
fetch_alloc_user
();
}
assert
(
fetch_int
()
==
(
int
)
CODE_updates_state
);
pts
=
fetch_int
(
);
qts
=
fetch_int
(
);
last_date
=
fetch_int
(
);
seq
=
fetch_int
(
);
bl_do_set_pts
(
fetch_int
()
);
bl_do_set_qts
(
fetch_int
()
);
bl_do_set_date
(
fetch_int
()
);
bl_do_set_seq
(
fetch_int
()
);
unread_messages
=
fetch_int
();
write_state_file
();
for
(
i
=
0
;
i
<
ml_pos
;
i
++
)
{
...
...
@@ -2492,6 +2494,7 @@ struct query_methods get_difference_methods = {
};
void
do_get_difference
(
void
)
{
get_difference_active
=
1
;
difference_got
=
0
;
clear_packet
();
do_insert_header
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment