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
fe08f0c5
Commit
fe08f0c5
authored
Aug 14, 2014
by
vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more code
parent
bf86f756
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
833 additions
and
762 deletions
+833
-762
binlog.c
binlog.c
+4
-8
interface.h
interface.h
+0
-5
loop.c
loop.c
+2
-2
main.c
main.c
+21
-8
mtproto-client.c
mtproto-client.c
+63
-95
mtproto-common.c
mtproto-common.c
+4
-9
mtproto-common.h
mtproto-common.h
+8
-12
net.h
net.h
+0
-3
queries.c
queries.c
+626
-568
queries.h
queries.h
+6
-4
structures.c
structures.c
+2
-2
tgl.c
tgl.c
+16
-0
tgl.h
tgl.h
+81
-46
No files found.
binlog.c
View file @
fe08f0c5
...
...
@@ -1126,9 +1126,7 @@ static void replay_log_event (void) {
assert
(
rptr
<
wptr
);
int
op
=
*
rptr
;
if
(
verbosity
>=
2
)
{
logprintf
(
"log_pos %lld, op 0x%08x
\n
"
,
binlog_pos
,
op
);
}
vlogprintf
(
E_DEBUG
,
"replay_log_event: log_pos=%lld, op=0x%08x
\n
"
,
binlog_pos
,
op
);
in_ptr
=
rptr
;
in_end
=
wptr
;
...
...
@@ -1201,7 +1199,7 @@ static void replay_log_event (void) {
FETCH_COMBINATOR_FUNCTION
(
binlog_set_msg_id
)
FETCH_COMBINATOR_FUNCTION
(
binlog_delete_msg
)
default:
logprintf
(
"Unknown op 0x%08x
\n
"
,
op
);
vlogprintf
(
E_ERROR
,
"Unknown op 0x%08x
\n
"
,
op
);
assert
(
0
);
}
assert
(
ok
>=
0
);
...
...
@@ -1287,9 +1285,7 @@ void tgl_reopen_binlog_for_writing (void) {
}
static
void
add_log_event
(
const
int
*
data
,
int
len
)
{
if
(
verbosity
)
{
logprintf
(
"Add log event: magic = 0x%08x, len = %d
\n
"
,
data
[
0
],
len
);
}
vlogprintf
(
E_DEBUG
,
"Add log event: magic = 0x%08x, len = %d
\n
"
,
data
[
0
],
len
);
assert
(
!
(
len
&
3
));
rptr
=
(
void
*
)
data
;
wptr
=
rptr
+
(
len
/
4
);
...
...
@@ -1297,7 +1293,7 @@ static void add_log_event (const int *data, int len) {
int
*
end
=
in_end
;
replay_log_event
();
if
(
rptr
!=
wptr
)
{
logprintf
(
"Unread %lld ints. Len = %d
\n
"
,
(
long
long
)(
wptr
-
rptr
),
len
);
vlogprintf
(
E_ERROR
,
"Unread %lld ints. Len = %d
\n
"
,
(
long
long
)(
wptr
-
rptr
),
len
);
assert
(
rptr
==
wptr
);
}
if
(
tgl_state
.
binlog_enabled
)
{
...
...
interface.h
View file @
fe08f0c5
...
...
@@ -34,11 +34,6 @@
#define COLOR_INVERSE "\033[7m"
#define E_ERROR 0
#define E_WARNING 1
#define E_NOTICE 2
#define E_DEBUG 3
char
*
get_default_prompt
(
void
);
char
*
complete_none
(
const
char
*
text
,
int
state
);
char
**
complete_text
(
char
*
text
,
int
start
,
int
end
);
...
...
loop.c
View file @
fe08f0c5
...
...
@@ -155,7 +155,7 @@ char *get_state_filename (void);
char
*
get_secret_chat_filename
(
void
);
int
zero
[
512
];
/*
void write_dc (int auth_file_fd, struct dc *DC) {
assert (write (auth_file_fd, &DC->port, 4) == 4);
int l = strlen (DC->ip);
...
...
@@ -436,7 +436,7 @@ void write_secret_chat_file (void) {
assert (write (fd, encr_prime, 256) == 256);
}
close (fd);
}
}
*/
extern
int
max_chat_size
;
int
mcs
(
void
)
{
...
...
main.c
View file @
fe08f0c5
...
...
@@ -49,7 +49,6 @@
#include "telegram.h"
#include "loop.h"
#include "mtproto-client.h"
#include "interface.h"
#include "tools.h"
...
...
@@ -59,8 +58,8 @@
#include "tgl.h"
#define PROGNAME "telegram-cli
ent
"
#define VERSION "0.0
1
"
#define PROGNAME "telegram-cli"
#define VERSION "0.0
7
"
#define CONFIG_DIRECTORY "." PROG_NAME
#define CONFIG_FILE "config"
...
...
@@ -319,13 +318,20 @@ void parse_config (void) {
config_directory
=
make_full_path
(
config_directory
);
parse_config_val
(
&
conf
,
&
auth_file_name
,
"auth_file"
,
AUTH_KEY_FILE
,
config_directory
);
parse_config_val
(
&
conf
,
&
state_file_name
,
"state_file"
,
STATE_FILE
,
config_directory
);
parse_config_val
(
&
conf
,
&
secret_chat_file_name
,
"secret"
,
SECRET_CHAT_FILE
,
config_directory
);
parse_config_val
(
&
conf
,
&
downloads_directory
,
"downloads"
,
DOWNLOADS_DIRECTORY
,
config_directory
);
parse_config_val
(
&
conf
,
&
binlog_file_name
,
"binlog"
,
BINLOG_FILE
,
config_directory
);
strcpy
(
buf
+
l
,
"binlog_enabled"
);
config_lookup_bool
(
&
conf
,
buf
,
&
binlog_enabled
);
if
(
binlog_enabled
)
{
tgl_set_binlog_mode
(
1
);
tgl_set_binlog_path
(
binlog_file_name
);
}
else
{
tgl_set_binlog_mode
(
0
);
tgl_set_auth_file_path
(
auth_file_name
);
}
tgl_set_download_directory
(
downloads_directory
);
if
(
!
mkdir
(
config_directory
,
CONFIG_DIRECTORY_MODE
))
{
printf
(
"[%s] created
\n
"
,
config_directory
);
...
...
@@ -338,10 +344,17 @@ void parse_config (void) {
void
parse_config
(
void
)
{
printf
(
"libconfig not enabled
\n
"
);
tasprintf
(
&
auth_file_name
,
"%s/%s/%s"
,
get_home_directory
(),
CONFIG_DIRECTORY
,
AUTH_KEY_FILE
);
tasprintf
(
&
state_file_name
,
"%s/%s/%s"
,
get_home_directory
(),
CONFIG_DIRECTORY
,
STATE_FILE
);
tasprintf
(
&
secret_chat_file_name
,
"%s/%s/%s"
,
get_home_directory
(),
CONFIG_DIRECTORY
,
SECRET_CHAT_FILE
);
tasprintf
(
&
downloads_directory
,
"%s/%s/%s"
,
get_home_directory
(),
CONFIG_DIRECTORY
,
DOWNLOADS_DIRECTORY
);
tasprintf
(
&
binlog_file_name
,
"%s/%s/%s"
,
get_home_directory
(),
CONFIG_DIRECTORY
,
BINLOG_FILE
);
if
(
binlog_enabled
)
{
tgl_set_binlog_mode
(
1
);
tgl_set_binlog_path
(
binlog_file_name
);
}
else
{
tgl_set_binlog_mode
(
0
);
tgl_set_auth_file_path
(
auth_file_name
;
}
tgl_set_download_directory
(
downloads_directory
);
}
#endif
...
...
@@ -488,7 +501,7 @@ int main (int argc, char **argv) {
args_parse
(
argc
,
argv
);
printf
(
"Telegram-client version "
TG_VERSION
", Copyright (C) 2013 Vitaly Valtman
\n
"
"Telegram-client version "
TG
L
_VERSION
", Copyright (C) 2013 Vitaly Valtman
\n
"
"Telegram-client comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
\n
"
"This is free software, and you are welcome to redistribute it
\n
"
"under certain conditions; type `show_license' for details.
\n
"
...
...
mtproto-client.c
View file @
fe08f0c5
This diff is collapsed.
Click to expand it.
mtproto-common.c
View file @
fe08f0c5
...
...
@@ -39,7 +39,6 @@
#include <openssl/sha.h>
#include "mtproto-common.h"
#include "interface.h"
#include "include.h"
#ifdef __MACH__
...
...
@@ -61,9 +60,7 @@ int get_random_bytes (unsigned char *buf, int n) {
if
(
h
>=
0
)
{
r
=
read
(
h
,
buf
,
n
);
if
(
r
>
0
)
{
if
(
verbosity
>=
3
)
{
logprintf
(
"added %d bytes of real entropy to secure random numbers seed
\n
"
,
r
);
}
vlogprintf
(
E_DEBUG
,
"added %d bytes of real entropy to secure random numbers seed
\n
"
,
r
);
}
else
{
r
=
0
;
}
...
...
@@ -143,16 +140,14 @@ void prng_seed (const char *password_filename, int password_length) {
if
(
password_filename
&&
password_length
>
0
)
{
int
fd
=
open
(
password_filename
,
O_RDONLY
);
if
(
fd
<
0
)
{
logprintf
(
"Warning: fail to open password file -
\"
%s
\"
, %m.
\n
"
,
password_filename
);
vlogprintf
(
E_WARNING
,
"Warning: fail to open password file -
\"
%s
\"
, %m.
\n
"
,
password_filename
);
}
else
{
unsigned
char
*
a
=
talloc0
(
password_length
);
int
l
=
read
(
fd
,
a
,
password_length
);
if
(
l
<
0
)
{
logprintf
(
"Warning: fail to read password file -
\"
%s
\"
, %m.
\n
"
,
password_filename
);
vlogprintf
(
E_WARNING
,
"Warning: fail to read password file -
\"
%s
\"
, %m.
\n
"
,
password_filename
);
}
else
{
if
(
verbosity
>
0
)
{
logprintf
(
"read %d bytes from password file.
\n
"
,
l
);
}
vlogprintf
(
E_DEBUG
,
"read %d bytes from password file.
\n
"
,
l
);
RAND_add
(
a
,
l
,
l
);
}
close
(
fd
);
...
...
mtproto-common.h
View file @
fe08f0c5
...
...
@@ -26,9 +26,11 @@
#include <openssl/aes.h>
#include <stdio.h>
#include "interface.h"
//
#include "interface.h"
#include "tools.h"
#include "auto/constants.h"
#include "tgl.h"
/* DH key exchange protocol data structures */
#define CODE_req_pq 0x60469778
#define CODE_resPQ 0x05162463
...
...
@@ -178,9 +180,7 @@ static inline int prefetch_strlen (void) {
extern
int
verbosity
;
static
inline
char
*
fetch_str
(
int
len
)
{
assert
(
len
>=
0
);
if
(
verbosity
>
6
)
{
logprintf
(
"fetch_string: len = %d
\n
"
,
len
);
}
vlogprintf
(
E_DEBUG
+
3
,
"fetch_string: len = %d
\n
"
,
len
);
if
(
len
<
254
)
{
char
*
str
=
(
char
*
)
in_ptr
+
1
;
in_ptr
+=
1
+
(
len
>>
2
);
...
...
@@ -272,16 +272,12 @@ int fetch_bignum (BIGNUM *x);
static
inline
int
fetch_int
(
void
)
{
assert
(
in_ptr
+
1
<=
in_end
);
if
(
verbosity
>
6
)
{
logprintf
(
"fetch_int: 0x%08x (%d)
\n
"
,
*
in_ptr
,
*
in_ptr
);
}
vlogprintf
(
E_DEBUG
+
3
,
"fetch_int: 0x%08x (%d)
\n
"
,
*
in_ptr
,
*
in_ptr
);
return
*
(
in_ptr
++
);
}
static
inline
int
fetch_bool
(
void
)
{
if
(
verbosity
>
6
)
{
logprintf
(
"fetch_bool: 0x%08x (%d)
\n
"
,
*
in_ptr
,
*
in_ptr
);
}
vlogprintf
(
E_DEBUG
+
3
,
"fetch_bool: 0x%08x (%d)
\n
"
,
*
in_ptr
,
*
in_ptr
);
assert
(
in_ptr
+
1
<=
in_end
);
assert
(
*
(
in_ptr
)
==
(
int
)
CODE_bool_true
||
*
(
in_ptr
)
==
(
int
)
CODE_bool_false
);
return
*
(
in_ptr
++
)
==
(
int
)
CODE_bool_true
;
...
...
@@ -349,14 +345,14 @@ void init_aes_unauth (const char server_nonce[16], const char hidden_client_nonc
void
init_aes_auth
(
char
auth_key
[
192
],
char
msg_key
[
16
],
int
encrypt
);
int
pad_aes_encrypt
(
char
*
from
,
int
from_len
,
char
*
to
,
int
size
);
int
pad_aes_decrypt
(
char
*
from
,
int
from_len
,
char
*
to
,
int
size
);
/*
static inline void hexdump_in (void) {
hexdump (in_ptr, in_end);
}
static inline void hexdump_out (void) {
hexdump (packet_buffer, packet_ptr);
}
}
*/
#ifdef __MACH__
#define CLOCK_REALTIME 0
...
...
net.h
View file @
fe08f0c5
...
...
@@ -26,9 +26,6 @@ struct dc;
#define TG_SERVER_TEST "173.240.5.253"
#define TG_APP_HASH "36722c72256a24c1225de00eb6a1ca74"
#define TG_APP_ID 2899
#define TG_BUILD "209"
#define TG_VERSION "0.01-beta"
#define ACK_TIMEOUT 1
#define MAX_DC_ID 10
...
...
queries.c
View file @
fe08f0c5
This diff is collapsed.
Click to expand it.
queries.h
View file @
fe08f0c5
...
...
@@ -50,10 +50,12 @@ struct query {
struct
dc
*
DC
;
struct
session
*
session
;
void
*
extra
;
void
*
callback
;
void
*
callback_extra
;
};
struct
query
*
send_query
(
struct
dc
*
DC
,
int
len
,
void
*
data
,
struct
query_methods
*
methods
,
void
*
extra
);
struct
query
*
send_query
(
struct
dc
*
DC
,
int
len
,
void
*
data
,
struct
query_methods
*
methods
,
void
*
extra
,
void
*
callback
,
void
*
callback_extra
);
void
query_ack
(
long
long
id
);
void
query_error
(
long
long
id
);
void
query_result
(
long
long
id
);
...
...
@@ -64,13 +66,13 @@ void remove_event_timer (struct event_timer *ev);
double
next_timer_in
(
void
);
void
work_timers
(
void
);
extern
struct
query_methods
help_get_config_methods
;
//
extern struct query_methods help_get_config_methods;
double
get_double_time
(
void
);
// For binlog
int
get_dh_config_on_answer
(
struct
query
*
q
);
void
fetch_dc_option
(
void
);
//
int get_dh_config_on_answer (struct query *q);
//
void fetch_dc_option (void);
#endif
structures.c
View file @
fe08f0c5
...
...
@@ -1628,9 +1628,9 @@ void tglm_message_remove_unsent (struct tgl_message *M) {
static
void
__send_msg
(
struct
tgl_message
*
M
)
{
vlogprintf
(
E_NOTICE
,
"Resending message...
\n
"
);
print_message
(
M
);
//
print_message (M);
tgl_do_send_msg
(
M
);
tgl_do_send_msg
(
M
,
0
,
0
);
}
void
tglm_send_all_unsent
(
void
)
{
...
...
tgl.c
View file @
fe08f0c5
...
...
@@ -5,3 +5,19 @@
#include "tgl.h"
struct
tgl_state
tgl_state
;
void
tgl_set_binlog_mode
(
int
mode
)
{
tgl_state
.
binlog_enabled
=
mode
;
}
void
tgl_set_binlog_path
(
const
char
*
path
)
{
tgl_state
.
binlog_name
=
tstrdup
(
path
);
}
void
tgl_set_auth_file_path
(
const
char
*
path
)
{
tgl_state
.
auth_file
=
tstrdup
(
path
);
}
void
tgl_set_download_directory
(
const
char
*
path
)
{
tgl_state
.
downloads_directory
=
tstrdup
(
path
);
}
tgl.h
View file @
fe08f0c5
This diff is collapsed.
Click to expand it.
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