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
c01eb112
Commit
c01eb112
authored
Oct 23, 2014
by
Vysheng
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:vysheng/tg
parents
f024b4bf
282b1c6a
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
174 additions
and
129 deletions
+174
-129
binlog.c
binlog.c
+28
-8
binlog.h
binlog.h
+1
-0
binlog.tl
binlog.tl
+1
-0
interface.c
interface.c
+3
-0
loop.c
loop.c
+18
-5
mtproto-client.c
mtproto-client.c
+0
-7
queries.c
queries.c
+0
-1
structures.c
structures.c
+101
-108
tgl.c
tgl.c
+3
-0
tgl.h
tgl.h
+19
-0
No files found.
binlog.c
View file @
c01eb112
...
...
@@ -39,7 +39,6 @@
#include "net.h"
#include "include.h"
#include "mtproto-client.h"
#include "loop.h"
#include "tgl.h"
#include "auto.h"
...
...
@@ -52,7 +51,7 @@
static
int
binlog_buffer
[
BINLOG_BUFFER_SIZE
];
static
int
*
rptr
;
static
int
*
wptr
;
static
int
binlog_fd
;
//static int tgl_state.
binlog_fd;
static
int
in_replay_log
;
// should be used ONLY for DEBUG
...
...
@@ -516,6 +515,16 @@ static int fetch_comb_binlog_encr_chat_update_seq (void *extra) {
return
0
;
}
static
int
fetch_comb_binlog_encr_chat_set_seq
(
void
*
extra
)
{
tgl_peer_id_t
id
=
TGL_MK_ENCR_CHAT
(
fetch_int
());
tgl_peer_t
*
_U
=
tgl_peer_get
(
id
);
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
;
}
static
int
fetch_comb_binlog_encr_chat_init
(
void
*
extra
)
{
tgl_peer_t
*
P
=
talloc0
(
sizeof
(
*
P
));
P
->
id
=
TGL_MK_ENCR_CHAT
(
fetch_int
());
...
...
@@ -1312,6 +1321,7 @@ static void replay_log_event (void) {
FETCH_COMBINATOR_FUNCTION
(
binlog_encr_chat_accepted
)
FETCH_COMBINATOR_FUNCTION
(
binlog_encr_chat_set_key
)
FETCH_COMBINATOR_FUNCTION
(
binlog_encr_chat_update_seq
)
FETCH_COMBINATOR_FUNCTION
(
binlog_encr_chat_set_seq
)
FETCH_COMBINATOR_FUNCTION
(
binlog_encr_chat_init
)
FETCH_COMBINATOR_FUNCTION
(
binlog_encr_chat_create
)
...
...
@@ -1467,14 +1477,14 @@ void tgl_replay_log (void) {
static
int
b_packet_buffer
[
PACKET_BUFFER_SIZE
];
void
tgl_reopen_binlog_for_writing
(
void
)
{
binlog_fd
=
open
(
get_binlog_file_name
(),
O_WRONLY
);
if
(
binlog_fd
<
0
)
{
tgl_state
.
binlog_fd
=
open
(
get_binlog_file_name
(),
O_WRONLY
);
if
(
tgl_state
.
binlog_fd
<
0
)
{
perror
(
"binlog open"
);
exit
(
2
);
}
assert
(
lseek
(
binlog_fd
,
binlog_pos
,
SEEK_SET
)
==
binlog_pos
);
if
(
flock
(
binlog_fd
,
LOCK_EX
|
LOCK_NB
)
<
0
)
{
assert
(
lseek
(
tgl_state
.
binlog_fd
,
binlog_pos
,
SEEK_SET
)
==
binlog_pos
);
if
(
flock
(
tgl_state
.
binlog_fd
,
LOCK_EX
|
LOCK_NB
)
<
0
)
{
perror
(
"get lock"
);
exit
(
2
);
}
...
...
@@ -1493,8 +1503,8 @@ static void add_log_event (const int *data, int len) {
assert
(
rptr
==
wptr
);
}
if
(
tgl_state
.
binlog_enabled
)
{
assert
(
binlog_fd
>
0
);
assert
(
write
(
binlog_fd
,
data
,
len
)
==
len
);
assert
(
tgl_state
.
binlog_fd
>
0
);
assert
(
write
(
tgl_state
.
binlog_fd
,
data
,
len
)
==
len
);
}
in_ptr
=
in
;
in_end
=
end
;
...
...
@@ -1805,6 +1815,16 @@ void bl_do_encr_chat_update_seq (struct tgl_secret_chat *E, int in_seq_no, int o
add_log_event
(
ev
,
16
);
}
void
bl_do_encr_chat_set_seq
(
struct
tgl_secret_chat
*
E
,
int
in_seq_no
,
int
last_in_seq_no
,
int
out_seq_no
)
{
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
;
add_log_event
(
ev
,
20
);
}
void
bl_do_set_dh_params
(
int
root
,
unsigned
char
prime
[],
int
version
)
{
int
*
ev
=
alloc_log_event
(
268
);
ev
[
0
]
=
CODE_binlog_set_dh_params
;
...
...
binlog.h
View file @
c01eb112
...
...
@@ -52,6 +52,7 @@ void bl_do_encr_chat_accepted (struct tgl_secret_chat *U, const unsigned char g_
void
bl_do_encr_chat_set_key
(
struct
tgl_secret_chat
*
E
,
unsigned
char
key
[],
long
long
key_fingerprint
);
void
bl_do_encr_chat_init
(
int
id
,
int
user_id
,
unsigned
char
random
[],
unsigned
char
g_a
[]);
void
bl_do_encr_chat_update_seq
(
struct
tgl_secret_chat
*
E
,
int
in_seq_no
,
int
out_seq_no
);
void
bl_do_encr_chat_set_seq
(
struct
tgl_secret_chat
*
E
,
int
in_seq_no
,
int
last_in_seq_no
,
int
out_seq_no
);
void
bl_do_dc_signed
(
int
id
);
void
bl_do_set_working_dc
(
int
num
);
...
...
binlog.tl
View file @
c01eb112
...
...
@@ -43,6 +43,7 @@ binlog.encrChatSetState id:int state:int = binlog.Update;
binlog.encrChatSetKey id:int key:64*[int] fingerprint:long = binlog.Update;
binlog.encrChatUpdateSeq id:int in_seq_no:int out_seq_no:int = binlog.Update;
binlog.encrChatSetSeq id:int in_seq_no:int last_in_seq_no:int out_seq_no:int = binlog.Update;
binlog.chatCreate id:int flags:int title:string user_num:int date:int version:int photo_big:%binlog.FileLocation photo_small:%binlog.FileLocation = binlog.Update;
binlog.chatChangeFlags id:int set_flags:int clear_flags:int = binlog.Update;
...
...
interface.c
View file @
c01eb112
...
...
@@ -1733,6 +1733,9 @@ void print_message_gw (struct tgl_message *M) {
lua_new_msg
(
M
);
#endif
if
(
!
binlog_read
)
{
return
;
}
if
(
tgl_get_peer_type
(
M
->
to_id
)
==
TGL_PEER_ENCR_CHAT
)
{
write_secret_chat_file
();
}
if
(
alert_sound
)
{
play_sound
();
}
...
...
loop.c
View file @
c01eb112
...
...
@@ -458,6 +458,9 @@ void write_secret_chat (tgl_peer_t *_P, void *extra) {
assert
(
write
(
fd
,
&
P
->
state
,
4
)
==
4
);
assert
(
write
(
fd
,
&
P
->
key_fingerprint
,
8
)
==
8
);
assert
(
write
(
fd
,
&
P
->
key
,
256
)
==
256
);
assert
(
write
(
fd
,
&
P
->
in_seq_no
,
4
)
==
4
);
assert
(
write
(
fd
,
&
P
->
last_in_seq_no
,
4
)
==
4
);
assert
(
write
(
fd
,
&
P
->
out_seq_no
,
4
)
==
4
);
}
void
write_secret_chat_file
(
void
)
{
...
...
@@ -466,7 +469,7 @@ void write_secret_chat_file (void) {
assert
(
secret_chat_fd
>=
0
);
int
x
=
SECRET_CHAT_FILE_MAGIC
;
assert
(
write
(
secret_chat_fd
,
&
x
,
4
)
==
4
);
x
=
0
;
x
=
1
;
assert
(
write
(
secret_chat_fd
,
&
x
,
4
)
==
4
);
// version
assert
(
write
(
secret_chat_fd
,
&
x
,
4
)
==
4
);
// num
...
...
@@ -559,7 +562,7 @@ void read_auth_file (void) {
close
(
auth_file_fd
);
}
void
read_secret_chat
(
int
fd
)
{
void
read_secret_chat
(
int
fd
,
int
v
)
{
int
id
,
l
,
user_id
,
admin_id
,
date
,
ttl
,
layer
,
state
;
long
long
access_hash
,
key_fingerprint
;
static
char
s
[
1000
];
...
...
@@ -578,6 +581,12 @@ void read_secret_chat (int fd) {
assert
(
read
(
fd
,
&
state
,
4
)
==
4
);
assert
(
read
(
fd
,
&
key_fingerprint
,
8
)
==
8
);
assert
(
read
(
fd
,
&
key
,
256
)
==
256
);
int
in_seq_no
=
0
,
out_seq_no
=
0
,
last_in_seq_no
=
0
;
if
(
v
>=
1
)
{
assert
(
read
(
fd
,
&
in_seq_no
,
4
)
==
4
);
assert
(
read
(
fd
,
&
last_in_seq_no
,
4
)
==
4
);
assert
(
read
(
fd
,
&
out_seq_no
,
4
)
==
4
);
}
bl_do_encr_chat_create
(
id
,
user_id
,
admin_id
,
s
,
l
);
struct
tgl_secret_chat
*
P
=
(
void
*
)
tgl_peer_get
(
TGL_MK_ENCR_CHAT
(
id
));
...
...
@@ -588,6 +597,9 @@ void read_secret_chat (int fd) {
bl_do_encr_chat_set_access_hash
(
P
,
access_hash
);
bl_do_encr_chat_set_state
(
P
,
state
);
bl_do_encr_chat_set_key
(
P
,
key
,
key_fingerprint
);
if
(
v
>=
1
)
{
bl_do_encr_chat_set_seq
(
P
,
in_seq_no
,
last_in_seq_no
,
out_seq_no
);
}
}
void
read_secret_chat_file
(
void
)
{
...
...
@@ -598,12 +610,13 @@ void read_secret_chat_file (void) {
int
x
;
if
(
read
(
secret_chat_fd
,
&
x
,
4
)
<
4
)
{
close
(
secret_chat_fd
);
return
;
}
if
(
x
!=
SECRET_CHAT_FILE_MAGIC
)
{
close
(
secret_chat_fd
);
return
;
}
assert
(
read
(
secret_chat_fd
,
&
x
,
4
)
==
4
);
assert
(
!
x
);
// version
int
v
=
0
;
assert
(
read
(
secret_chat_fd
,
&
v
,
4
)
==
4
);
assert
(
v
==
0
||
v
==
1
);
// version
assert
(
read
(
secret_chat_fd
,
&
x
,
4
)
==
4
);
assert
(
x
>=
0
);
while
(
x
-->
0
)
{
read_secret_chat
(
secret_chat_fd
);
read_secret_chat
(
secret_chat_fd
,
v
);
}
close
(
secret_chat_fd
);
}
...
...
mtproto-client.c
View file @
c01eb112
...
...
@@ -90,7 +90,6 @@ static inline unsigned __builtin_bswap32(unsigned x) {
#endif
//int verbosity;
static
int
auth_success
;
//static enum tgl_dc_state c_state;
//extern int binlog_enabled;
//extern int disable_auto_accept;
...
...
@@ -713,7 +712,6 @@ static int process_auth_complete (struct connection *c UU, char *packet, int len
D
->
state
=
st_authorized
;
//return 1;
vlogprintf
(
E_DEBUG
,
"Auth success
\n
"
);
auth_success
++
;
if
(
temp_key
)
{
//D->flags |= 2;
...
...
@@ -1308,13 +1306,8 @@ void tglmp_on_start (void) {
pk_fingerprint
=
tgl_do_compute_rsa_key_fingerprint
(
pubKey
);
}
//int auth_ok (void) {
// return auth_success;
//}
void
tgl_dc_authorize
(
struct
tgl_dc
*
DC
)
{
//c_state = 0;
//auth_success = 0;
if
(
!
DC
->
sessions
[
0
])
{
tglmp_dc_create_session
(
DC
);
}
...
...
queries.c
View file @
c01eb112
...
...
@@ -39,7 +39,6 @@
#include "tree.h"
#include "mtproto-common.h"
//#include "telegram.h"
#include "loop.h"
#include "structures.h"
//#include "interface.h"
//#include "net.h"
...
...
structures.c
View file @
c01eb112
This diff is collapsed.
Click to expand it.
tgl.c
View file @
c01eb112
...
...
@@ -78,6 +78,9 @@ void tgl_init (void) {
tgl_state
.
temp_key_expire_time
=
100000
;
}
tgl_state
.
message_list
.
next_use
=
&
tgl_state
.
message_list
;
tgl_state
.
message_list
.
prev_use
=
&
tgl_state
.
message_list
;
tglmp_on_start
();
}
...
...
tgl.h
View file @
c01eb112
...
...
@@ -127,6 +127,7 @@ struct tgl_net_methods {
#define TGL_MAX_RSA_KEYS_NUM 10
// Do not modify this structure, unless you know what you do
struct
tgl_state
{
int
our_id
;
// ID of logged in user
int
encr_root
;
...
...
@@ -170,6 +171,24 @@ struct tgl_state {
struct
bignum_ctx
*
BN_ctx
;
struct
tgl_allocator
allocator
;
struct
tree_peer
*
peer_tree
;
struct
tree_peer_by_name
*
peer_by_name_tree
;
struct
tree_message
*
message_tree
;
struct
tree_message
*
message_unsent_tree
;
int
users_allocated
;
int
chats_allocated
;
int
messages_allocated
;
int
peer_num
;
int
peer_size
;
int
encr_chats_allocated
;
int
geo_chats_allocated
;
tgl_peer_t
**
Peers
;
struct
tgl_message
message_list
;
int
binlog_fd
;
};
extern
struct
tgl_state
tgl_state
;
...
...
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