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
ff97f2a4
Commit
ff97f2a4
authored
Sep 18, 2014
by
vvaltman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewitten input parse
parent
1789aa3c
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1038 additions
and
820 deletions
+1038
-820
CHANGELOG
CHANGELOG
+3
-0
interface.c
interface.c
+935
-796
mtproto-client.c
mtproto-client.c
+1
-1
queries.c
queries.c
+96
-22
structures.c
structures.c
+1
-1
tgl.h
tgl.h
+2
-0
No files found.
CHANGELOG
View file @
ff97f2a4
1.0.4
* changed create_group_chat format
* rewritten interface code. Support for escaped characters in quotes
1.0.3
* options to help to run telegram-cli as daemon
1.0.2
...
...
interface.c
View file @
ff97f2a4
This diff is collapsed.
Click to expand it.
mtproto-client.c
View file @
ff97f2a4
...
...
@@ -659,7 +659,7 @@ static long long msg_id_override;
static
void
mpc_on_get_config
(
void
*
extra
,
int
success
);
static
int
process_auth_complete
(
struct
connection
*
c
UU
,
char
*
packet
,
int
len
,
int
temp_key
)
{
struct
tgl_dc
*
D
=
tgl_state
.
net_methods
->
get_dc
(
c
);
vlogprintf
(
E_DEBUG
,
"process_dh_answer(), len=%d
\n
"
,
len
);
vlogprintf
(
E_DEBUG
-
1
,
"process_dh_answer(), len=%d
\n
"
,
len
);
assert
(
len
==
72
);
assert
(
!*
(
long
long
*
)
packet
);
assert
(
*
(
int
*
)
(
packet
+
16
)
==
len
-
20
);
...
...
queries.c
View file @
ff97f2a4
...
...
@@ -1160,7 +1160,7 @@ void tgl_do_messages_mark_read_encr (tgl_peer_id_t id, long long access_hash, in
void
tgl_do_mark_read
(
tgl_peer_id_t
id
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
),
void
*
callback_extra
)
{
if
(
tgl_get_peer_type
(
id
)
==
TGL_PEER_USER
||
tgl_get_peer_type
(
id
)
==
TGL_PEER_CHAT
)
{
tgl_do_messages_mark_read
(
id
,
tgl_state
.
max_msg_id
,
0
,
callback
,
callback_extra
);
tgl_do_messages_mark_read
(
id
,
0
,
0
,
callback
,
callback_extra
);
return
;
}
tgl_peer_t
*
P
=
tgl_peer_get
(
id
);
...
...
@@ -1260,7 +1260,9 @@ static struct query_methods get_history_methods = {
void
tgl_do_get_local_history
(
tgl_peer_id_t
id
,
int
limit
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
int
size
,
struct
tgl_message
*
list
[]),
void
*
callback_extra
)
{
tgl_peer_t
*
P
=
tgl_peer_get
(
id
);
if
(
!
P
||
!
P
->
last
)
{
callback
(
callback_extra
,
0
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
,
0
);
}
return
;
}
struct
tgl_message
*
M
=
P
->
last
;
...
...
@@ -1279,14 +1281,18 @@ void tgl_do_get_local_history (tgl_peer_id_t id, int limit, void (*callback)(voi
ML
[
count
++
]
=
M
;
}
callback
(
callback_extra
,
1
,
count
,
ML
);
if
(
callback
)
{
callback
(
callback_extra
,
1
,
count
,
ML
);
}
tfree
(
ML
,
sizeof
(
void
*
)
*
count
);
}
void
tgl_do_get_local_history_ext
(
tgl_peer_id_t
id
,
int
offset
,
int
limit
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
int
size
,
struct
tgl_message
*
list
[]),
void
*
callback_extra
)
{
tgl_peer_t
*
P
=
tgl_peer_get
(
id
);
if
(
!
P
||
!
P
->
last
)
{
callback
(
callback_extra
,
0
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
,
0
);
}
return
;
}
struct
tgl_message
*
M
=
P
->
last
;
...
...
@@ -1297,7 +1303,9 @@ void tgl_do_get_local_history_ext (tgl_peer_id_t id, int offset, int limit, void
count
++
;
}
if
(
count
<=
offset
)
{
callback
(
callback_extra
,
1
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
1
,
0
,
0
);
}
return
;
}
struct
tgl_message
**
ML
=
talloc
(
sizeof
(
void
*
)
*
(
count
-
offset
));
...
...
@@ -1312,7 +1320,9 @@ void tgl_do_get_local_history_ext (tgl_peer_id_t id, int offset, int limit, void
count
++
;
}
callback
(
callback_extra
,
1
,
count
-
offset
,
ML
);
if
(
callback
)
{
callback
(
callback_extra
,
1
,
count
-
offset
,
ML
);
}
tfree
(
ML
,
sizeof
(
void
*
)
*
(
count
)
-
offset
);
}
...
...
@@ -1835,7 +1845,9 @@ void _tgl_do_send_photo (enum tgl_message_media_type type, tgl_peer_id_t to_id,
int
fd
=
open
(
file_name
,
O_RDONLY
);
if
(
fd
<
0
)
{
vlogprintf
(
E_WARNING
,
"No such file '%s'
\n
"
,
file_name
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
struct
stat
buf
;
...
...
@@ -1844,7 +1856,9 @@ void _tgl_do_send_photo (enum tgl_message_media_type type, tgl_peer_id_t to_id,
if
(
size
<=
0
)
{
vlogprintf
(
E_WARNING
,
"File has zero length
\n
"
);
close
(
fd
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
struct
send_file
*
f
=
talloc0
(
sizeof
(
*
f
));
...
...
@@ -1863,7 +1877,9 @@ void _tgl_do_send_photo (enum tgl_message_media_type type, tgl_peer_id_t to_id,
close
(
fd
);
vlogprintf
(
E_WARNING
,
"Too big file. Maximal supported size is %d.
\n
"
,
(
512
<<
10
)
*
1000
);
tfree
(
f
,
sizeof
(
*
f
));
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
...
...
@@ -1886,7 +1902,9 @@ void _tgl_do_send_photo (enum tgl_message_media_type type, tgl_peer_id_t to_id,
close
(
fd
);
vlogprintf
(
E_WARNING
,
"Unknown type %d.
\n
"
,
type
);
tfree
(
f
,
sizeof
(
*
f
));
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
f
->
file_name
=
tstrdup
(
file_name
);
...
...
@@ -1968,7 +1986,9 @@ static struct query_methods fwd_msg_methods = {
void
tgl_do_forward_message
(
tgl_peer_id_t
id
,
int
n
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
)
{
if
(
tgl_get_peer_type
(
id
)
==
TGL_PEER_ENCR_CHAT
)
{
vlogprintf
(
E_WARNING
,
"Can not forward messages from secret chat
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
clear_packet
();
...
...
@@ -2007,23 +2027,31 @@ void tgl_do_send_contact (tgl_peer_id_t id, const char *phone, int phone_len, co
void
tgl_do_forward_media
(
tgl_peer_id_t
id
,
int
n
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
)
{
if
(
tgl_get_peer_type
(
id
)
==
TGL_PEER_ENCR_CHAT
)
{
vlogprintf
(
E_WARNING
,
"Can not forward messages from secret chat
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
struct
tgl_message
*
M
=
tgl_message_get
(
n
);
if
(
!
M
)
{
vlogprintf
(
E_WARNING
,
"No such message
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
if
(
M
->
flags
&
FLAG_ENCRYPTED
)
{
vlogprintf
(
E_WARNING
,
"Can not forward media from encrypted message
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
if
(
M
->
media
.
type
!=
tgl_message_media_photo
&&
M
->
media
.
type
!=
tgl_message_media_video
&&
M
->
media
.
type
!=
tgl_message_media_audio
&&
M
->
media
.
type
!=
tgl_message_media_document
)
{
vlogprintf
(
E_WARNING
,
"Can only forward photo/audio/video/document
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
clear_packet
();
...
...
@@ -2159,10 +2187,14 @@ void tgl_do_get_chat_info (tgl_peer_id_t id, int offline_mode, void (*callback)(
tgl_peer_t
*
C
=
tgl_peer_get
(
id
);
if
(
!
C
)
{
vlogprintf
(
E_WARNING
,
"No such chat
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
}
else
{
//print_chat_info (&C->chat);
callback
(
callback_extra
,
1
,
&
C
->
chat
);
if
(
callback
)
{
callback
(
callback_extra
,
1
,
&
C
->
chat
);
}
}
return
;
}
...
...
@@ -2214,9 +2246,13 @@ void tgl_do_get_user_info (tgl_peer_id_t id, int offline_mode, void (*callback)(
tgl_peer_t
*
C
=
tgl_peer_get
(
id
);
if
(
!
C
)
{
vlogprintf
(
E_WARNING
,
"No such user
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
}
else
{
callback
(
callback_extra
,
1
,
&
C
->
user
);
if
(
callback
)
{
callback
(
callback_extra
,
1
,
&
C
->
user
);
}
}
return
;
}
...
...
@@ -2415,7 +2451,9 @@ static void load_next_part (struct download *D, void *callback, void *callback_e
void
tgl_do_load_photo_size
(
struct
tgl_photo_size
*
P
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
char
*
filename
),
void
*
callback_extra
)
{
if
(
!
P
->
loc
.
dc
)
{
vlogprintf
(
E_WARNING
,
"Bad video thumb
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
...
...
@@ -2436,7 +2474,9 @@ void tgl_do_load_photo_size (struct tgl_photo_size *P, void (*callback)(void *ca
void
tgl_do_load_photo
(
struct
tgl_photo
*
photo
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
char
*
filename
),
void
*
callback_extra
)
{
if
(
!
photo
->
sizes_num
)
{
vlogprintf
(
E_WARNING
,
"No sizes
\n
"
);
callback
(
callback_extra
,
0
,
0
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
int
max
=
-
1
;
...
...
@@ -2841,7 +2881,9 @@ void tgl_do_send_accept_encr_chat (struct tgl_secret_chat *E, unsigned char *ran
}
}
if
(
ok
)
{
callback
(
callback_extra
,
1
,
E
);
if
(
callback
)
{
callback
(
callback_extra
,
1
,
E
);
}
return
;
}
// Already generated key for this chat
unsigned
char
random_here
[
256
];
...
...
@@ -3378,6 +3420,9 @@ void tgl_do_create_group_chat (tgl_peer_id_t id, char *chat_topic, void (*callba
tgl_peer_t
*
U
=
tgl_peer_get
(
id
);
if
(
!
U
)
{
vlogprintf
(
E_WARNING
,
"Can not create chat with unknown user
\n
"
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
clear_packet
();
...
...
@@ -3395,6 +3440,35 @@ void tgl_do_create_group_chat (tgl_peer_id_t id, char *chat_topic, void (*callba
out_string
(
chat_topic
);
tglq_send_query
(
tgl_state
.
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
create_group_chat_methods
,
0
,
callback
,
callback_extra
);
}
void
tgl_do_create_group_chat_ex
(
int
users_num
,
tgl_peer_id_t
ids
[],
char
*
chat_topic
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
)
{
clear_packet
();
out_int
(
CODE_messages_create_chat
);
out_int
(
CODE_vector
);
out_int
(
users_num
);
// Number of users, currently we support only 1 user.
int
i
;
for
(
i
=
0
;
i
<
users_num
;
i
++
)
{
tgl_peer_id_t
id
=
ids
[
i
];
tgl_peer_t
*
U
=
tgl_peer_get
(
id
);
if
(
!
U
||
tgl_get_peer_type
(
id
)
!=
TGL_PEER_USER
)
{
vlogprintf
(
E_WARNING
,
"Can not create chat with unknown user
\n
"
);
if
(
callback
)
{
callback
(
callback_extra
,
0
,
0
);
}
return
;
}
if
(
U
&&
U
->
user
.
access_hash
)
{
out_int
(
CODE_input_user_foreign
);
out_int
(
tgl_get_peer_id
(
id
));
out_long
(
U
->
user
.
access_hash
);
}
else
{
out_int
(
CODE_input_user_contact
);
out_int
(
tgl_get_peer_id
(
id
));
}
}
out_string
(
chat_topic
);
tglq_send_query
(
tgl_state
.
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
create_group_chat_methods
,
0
,
callback
,
callback_extra
);
}
/* }}} */
/* {{{ Delete msg */
...
...
structures.c
View file @
ff97f2a4
...
...
@@ -87,7 +87,7 @@ char *tgls_default_create_print_name (tgl_peer_id_t id, const char *a1, const ch
}
char
*
s
=
buf
;
while
(
*
s
)
{
if
(
*
s
=
=
' '
)
{
*
s
=
'_'
;
}
if
(
((
unsigned
char
)
*
s
)
<
=
' '
)
{
*
s
=
'_'
;
}
if
(
*
s
==
'#'
)
{
*
s
=
'@'
;
}
s
++
;
}
...
...
tgl.h
View file @
ff97f2a4
...
...
@@ -249,6 +249,7 @@ void tgl_do_send_msg (struct tgl_message *M, void (*callback)(void *callback_ext
void
tgl_do_send_text
(
tgl_peer_id_t
id
,
char
*
file
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_mark_read
(
tgl_peer_id_t
id
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
),
void
*
callback_extra
);
void
tgl_do_get_history
(
tgl_peer_id_t
id
,
int
limit
,
int
offline_mode
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
int
size
,
struct
tgl_message
*
list
[]),
void
*
callback_extra
);
void
tgl_do_get_history_ext
(
tgl_peer_id_t
id
,
int
offset
,
int
limit
,
int
offline_mode
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
int
size
,
struct
tgl_message
*
list
[]),
void
*
callback_extra
);
void
tgl_do_get_dialog_list
(
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
int
size
,
tgl_peer_id_t
peers
[],
int
last_msg_id
[],
int
unread_count
[]),
void
*
callback_extra
);
void
tgl_do_send_photo
(
enum
tgl_message_media_type
type
,
tgl_peer_id_t
to_id
,
char
*
file_name
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_set_chat_photo
(
tgl_peer_id_t
chat_id
,
char
*
file_name
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
...
...
@@ -275,6 +276,7 @@ void tgl_do_get_difference (int sync_from_start, void (*callback)(void *callback
void
tgl_do_add_user_to_chat
(
tgl_peer_id_t
chat_id
,
tgl_peer_id_t
id
,
int
limit
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_del_user_from_chat
(
tgl_peer_id_t
chat_id
,
tgl_peer_id_t
id
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_create_group_chat
(
tgl_peer_id_t
id
,
char
*
chat_topic
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_create_group_chat_ex
(
int
users_num
,
tgl_peer_id_t
ids
[],
char
*
chat_topic
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
,
struct
tgl_message
*
M
),
void
*
callback_extra
);
void
tgl_do_delete_msg
(
long
long
id
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
),
void
*
callback_extra
);
void
tgl_do_restore_msg
(
long
long
id
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
),
void
*
callback_extra
);
void
tgl_do_update_status
(
int
online
,
void
(
*
callback
)(
void
*
callback_extra
,
int
success
),
void
*
callback_extra
);
...
...
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