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
6707c119
Commit
6707c119
authored
Aug 21, 2014
by
Vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
969da088
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
365 additions
and
173 deletions
+365
-173
binlog.c
binlog.c
+44
-115
binlog.tl
binlog.tl
+1
-0
interface.c
interface.c
+164
-5
loop.c
loop.c
+3
-0
lua-tg.c
lua-tg.c
+97
-29
lua-tg.h
lua-tg.h
+5
-6
main.c
main.c
+6
-2
queries.c
queries.c
+32
-11
tgl.h
tgl.h
+5
-0
updates.c
updates.c
+8
-5
No files found.
binlog.c
View file @
6707c119
This diff is collapsed.
Click to expand it.
binlog.tl
View file @
6707c119
...
...
@@ -61,6 +61,7 @@ binlog.createMessageService id:int from_id:int to_type:int to_id:int date:int ac
binlog.createMessageServiceEncr id:long from_id:int to_type:int to_id:int date:int action:DecryptedMessageAction = binlog.Update;
binlog.createMessageServiceFwd id:int from_id:int to_type:int to_id:int date:int fwd_from_id:int fwd_date:int action:MessageAction = binlog.Update;
binlog.messageSetUnread id:int = binlog.Update;
binlog.messageSetUnreadLong id:long = binlog.Update;
binlog.setMessageSent id:long = binlog.Update;
binlog.setMsgId old_id:long new_id:int = binlog.Update;
binlog.deleteMsg id:long = binlog.Update;
...
...
interface.c
View file @
6707c119
...
...
@@ -46,6 +46,10 @@
//#include "tools.h"
//#include "structures.h"
#ifdef USE_LUA
# include "lua-tg.h"
#endif
//#include "mtproto-common.h"
#include "tgl.h"
...
...
@@ -65,6 +69,7 @@ char *default_prompt = "> ";
int
msg_num_mode
;
int
alert_sound
;
extern
int
binlog_read
;
int
safe_quit
;
...
...
@@ -686,10 +691,39 @@ void interpreter_chat_mode (char *line) {
}
void
mark_read_upd
(
int
num
,
struct
tgl_message
*
list
[])
{
if
(
!
binlog_read
)
{
return
;
}
if
(
log_level
<
1
)
{
return
;
}
tgl_peer_id_t
to_id
=
list
[
0
]
->
from_id
;
int
ok
=
1
;
int
i
;
for
(
i
=
1
;
i
<
num
;
i
++
)
{
if
(
tgl_cmp_peer_id
(
to_id
,
list
[
i
]
->
to_id
))
{
ok
=
0
;
}
}
print_start
();
push_color
(
COLOR_YELLOW
);
printf
(
"%d messages mark read
\n
"
,
num
);
if
(
!
ok
)
{
printf
(
"%d messages mark read
\n
"
,
num
);
}
else
{
printf
(
"%d messages mark read in "
,
num
);
switch
(
tgl_get_peer_type
(
to_id
))
{
case
TGL_PEER_USER
:
printf
(
" user "
);
print_user_name
(
to_id
,
tgl_peer_get
(
to_id
));
break
;
case
TGL_PEER_CHAT
:
printf
(
" chat "
);
print_chat_name
(
to_id
,
tgl_peer_get
(
to_id
));
break
;
case
TGL_PEER_ENCR_CHAT
:
printf
(
" secret chat "
);
print_chat_name
(
to_id
,
tgl_peer_get
(
to_id
));
break
;
}
printf
(
"
\n
"
);
}
pop_color
();
print_end
();
}
...
...
@@ -720,11 +754,135 @@ void type_in_chat_notification_upd (struct tgl_user *U, struct tgl_chat *C) {
void
print_message_gw
(
struct
tgl_message
*
M
)
{
#ifdef USE_LUA
lua_new_msg
(
M
);
#endif
if
(
!
binlog_read
)
{
return
;
}
print_start
();
print_message
(
M
);
print_end
();
}
void
our_id_gw
(
int
id
)
{
#ifdef USE_LUA
lua_our_id
(
id
);
#endif
}
void
print_peer_updates
(
int
flags
)
{
if
(
flags
&
TGL_UPDATE_PHONE
)
{
printf
(
" phone"
);
}
if
(
flags
&
TGL_UPDATE_CONTACT
)
{
printf
(
" contact"
);
}
if
(
flags
&
TGL_UPDATE_PHOTO
)
{
printf
(
" photo"
);
}
if
(
flags
&
TGL_UPDATE_BLOCKED
)
{
printf
(
" blocked"
);
}
if
(
flags
&
TGL_UPDATE_REAL_NAME
)
{
printf
(
" name"
);
}
if
(
flags
&
TGL_UPDATE_NAME
)
{
printf
(
" contact_name"
);
}
if
(
flags
&
TGL_UPDATE_REQUESTED
)
{
printf
(
" status"
);
}
if
(
flags
&
TGL_UPDATE_WORKING
)
{
printf
(
" status"
);
}
if
(
flags
&
TGL_UPDATE_FLAGS
)
{
printf
(
" flags"
);
}
if
(
flags
&
TGL_UPDATE_TITLE
)
{
printf
(
" title"
);
}
if
(
flags
&
TGL_UPDATE_ADMIN
)
{
printf
(
" admin"
);
}
if
(
flags
&
TGL_UPDATE_MEMBERS
)
{
printf
(
" members"
);
}
if
(
flags
&
TGL_UPDATE_ACCESS_HASH
)
{
printf
(
" access_hash"
);
}
}
void
user_update_gw
(
struct
tgl_user
*
U
,
unsigned
flags
)
{
#ifdef USE_LUA
lua_user_update
(
U
,
flags
);
#endif
if
(
!
binlog_read
)
{
return
;
}
if
(
!
(
flags
&
TGL_UPDATE_CREATED
))
{
print_start
();
push_color
(
COLOR_YELLOW
);
printf
(
"User "
);
print_user_name
(
U
->
id
,
(
void
*
)
U
);
if
(
!
(
flags
&
TGL_UPDATE_DELETED
))
{
printf
(
" updated"
);
print_peer_updates
(
flags
);
}
else
{
printf
(
" deleted"
);
}
printf
(
"
\n
"
);
pop_color
();
print_end
();
}
}
void
chat_update_gw
(
struct
tgl_chat
*
U
,
unsigned
flags
)
{
#ifdef USE_LUA
lua_chat_update
(
U
,
flags
);
#endif
if
(
!
binlog_read
)
{
return
;
}
if
(
!
(
flags
&
TGL_UPDATE_CREATED
))
{
print_start
();
push_color
(
COLOR_YELLOW
);
printf
(
"Chat "
);
print_chat_name
(
U
->
id
,
(
void
*
)
U
);
if
(
!
(
flags
&
TGL_UPDATE_DELETED
))
{
printf
(
" updated"
);
print_peer_updates
(
flags
);
}
else
{
printf
(
" deleted"
);
}
printf
(
"
\n
"
);
pop_color
();
print_end
();
}
}
void
secret_chat_update_gw
(
struct
tgl_secret_chat
*
U
,
unsigned
flags
)
{
#ifdef USE_LUA
lua_secret_chat_update
(
U
,
flags
);
#endif
if
(
!
binlog_read
)
{
return
;
}
if
(
!
(
flags
&
TGL_UPDATE_CREATED
))
{
print_start
();
push_color
(
COLOR_YELLOW
);
printf
(
"Secret chat "
);
print_encr_chat_name
(
U
->
id
,
(
void
*
)
U
);
if
(
!
(
flags
&
TGL_UPDATE_DELETED
))
{
printf
(
" updated"
);
print_peer_updates
(
flags
);
}
else
{
printf
(
" deleted"
);
}
printf
(
"
\n
"
);
pop_color
();
print_end
();
}
}
struct
tgl_update_callback
upd_cb
=
{
.
new_msg
=
print_message_gw
,
.
marked_read
=
mark_read_upd
,
...
...
@@ -736,10 +894,11 @@ struct tgl_update_callback upd_cb = {
.
user_registered
=
0
,
.
user_activated
=
0
,
.
new_authorization
=
0
,
.
user_update
=
0
,
.
chat_update
=
0
,
.
secret_chat_update
=
0
,
.
msg_receive
=
print_message_gw
.
user_update
=
user_update_gw
,
.
chat_update
=
chat_update_gw
,
.
secret_chat_update
=
secret_chat_update_gw
,
.
msg_receive
=
print_message_gw
,
.
our_id
=
our_id_gw
};
...
...
loop.c
View file @
6707c119
...
...
@@ -53,6 +53,7 @@
int
verbosity
;
int
binlog_read
;
extern
char
*
default_username
;
extern
char
*
auth_token
;
void
set_default_username
(
const
char
*
s
);
...
...
@@ -238,6 +239,8 @@ int loop (void) {
tgl_replay_log
();
logprintf
(
"replay log end in %lf seconds
\n
"
,
tglt_get_double_time
()
-
t
);
tgl_reopen_binlog_for_writing
();
binlog_read
=
1
;
//exit (0);
#ifdef USE_LUA
lua_binlog_end
();
#endif
...
...
lua-tg.c
View file @
6707c119
...
...
@@ -16,10 +16,12 @@
#include <event2/event.h>
lua_State
*
luaState
;
#include "interface.h"
#include "auto/constants.h"
//
#include "interface.h"
//
#include "auto/constants.h"
#include "tgl.h"
#include "interface.h"
#include <assert.h>
extern
int
verbosity
;
static
int
have_file
;
...
...
@@ -37,6 +39,14 @@ void lua_add_string_field (const char *name, const char *value) {
lua_settable
(
luaState
,
-
3
);
}
void
lua_add_string_field_arr
(
int
num
,
const
char
*
value
)
{
if
(
!
value
||
!
strlen
(
value
))
{
return
;
}
my_lua_checkstack
(
luaState
,
3
);
lua_pushnumber
(
luaState
,
num
);
lua_pushstring
(
luaState
,
value
);
lua_settable
(
luaState
,
-
3
);
}
void
lua_add_num_field
(
const
char
*
name
,
double
value
)
{
assert
(
name
&&
strlen
(
name
));
my_lua_checkstack
(
luaState
,
3
);
...
...
@@ -68,6 +78,9 @@ void push_user (tgl_peer_t *P UU) {
lua_add_string_field
(
"real_first_name"
,
P
->
user
.
real_first_name
);
lua_add_string_field
(
"real_last_name"
,
P
->
user
.
real_last_name
);
lua_add_string_field
(
"phone"
,
P
->
user
.
phone
);
if
(
P
->
user
.
access_hash
)
{
lua_add_num_field
(
"access_hash"
,
1
);
}
}
void
push_chat
(
tgl_peer_t
*
P
)
{
...
...
@@ -84,6 +97,60 @@ void push_encr_chat (tgl_peer_t *P) {
lua_settable
(
luaState
,
-
3
);
}
void
push_update_types
(
unsigned
flags
)
{
my_lua_checkstack
(
luaState
,
4
);
lua_newtable
(
luaState
);
int
cc
=
0
;
if
(
flags
&
TGL_UPDATE_CREATED
)
{
lua_add_string_field_arr
(
cc
++
,
"created"
);
}
if
(
flags
&
TGL_UPDATE_DELETED
)
{
lua_add_string_field_arr
(
cc
++
,
"deleted"
);
}
if
(
flags
&
TGL_UPDATE_PHONE
)
{
lua_add_string_field_arr
(
cc
++
,
"phone"
);
}
if
(
flags
&
TGL_UPDATE_CONTACT
)
{
lua_add_string_field_arr
(
cc
++
,
"contact"
);
}
if
(
flags
&
TGL_UPDATE_PHOTO
)
{
lua_add_string_field_arr
(
cc
++
,
"photo"
);
}
if
(
flags
&
TGL_UPDATE_BLOCKED
)
{
lua_add_string_field_arr
(
cc
++
,
"blocked"
);
}
if
(
flags
&
TGL_UPDATE_REAL_NAME
)
{
lua_add_string_field_arr
(
cc
++
,
"real_name"
);
}
if
(
flags
&
TGL_UPDATE_NAME
)
{
lua_add_string_field_arr
(
cc
++
,
"name"
);
}
if
(
flags
&
TGL_UPDATE_REQUESTED
)
{
lua_add_string_field_arr
(
cc
++
,
"requested"
);
}
if
(
flags
&
TGL_UPDATE_WORKING
)
{
lua_add_string_field_arr
(
cc
++
,
"working"
);
}
if
(
flags
&
TGL_UPDATE_FLAGS
)
{
lua_add_string_field_arr
(
cc
++
,
"flags"
);
}
if
(
flags
&
TGL_UPDATE_TITLE
)
{
lua_add_string_field_arr
(
cc
++
,
"title"
);
}
if
(
flags
&
TGL_UPDATE_ADMIN
)
{
lua_add_string_field_arr
(
cc
++
,
"admin"
);
}
if
(
flags
&
TGL_UPDATE_MEMBERS
)
{
lua_add_string_field_arr
(
cc
++
,
"members"
);
}
if
(
flags
&
TGL_UPDATE_ACCESS_HASH
)
{
lua_add_string_field_arr
(
cc
++
,
"access_hash"
);
}
}
void
push_peer
(
tgl_peer_id_t
id
,
tgl_peer_t
*
P
)
{
lua_newtable
(
luaState
);
...
...
@@ -137,32 +204,30 @@ void push_media (struct tgl_message_media *M) {
my_lua_checkstack
(
luaState
,
4
);
switch
(
M
->
type
)
{
case
CODE
_message_media_photo
:
case
CODE_decrypted_message_media_photo
:
case
tgl
_message_media_photo
:
case
tgl_message_media_photo_encr
:
lua_pushstring
(
luaState
,
"photo"
);
break
;
case
CODE_message_media_video
:
case
CODE_decrypted_message_media_video
:
lua_pushstring
(
luaState
,
"video"
);
case
tgl_message_media_video
:
case
tgl_message_media_video_encr
:
break
;
case
CODE
_message_media_audio
:
case
CODE_decrypted_message_media_audio
:
case
tgl
_message_media_audio
:
case
tgl_message_media_audio_encr
:
lua_pushstring
(
luaState
,
"audio"
);
break
;
case
CODE
_message_media_document
:
case
CODE_decrypted_message_media_document
:
case
tgl
_message_media_document
:
case
tgl_message_media_document_encr
:
lua_pushstring
(
luaState
,
"document"
);
break
;
case
CODE
_message_media_unsupported
:
case
tgl
_message_media_unsupported
:
lua_pushstring
(
luaState
,
"unsupported"
);
break
;
case
CODE
_message_media_geo
:
case
tgl
_message_media_geo
:
lua_newtable
(
luaState
);
lua_add_num_field
(
"longitude"
,
M
->
geo
.
longitude
);
lua_add_num_field
(
"latitude"
,
M
->
geo
.
latitude
);
break
;
case
CODE_message_media_contact
:
case
CODE_decrypted_message_media_contact
:
case
tgl_message_media_contact
:
lua_newtable
(
luaState
);
lua_add_string_field
(
"phone"
,
M
->
phone
);
lua_add_string_field
(
"first_name"
,
M
->
first_name
);
...
...
@@ -222,7 +287,7 @@ void push_message (struct tgl_message *M) {
lua_pushlstring
(
luaState
,
M
->
message
,
M
->
message_len
);
lua_settable
(
luaState
,
-
3
);
}
if
(
M
->
media
.
type
&&
M
->
media
.
type
!=
CODE_message_media_empty
&&
M
->
media
.
type
!=
CODE_decrypted_message_media_empty
)
{
if
(
M
->
media
.
type
&&
M
->
media
.
type
!=
tgl_message_media_none
)
{
lua_pushstring
(
luaState
,
"media"
);
push_media
(
&
M
->
media
);
lua_settable
(
luaState
,
-
3
);
...
...
@@ -288,53 +353,56 @@ void lua_new_msg (struct tgl_message *M UU) {
}
}
void
lua_secret_chat_
created
(
struct
tgl_secret_chat
*
C
)
{
void
lua_secret_chat_
update
(
struct
tgl_secret_chat
*
C
,
unsigned
flags
)
{
if
(
!
have_file
)
{
return
;
}
lua_settop
(
luaState
,
0
);
//lua_checkstack (luaState, 20);
my_lua_checkstack
(
luaState
,
20
);
lua_getglobal
(
luaState
,
"on_secret_chat_
created
"
);
lua_getglobal
(
luaState
,
"on_secret_chat_
update
"
);
push_peer
(
C
->
id
,
(
void
*
)
C
);
assert
(
lua_gettop
(
luaState
)
==
2
);
push_update_types
(
flags
);
assert
(
lua_gettop
(
luaState
)
==
3
);
int
r
=
lua_pcall
(
luaState
,
1
,
0
,
0
);
int
r
=
lua_pcall
(
luaState
,
2
,
0
,
0
);
if
(
r
)
{
logprintf
(
"lua: %s
\n
"
,
lua_tostring
(
luaState
,
-
1
));
}
}
void
lua_user_update
(
struct
tgl_user
*
U
)
{
void
lua_user_update
(
struct
tgl_user
*
U
,
unsigned
flags
)
{
if
(
!
have_file
)
{
return
;
}
lua_settop
(
luaState
,
0
);
//lua_checkstack (luaState, 20);
my_lua_checkstack
(
luaState
,
20
);
lua_getglobal
(
luaState
,
"on_user_update"
);
push_peer
(
U
->
id
,
(
void
*
)
U
);
assert
(
lua_gettop
(
luaState
)
==
2
);
push_update_types
(
flags
);
assert
(
lua_gettop
(
luaState
)
==
3
);
int
r
=
lua_pcall
(
luaState
,
1
,
0
,
0
);
int
r
=
lua_pcall
(
luaState
,
2
,
0
,
0
);
if
(
r
)
{
logprintf
(
"lua: %s
\n
"
,
lua_tostring
(
luaState
,
-
1
));
}
}
void
lua_chat_update
(
struct
tgl_chat
*
C
)
{
void
lua_chat_update
(
struct
tgl_chat
*
C
,
unsigned
flags
)
{
if
(
!
have_file
)
{
return
;
}
lua_settop
(
luaState
,
0
);
//lua_checkstack (luaState, 20);
my_lua_checkstack
(
luaState
,
20
);
lua_getglobal
(
luaState
,
"on_chat_update"
);
push_peer
(
C
->
id
,
(
void
*
)
C
);
assert
(
lua_gettop
(
luaState
)
==
2
);
push_update_types
(
flags
);
assert
(
lua_gettop
(
luaState
)
==
3
);
int
r
=
lua_pcall
(
luaState
,
1
,
0
,
0
);
int
r
=
lua_pcall
(
luaState
,
2
,
0
,
0
);
if
(
r
)
{
logprintf
(
"lua: %s
\n
"
,
lua_tostring
(
luaState
,
-
1
));
}
}
extern
tgl_peer_t
*
Peers
[];
extern
int
peer_num
;
//
extern tgl_peer_t *Peers[];
//
extern int peer_num;
#define MAX_LUA_COMMANDS 1000
void
*
lua_ptr
[
MAX_LUA_COMMANDS
];
...
...
@@ -511,7 +579,7 @@ static int postpone_from_lua (lua_State *L) {
t
[
1
]
=
a2
;
*
(
void
**
)(
t
+
2
)
=
ev
;
struct
timeval
ts
=
{
timeout
,
0
};
struct
timeval
ts
=
{
timeout
,
0
};
event_add
(
ev
,
&
ts
);
lua_pushboolean
(
L
,
1
);
...
...
lua-tg.h
View file @
6707c119
...
...
@@ -2,17 +2,16 @@
#define __LUA_TG_H__
#include <string.h>
#include "structures.h"
#include "lua-tg.h"
#include "tgl.h"
void
lua_init
(
const
char
*
file
);
void
lua_new_msg
(
struct
tgl_message
*
M
);
void
lua_our_id
(
int
id
);
void
lua_secret_chat_
created
(
struct
tgl_secret_chat
*
U
);
void
lua_user_update
(
struct
tgl_user
*
U
);
void
lua_chat_update
(
struct
tgl_chat
*
C
);
void
lua_secret_chat_
update
(
struct
tgl_secret_chat
*
U
,
unsigned
flags
);
void
lua_user_update
(
struct
tgl_user
*
U
,
unsigned
flags
);
void
lua_chat_update
(
struct
tgl_chat
*
C
,
unsigned
flags
);
void
lua_binlog_end
(
void
);
void
lua_diff_end
(
void
);
void
lua_do_all
(
void
);
#define lua_secret_chat_update(x)
#define lua_update_msg(x)
#endif
main.c
View file @
6707c119
...
...
@@ -91,6 +91,7 @@ int binlog_enabled;
extern
int
log_level
;
int
sync_from_start
;
int
allow_weak_random
;
char
*
lua_file
;
void
set_default_username
(
const
char
*
s
)
{
if
(
default_username
)
{
...
...
@@ -271,7 +272,7 @@ void parse_config_val (config_t *conf, char **s, char *param_name, const char *d
if
(
path
)
{
tasprintf
(
s
,
"%s/%s"
,
path
,
default_name
);
}
else
{
*
s
=
tstrdup
(
default_name
)
;
*
s
=
default_name
?
tstrdup
(
default_name
)
:
0
;
}
}
}
...
...
@@ -322,6 +323,10 @@ void parse_config (void) {
parse_config_val
(
&
conf
,
&
downloads_directory
,
"downloads"
,
DOWNLOADS_DIRECTORY
,
config_directory
);
parse_config_val
(
&
conf
,
&
binlog_file_name
,
"binlog"
,
BINLOG_FILE
,
config_directory
);
if
(
!
lua_file
)
{
parse_config_val
(
&
conf
,
&
lua_file
,
"lua_script"
,
0
,
config_directory
);
}
strcpy
(
buf
+
l
,
"binlog_enabled"
);
config_lookup_bool
(
&
conf
,
buf
,
&
binlog_enabled
);
...
...
@@ -396,7 +401,6 @@ int register_mode;
int
disable_auto_accept
;
int
wait_dialog_list
;
char
*
lua_file
;
void
args_parse
(
int
argc
,
char
**
argv
)
{
int
opt
=
0
;
...
...
queries.c
View file @
6707c119
...
...
@@ -757,12 +757,13 @@ void tgl_do_send_encr_chat_layer (struct tgl_secret_chat *E) {
long
long
t
;
tglt_secure_random
(
&
t
,
8
);
int
action
[
2
];
action
[
0
]
=
tgl
_message_action_notify_layer
;
action
[
0
]
=
CODE_decrypted
_message_action_notify_layer
;
action
[
1
]
=
15
;
bl_do_send_message_action_encr
(
t
,
tgl_state
.
our_id
,
tgl_get_peer_type
(
E
->
id
),
tgl_get_peer_id
(
E
->
id
),
time
(
0
),
2
,
action
);
struct
tgl_message
*
M
=
tgl_message_get
(
t
);
assert
(
M
);
assert
(
M
->
action
.
type
==
tgl_message_action_notify_layer
);
tgl_do_send_msg
(
M
,
0
,
0
);
//print_message (M);
}
...
...
@@ -788,12 +789,14 @@ static int msg_send_on_answer (struct query *q UU) {
int
id
=
fetch_int
();
// id
struct
tgl_message
*
M
=
q
->
extra
;
bl_do_set_msg_id
(
M
,
id
);
tglu_fetch_date
();
tglu_fetch_pts
();
int
date
=
fetch_int
();
int
pts
=
fetch_int
();
//tglu_fetch_seq ();
//bl_do_
int
seq
=
fetch_int
();
if
(
seq
==
tgl_state
.
seq
+
1
)
{
bl_do_set_date
(
date
);
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
id
);
}
else
{
tgl_do_get_difference
(
0
,
0
,
0
);
...
...
@@ -1012,7 +1015,8 @@ void tgl_do_send_text (tgl_peer_id_t id, char *file_name, void (*callback)(void
/* {{{ Mark read */
static
int
mark_read_on_receive
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
(
int
)
CODE_messages_affected_history
);
tglu_fetch_pts
();
//tglu_fetch_pts ();
fetch_int
();
//tglu_fetch_seq ();
fetch_int
();
// seq
fetch_int
();
// offset
...
...
@@ -1150,7 +1154,7 @@ void tgl_do_get_local_history (tgl_peer_id_t id, int limit, void (*callback)(voi
count
=
1
;
while
(
count
<
limit
&&
M
->
next
)
{
M
=
M
->
next
;
ML
[
count
++
]
=
M
->
next
;
ML
[
count
++
]
=
M
;
}
callback
(
callback_extra
,
1
,
count
,
ML
);
...
...
@@ -1324,11 +1328,13 @@ static int send_file_on_answer (struct query *q UU) {
for
(
i
=
0
;
i
<
n
;
i
++
)
{
tglf_fetch_alloc_user
();
}
tglu_fetch_pts
();
//tglu_fetch_pts ();
int
pts
=
fetch_int
();
//tglu_fetch_seq ();
int
seq
=
fetch_int
();
if
(
seq
==
tgl_state
.
seq
+
1
)
{
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
M
->
id
);
}
else
{
tgl_do_get_difference
(
0
,
0
,
0
);
...
...
@@ -1670,10 +1676,12 @@ static int fwd_msg_on_answer (struct query *q UU) {
for
(
i
=
0
;
i
<
n
;
i
++
)
{
tglf_fetch_alloc_user
();
}
tglu_fetch_pts
();
//tglu_fetch_pts ();
int
pts
=
fetch_int
();
int
seq
=
fetch_int
();
if
(
seq
==
tgl_state
.
seq
+
1
)
{
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
M
->
id
);
}
else
{
tgl_do_get_difference
(
0
,
0
,
0
);
...
...
@@ -1720,9 +1728,12 @@ static int rename_chat_on_answer (struct query *q UU) {
for
(
i
=
0
;
i
<
n
;
i
++
)
{
tglf_fetch_alloc_user
();
}
tglu_fetch_pts
();
//tglu_fetch_pts ();
int
pts
=
fetch_int
();
int
seq
=
fetch_int
();
if
(
seq
==
tgl_state
.
seq
+
1
)
{
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
M
->
id
);
}
else
{
tgl_do_get_difference
(
0
,
0
,
0
);
...
...
@@ -2715,6 +2726,9 @@ static int get_state_on_answer (struct query *q UU) {
//int get_difference_active;
static
int
get_difference_on_answer
(
struct
query
*
q
UU
)
{
//get_difference_active = 0;
assert
(
tgl_state
.
locks
&
TGL_LOCK_DIFF
);
tgl_state
.
locks
^=
TGL_LOCK_DIFF
;
unsigned
x
=
fetch_int
();
if
(
x
==
CODE_updates_difference_empty
)
{
bl_do_set_date
(
fetch_int
());
...
...
@@ -2778,9 +2792,9 @@ static int get_difference_on_answer (struct query *q UU) {
tfree
(
EL
,
el_pos
*
sizeof
(
void
*
));
if
(
x
==
CODE_updates_difference_slice
)
{
if
(
q
->
callback
)
{
((
void
(
*
)(
void
*
,
int
))
q
->
callback
)
(
q
->
callback_extra
,
1
);
}
//
if (q->callback) {
//
((void (*)(void *, int))q->callback) (q->callback_extra, 1);
//
}
tgl_do_get_difference
(
0
,
q
->
callback
,
q
->
callback_extra
);
}
else
{
//difference_got = 1;
...
...
@@ -2807,6 +2821,13 @@ static struct query_methods get_difference_methods = {
void
tgl_do_get_difference
(
int
sync_from_start
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
),
void
*
callback_extra
)
{
//get_difference_active = 1;
//difference_got = 0;
if
(
tgl_state
.
locks
&
TGL_LOCK_DIFF
)
{
if
(
callback
)
{
callback
(
callback_extra
,
0
);
}
return
;
}
tgl_state
.
locks
|=
TGL_LOCK_DIFF
;
clear_packet
();
tgl_do_insert_header
();
if
(
tgl_state
.
seq
>
0
||
sync_from_start
)
{
...
...
tgl.h
View file @
6707c119
...
...
@@ -29,6 +29,7 @@ struct dc;
#define TGL_UPDATE_TITLE 2048
#define TGL_UPDATE_ADMIN 4096
#define TGL_UPDATE_MEMBERS 8192
#define TGL_UPDATE_ACCESS_HASH 16384
struct
tgl_update_callback
{
void
(
*
new_msg
)(
struct
tgl_message
*
M
);
...
...
@@ -57,6 +58,7 @@ struct tgl_update_callback {
void
(
*
user_update
)(
struct
tgl_user
*
C
,
unsigned
flags
);
void
(
*
secret_chat_update
)(
struct
tgl_secret_chat
*
C
,
unsigned
flags
);
void
(
*
msg_receive
)(
struct
tgl_message
*
M
);
void
(
*
our_id
)(
int
id
);
};
struct
tgl_net_methods
{
...
...
@@ -77,6 +79,8 @@ struct tgl_net_methods {
#define E_NOTICE 2
#define E_DEBUG 3
#define TGL_LOCK_DIFF 1
struct
tgl_state
{
int
our_id
;
// ID of logged in user
int
encr_root
;
...
...
@@ -91,6 +95,7 @@ struct tgl_state {
int
verbosity
;
int
unread_messages
;
long
long
locks
;
struct
dc
*
DC_list
[
TGL_MAX_DC_NUM
];
struct
dc
*
DC_working
;
int
max_dc_num
;
...
...
updates.c
View file @
6707c119
...
...
@@ -10,7 +10,7 @@
void
tglu_fetch_pts
(
void
)
{
int
p
=
fetch_int
();
if
(
p
<=
tgl_state
.
pts
)
{
return
;
}
if
(
p
!=
tgl_state
.
pts
+
1
)
{
/*
if (p != tgl_state.pts + 1) {
if (tgl_state.pts) {
//vlogprintf (E_NOTICE, "Hole in pts p = %d, pts = %d\n", p, tgl_state.pts);
...
...
@@ -21,14 +21,14 @@ void tglu_fetch_pts (void) {
}
} else {
tgl_state.pts ++;
}
}
*/
bl_do_set_pts
(
tgl_state
.
pts
);
}
void
tglu_fetch_qts
(
void
)
{
int
p
=
fetch_int
();
if
(
p
<=
tgl_state
.
qts
)
{
return
;
}
if
(
p
!=
tgl_state
.
qts
+
1
)
{
/*
if (p != tgl_state.qts + 1) {
if (tgl_state.qts) {
//logprintf ("Hole in qts\n");
// get difference should be here
...
...
@@ -38,14 +38,14 @@ void tglu_fetch_qts (void) {
}
} else {
tgl_state.qts ++;
}
}
*/
bl_do_set_qts
(
tgl_state
.
qts
);
}
void
tglu_fetch_date
(
void
)
{
int
p
=
fetch_int
();
if
(
p
>
tgl_state
.
date
)
{
tgl_state
.
date
=
p
;
//
tgl_state.date = p;
bl_do_set_date
(
tgl_state
.
date
);
}
}
...
...
@@ -669,6 +669,9 @@ static int do_skip_seq (int seq) {
tgl_do_get_difference
(
0
,
0
,
0
);
return
-
1
;
}
if
(
tgl_state
.
locks
&
TGL_LOCK_DIFF
)
{
return
-
1
;
}
return
0
;
}
else
{
return
-
1
;
...
...
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