more code
This commit is contained in:
parent
bf86f75604
commit
fe08f0c5e7
12
binlog.c
12
binlog.c
@ -1126,9 +1126,7 @@ static void replay_log_event (void) {
|
|||||||
assert (rptr < wptr);
|
assert (rptr < wptr);
|
||||||
int op = *rptr;
|
int op = *rptr;
|
||||||
|
|
||||||
if (verbosity >= 2) {
|
vlogprintf (E_DEBUG, "replay_log_event: log_pos=%lld, op=0x%08x\n", binlog_pos, op);
|
||||||
logprintf ("log_pos %lld, op 0x%08x\n", binlog_pos, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
in_ptr = rptr;
|
in_ptr = rptr;
|
||||||
in_end = wptr;
|
in_end = wptr;
|
||||||
@ -1201,7 +1199,7 @@ static void replay_log_event (void) {
|
|||||||
FETCH_COMBINATOR_FUNCTION (binlog_set_msg_id)
|
FETCH_COMBINATOR_FUNCTION (binlog_set_msg_id)
|
||||||
FETCH_COMBINATOR_FUNCTION (binlog_delete_msg)
|
FETCH_COMBINATOR_FUNCTION (binlog_delete_msg)
|
||||||
default:
|
default:
|
||||||
logprintf ("Unknown op 0x%08x\n", op);
|
vlogprintf (E_ERROR, "Unknown op 0x%08x\n", op);
|
||||||
assert (0);
|
assert (0);
|
||||||
}
|
}
|
||||||
assert (ok >= 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) {
|
static void add_log_event (const int *data, int len) {
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "Add log event: magic = 0x%08x, len = %d\n", data[0], len);
|
||||||
logprintf ("Add log event: magic = 0x%08x, len = %d\n", data[0], len);
|
|
||||||
}
|
|
||||||
assert (!(len & 3));
|
assert (!(len & 3));
|
||||||
rptr = (void *)data;
|
rptr = (void *)data;
|
||||||
wptr = rptr + (len / 4);
|
wptr = rptr + (len / 4);
|
||||||
@ -1297,7 +1293,7 @@ static void add_log_event (const int *data, int len) {
|
|||||||
int *end = in_end;
|
int *end = in_end;
|
||||||
replay_log_event ();
|
replay_log_event ();
|
||||||
if (rptr != wptr) {
|
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);
|
assert (rptr == wptr);
|
||||||
}
|
}
|
||||||
if (tgl_state.binlog_enabled) {
|
if (tgl_state.binlog_enabled) {
|
||||||
|
@ -34,11 +34,6 @@
|
|||||||
|
|
||||||
#define COLOR_INVERSE "\033[7m"
|
#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 *get_default_prompt (void);
|
||||||
char *complete_none (const char *text, int state);
|
char *complete_none (const char *text, int state);
|
||||||
char **complete_text (char *text, int start, int end);
|
char **complete_text (char *text, int start, int end);
|
||||||
|
4
loop.c
4
loop.c
@ -155,7 +155,7 @@ char *get_state_filename (void);
|
|||||||
char *get_secret_chat_filename (void);
|
char *get_secret_chat_filename (void);
|
||||||
int zero[512];
|
int zero[512];
|
||||||
|
|
||||||
|
/*
|
||||||
void write_dc (int auth_file_fd, struct dc *DC) {
|
void write_dc (int auth_file_fd, struct dc *DC) {
|
||||||
assert (write (auth_file_fd, &DC->port, 4) == 4);
|
assert (write (auth_file_fd, &DC->port, 4) == 4);
|
||||||
int l = strlen (DC->ip);
|
int l = strlen (DC->ip);
|
||||||
@ -436,7 +436,7 @@ void write_secret_chat_file (void) {
|
|||||||
assert (write (fd, encr_prime, 256) == 256);
|
assert (write (fd, encr_prime, 256) == 256);
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
extern int max_chat_size;
|
extern int max_chat_size;
|
||||||
int mcs (void) {
|
int mcs (void) {
|
||||||
|
29
main.c
29
main.c
@ -49,7 +49,6 @@
|
|||||||
|
|
||||||
#include "telegram.h"
|
#include "telegram.h"
|
||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
#include "mtproto-client.h"
|
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
@ -59,8 +58,8 @@
|
|||||||
|
|
||||||
#include "tgl.h"
|
#include "tgl.h"
|
||||||
|
|
||||||
#define PROGNAME "telegram-client"
|
#define PROGNAME "telegram-cli"
|
||||||
#define VERSION "0.01"
|
#define VERSION "0.07"
|
||||||
|
|
||||||
#define CONFIG_DIRECTORY "." PROG_NAME
|
#define CONFIG_DIRECTORY "." PROG_NAME
|
||||||
#define CONFIG_FILE "config"
|
#define CONFIG_FILE "config"
|
||||||
@ -319,13 +318,20 @@ void parse_config (void) {
|
|||||||
config_directory = make_full_path (config_directory);
|
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, &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, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory);
|
||||||
parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory);
|
parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory);
|
||||||
|
|
||||||
strcpy (buf + l, "binlog_enabled");
|
strcpy (buf + l, "binlog_enabled");
|
||||||
config_lookup_bool (&conf, buf, &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)) {
|
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
|
||||||
printf ("[%s] created\n", config_directory);
|
printf ("[%s] created\n", config_directory);
|
||||||
@ -338,10 +344,17 @@ void parse_config (void) {
|
|||||||
void parse_config (void) {
|
void parse_config (void) {
|
||||||
printf ("libconfig not enabled\n");
|
printf ("libconfig not enabled\n");
|
||||||
tasprintf (&auth_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, AUTH_KEY_FILE);
|
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 (&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);
|
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
|
#endif
|
||||||
|
|
||||||
@ -488,7 +501,7 @@ int main (int argc, char **argv) {
|
|||||||
|
|
||||||
args_parse (argc, argv);
|
args_parse (argc, argv);
|
||||||
printf (
|
printf (
|
||||||
"Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n"
|
"Telegram-client version " TGL_VERSION ", Copyright (C) 2013 Vitaly Valtman\n"
|
||||||
"Telegram-client comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\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"
|
"This is free software, and you are welcome to redistribute it\n"
|
||||||
"under certain conditions; type `show_license' for details.\n"
|
"under certain conditions; type `show_license' for details.\n"
|
||||||
|
158
mtproto-client.c
158
mtproto-client.c
@ -50,7 +50,6 @@
|
|||||||
#include "include.h"
|
#include "include.h"
|
||||||
#include "queries.h"
|
#include "queries.h"
|
||||||
#include "loop.h"
|
#include "loop.h"
|
||||||
#include "interface.h"
|
|
||||||
#include "structures.h"
|
#include "structures.h"
|
||||||
#include "binlog.h"
|
#include "binlog.h"
|
||||||
#include "auto.h"
|
#include "auto.h"
|
||||||
@ -142,18 +141,18 @@ static int rsa_load_public_key (const char *public_key_name) {
|
|||||||
pubKey = NULL;
|
pubKey = NULL;
|
||||||
FILE *f = fopen (public_key_name, "r");
|
FILE *f = fopen (public_key_name, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
logprintf ( "Couldn't open public key file: %s\n", public_key_name);
|
vlogprintf (E_WARNING, "Couldn't open public key file: %s\n", public_key_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pubKey = PEM_read_RSAPublicKey (f, NULL, NULL, NULL);
|
pubKey = PEM_read_RSAPublicKey (f, NULL, NULL, NULL);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
if (pubKey == NULL) {
|
if (pubKey == NULL) {
|
||||||
logprintf ( "PEM_read_RSAPublicKey returns NULL.\n");
|
vlogprintf (E_WARNING, "PEM_read_RSAPublicKey returns NULL.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbosity) {
|
if (verbosity) {
|
||||||
logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name);
|
vlogprintf (E_WARNING, "public key '%s' loaded successfully\n", rsa_public_key_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -267,9 +266,7 @@ unsigned p1, p2;
|
|||||||
|
|
||||||
int process_respq_answer (struct connection *c, char *packet, int len) {
|
int process_respq_answer (struct connection *c, char *packet, int len) {
|
||||||
int i;
|
int i;
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "process_respq_answer(), len=%d\n", len);
|
||||||
logprintf ( "process_respq_answer(), len=%d\n", len);
|
|
||||||
}
|
|
||||||
assert (len >= 76);
|
assert (len >= 76);
|
||||||
assert (!*(long long *) packet);
|
assert (!*(long long *) packet);
|
||||||
assert (*(int *) (packet + 16) == len - 20);
|
assert (*(int *) (packet + 16) == len - 20);
|
||||||
@ -289,10 +286,6 @@ int process_respq_answer (struct connection *c, char *packet, int len) {
|
|||||||
|
|
||||||
p1 = 0, p2 = 0;
|
p1 = 0, p2 = 0;
|
||||||
|
|
||||||
if (verbosity >= 2) {
|
|
||||||
logprintf ( "%lld received\n", what);
|
|
||||||
}
|
|
||||||
|
|
||||||
int it = 0;
|
int it = 0;
|
||||||
unsigned long long g = 0;
|
unsigned long long g = 0;
|
||||||
for (i = 0; i < 3 || it < 1000; i++) {
|
for (i = 0; i < 3 || it < 1000; i++) {
|
||||||
@ -337,10 +330,6 @@ int process_respq_answer (struct connection *c, char *packet, int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (verbosity) {
|
|
||||||
logprintf ( "p1 = %d, p2 = %d, %d iterations\n", p1, p2, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ++p1; ///
|
/// ++p1; ///
|
||||||
|
|
||||||
assert (*(int *) (from) == CODE_vector);
|
assert (*(int *) (from) == CODE_vector);
|
||||||
@ -354,7 +343,7 @@ int process_respq_answer (struct connection *c, char *packet, int len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == fingerprints_num) {
|
if (i == fingerprints_num) {
|
||||||
logprintf ( "fatal: don't have any matching keys (%016llx expected)\n", pk_fingerprint);
|
vlogprintf (E_ERROR, "fatal: don't have any matching keys (%016llx expected)\n", pk_fingerprint);
|
||||||
exit (2);
|
exit (2);
|
||||||
}
|
}
|
||||||
// create inner part (P_Q_inner_data)
|
// create inner part (P_Q_inner_data)
|
||||||
@ -519,7 +508,7 @@ int check_g (unsigned char p[256], BIGNUM *g) {
|
|||||||
ok = 1;
|
ok = 1;
|
||||||
break;
|
break;
|
||||||
} else if (s[i] > p[i]) {
|
} else if (s[i] > p[i]) {
|
||||||
logprintf ("i = %d (%d %d)\n", i, (int)s[i], (int)p[i]);
|
vlogprintf (E_WARNING, "i = %d (%d %d)\n", i, (int)s[i], (int)p[i]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -536,11 +525,9 @@ int check_g_bn (BIGNUM *p, BIGNUM *g) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int process_dh_answer (struct connection *c, char *packet, int len) {
|
int process_dh_answer (struct connection *c, char *packet, int len) {
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "process_dh_answer(), len=%d\n", len);
|
||||||
logprintf ( "process_dh_answer(), len=%d\n", len);
|
|
||||||
}
|
|
||||||
if (len < 116) {
|
if (len < 116) {
|
||||||
logprintf ( "%u * %u = %llu", p1, p2, what);
|
vlogprintf (E_ERROR, "%u * %u = %llu", p1, p2, what);
|
||||||
}
|
}
|
||||||
assert (len >= 116);
|
assert (len >= 116);
|
||||||
assert (!*(long long *) packet);
|
assert (!*(long long *) packet);
|
||||||
@ -636,9 +623,7 @@ int process_dh_answer (struct connection *c, char *packet, int len) {
|
|||||||
|
|
||||||
|
|
||||||
int process_auth_complete (struct connection *c UU, char *packet, int len) {
|
int process_auth_complete (struct connection *c UU, char *packet, int len) {
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "process_dh_answer(), len=%d\n", len);
|
||||||
logprintf ( "process_dh_answer(), len=%d\n", len);
|
|
||||||
}
|
|
||||||
assert (len == 72);
|
assert (len == 72);
|
||||||
assert (!*(long long *) packet);
|
assert (!*(long long *) packet);
|
||||||
assert (*(int *) (packet + 16) == len - 20);
|
assert (*(int *) (packet + 16) == len - 20);
|
||||||
@ -659,9 +644,6 @@ int process_auth_complete (struct connection *c UU, char *packet, int len) {
|
|||||||
assert (!memcmp (packet + 56, sha1_buffer + 4, 16));
|
assert (!memcmp (packet + 56, sha1_buffer + 4, 16));
|
||||||
GET_DC(c)->server_salt = *(long long *)server_nonce ^ *(long long *)new_nonce;
|
GET_DC(c)->server_salt = *(long long *)server_nonce ^ *(long long *)new_nonce;
|
||||||
|
|
||||||
if (verbosity >= 3) {
|
|
||||||
logprintf ( "auth_key_id=%016llx\n", GET_DC(c)->auth_key_id);
|
|
||||||
}
|
|
||||||
//kprintf ("OK\n");
|
//kprintf ("OK\n");
|
||||||
|
|
||||||
//c->status = conn_error;
|
//c->status = conn_error;
|
||||||
@ -669,9 +651,7 @@ int process_auth_complete (struct connection *c UU, char *packet, int len) {
|
|||||||
|
|
||||||
c_state = st_authorized;
|
c_state = st_authorized;
|
||||||
//return 1;
|
//return 1;
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "Auth success\n");
|
||||||
logprintf ( "Auth success\n");
|
|
||||||
}
|
|
||||||
auth_success ++;
|
auth_success ++;
|
||||||
GET_DC(c)->flags |= 1;
|
GET_DC(c)->flags |= 1;
|
||||||
write_auth_file ();
|
write_auth_file ();
|
||||||
@ -735,9 +715,7 @@ int aes_encrypt_message (struct dc *DC, struct encrypted_message *enc) {
|
|||||||
assert (enc->msg_len >= 0 && enc->msg_len <= MAX_MESSAGE_INTS * 4 - 16 && !(enc->msg_len & 3));
|
assert (enc->msg_len >= 0 && enc->msg_len <= MAX_MESSAGE_INTS * 4 - 16 && !(enc->msg_len & 3));
|
||||||
sha1 ((unsigned char *) &enc->server_salt, enc_len, sha1_buffer);
|
sha1 ((unsigned char *) &enc->server_salt, enc_len, sha1_buffer);
|
||||||
//printf ("enc_len is %d\n", enc_len);
|
//printf ("enc_len is %d\n", enc_len);
|
||||||
if (verbosity >= 2) {
|
vlogprintf (E_DEBUG, "sending message with sha1 %08x\n", *(int *)sha1_buffer);
|
||||||
logprintf ( "sending message with sha1 %08x\n", *(int *)sha1_buffer);
|
|
||||||
}
|
|
||||||
memcpy (enc->msg_key, sha1_buffer + 4, 16);
|
memcpy (enc->msg_key, sha1_buffer + 4, 16);
|
||||||
init_aes_auth (DC->auth_key, enc->msg_key, AES_ENCRYPT);
|
init_aes_auth (DC->auth_key, enc->msg_key, AES_ENCRYPT);
|
||||||
//hexdump ((char *)enc, (char *)enc + enc_len + 24);
|
//hexdump ((char *)enc, (char *)enc + enc_len + 24);
|
||||||
@ -831,7 +809,7 @@ void fetch_date (void) {
|
|||||||
void fetch_seq (void) {
|
void fetch_seq (void) {
|
||||||
int x = fetch_int ();
|
int x = fetch_int ();
|
||||||
if (x > seq + 1) {
|
if (x > seq + 1) {
|
||||||
logprintf ("Hole in seq: seq = %d, x = %d\n", seq, x);
|
vlogprintf (E_NOTICE, "Hole in seq: seq = %d, x = %d\n", seq, x);
|
||||||
//tgl_do_get_difference ();
|
//tgl_do_get_difference ();
|
||||||
//seq = x;
|
//seq = x;
|
||||||
} else if (x == seq + 1) {
|
} else if (x == seq + 1) {
|
||||||
@ -911,9 +889,11 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
struct tgl_message *M = tglf_fetch_alloc_message ();
|
struct tgl_message *M = tglf_fetch_alloc_message ();
|
||||||
assert (M);
|
assert (M);
|
||||||
fetch_pts ();
|
fetch_pts ();
|
||||||
unread_messages ++;
|
|
||||||
print_message (M);
|
tgl_state.callback.new_msg (M);
|
||||||
update_prompt ();
|
//unread_messages ++;
|
||||||
|
//print_message (M);
|
||||||
|
//update_prompt ();
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
case CODE_update_message_i_d:
|
case CODE_update_message_i_d:
|
||||||
@ -930,30 +910,38 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
{
|
{
|
||||||
assert (fetch_int () == (int)CODE_vector);
|
assert (fetch_int () == (int)CODE_vector);
|
||||||
int n = fetch_int ();
|
int n = fetch_int ();
|
||||||
|
|
||||||
|
struct tgl_message **ML = talloc (n * sizeof (void *));
|
||||||
|
int p = 0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
int id = fetch_int ();
|
int id = fetch_int ();
|
||||||
struct tgl_message *M = tgl_message_get (id);
|
struct tgl_message *M = tgl_message_get (id);
|
||||||
if (M) {
|
if (M) {
|
||||||
bl_do_set_unread (M, 0);
|
bl_do_set_unread (M, 0);
|
||||||
|
ML[p ++] = M;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetch_pts ();
|
fetch_pts ();
|
||||||
if (log_level >= 1) {
|
tgl_state.callback.marked_read (p, ML);
|
||||||
|
tfree (ML, sizeof (void *) * n);
|
||||||
|
/*if (log_level >= 1) {
|
||||||
print_start ();
|
print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" %d messages marked as read\n", n);
|
printf (" %d messages marked as read\n", n);
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CODE_update_user_typing:
|
case CODE_update_user_typing:
|
||||||
{
|
{
|
||||||
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
||||||
tgl_peer_t *U = tgl_peer_get (id);
|
tgl_peer_t *U = tgl_peer_get (id);
|
||||||
if (log_level >= 2) {
|
|
||||||
|
tgl_state.callback.type_notification (id, (void *)U);
|
||||||
|
/*if (log_level >= 2) {
|
||||||
print_start ();
|
print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
@ -962,7 +950,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
printf (" is typing....\n");
|
printf (" is typing....\n");
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CODE_update_chat_user_typing:
|
case CODE_update_chat_user_typing:
|
||||||
@ -971,7 +959,9 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
|
||||||
tgl_peer_t *C = tgl_peer_get (chat_id);
|
tgl_peer_t *C = tgl_peer_get (chat_id);
|
||||||
tgl_peer_t *U = tgl_peer_get (id);
|
tgl_peer_t *U = tgl_peer_get (id);
|
||||||
if (log_level >= 2) {
|
|
||||||
|
tgl_state.callback.type_in_chat_notification (id, (void *)U, chat_id, (void *)C);
|
||||||
|
/*if (log_level >= 2) {
|
||||||
print_start ();
|
print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
@ -982,7 +972,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
printf ("....\n");
|
printf ("....\n");
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CODE_update_user_status:
|
case CODE_update_user_status:
|
||||||
@ -991,7 +981,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
tgl_peer_t *U = tgl_peer_get (user_id);
|
tgl_peer_t *U = tgl_peer_get (user_id);
|
||||||
if (U) {
|
if (U) {
|
||||||
tglf_fetch_user_status (&U->user.status);
|
tglf_fetch_user_status (&U->user.status);
|
||||||
if (log_level >= 3) {
|
tgl_state.callback.status_notification ((void *)U);
|
||||||
|
/*if (log_level >= 3) {
|
||||||
print_start ();
|
print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
@ -1001,7 +992,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
printf ("%s\n", (U->user.status.online > 0) ? "online" : "offline");
|
printf ("%s\n", (U->user.status.online > 0) ? "online" : "offline");
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();
|
||||||
}
|
}*/
|
||||||
} else {
|
} else {
|
||||||
struct tgl_user_status t;
|
struct tgl_user_status t;
|
||||||
tglf_fetch_user_status (&t);
|
tglf_fetch_user_status (&t);
|
||||||
@ -1019,7 +1010,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
char *l = fetch_str (l2);
|
char *l = fetch_str (l2);
|
||||||
struct tgl_user *U = &UC->user;
|
struct tgl_user *U = &UC->user;
|
||||||
bl_do_user_set_real_name (U, f, l1, l, l2);
|
bl_do_user_set_real_name (U, f, l1, l, l2);
|
||||||
print_start ();
|
/*print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" User ");
|
printf (" User ");
|
||||||
@ -1028,7 +1019,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
print_user_name (user_id, UC);
|
print_user_name (user_id, UC);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();*/
|
||||||
} else {
|
} else {
|
||||||
fetch_skip_str ();
|
fetch_skip_str ();
|
||||||
fetch_skip_str ();
|
fetch_skip_str ();
|
||||||
@ -1060,14 +1051,14 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
}
|
}
|
||||||
bl_do_set_user_profile_photo (U, photo_id, &big, &small);
|
bl_do_set_user_profile_photo (U, photo_id, &big, &small);
|
||||||
|
|
||||||
print_start ();
|
/*print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" User ");
|
printf (" User ");
|
||||||
print_user_name (user_id, UC);
|
print_user_name (user_id, UC);
|
||||||
printf (" updated profile photo\n");
|
printf (" updated profile photo\n");
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();*/
|
||||||
} else {
|
} else {
|
||||||
struct tgl_file_location t;
|
struct tgl_file_location t;
|
||||||
unsigned y = fetch_int ();
|
unsigned y = fetch_int ();
|
||||||
@ -1086,12 +1077,12 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
{
|
{
|
||||||
assert (fetch_int () == CODE_vector);
|
assert (fetch_int () == CODE_vector);
|
||||||
int n = fetch_int ();
|
int n = fetch_int ();
|
||||||
print_start ();
|
/*print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" Restored %d messages\n", n);
|
printf (" Restored %d messages\n", n);
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();*/
|
||||||
fetch_skip (n);
|
fetch_skip (n);
|
||||||
fetch_pts ();
|
fetch_pts ();
|
||||||
}
|
}
|
||||||
@ -1100,12 +1091,12 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
{
|
{
|
||||||
assert (fetch_int () == CODE_vector);
|
assert (fetch_int () == CODE_vector);
|
||||||
int n = fetch_int ();
|
int n = fetch_int ();
|
||||||
print_start ();
|
/*print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" Deleted %d messages\n", n);
|
printf (" Deleted %d messages\n", n);
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();*/
|
||||||
fetch_skip (n);
|
fetch_skip (n);
|
||||||
fetch_pts ();
|
fetch_pts ();
|
||||||
}
|
}
|
||||||
@ -1142,7 +1133,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
fetch_int (); // version
|
fetch_int (); // version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print_start ();
|
/*print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" Chat ");
|
printf (" Chat ");
|
||||||
@ -1153,7 +1144,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
printf (" changed list, but we are forbidden to know about it (Why this update even was sent to us?\n");
|
printf (" changed list, but we are forbidden to know about it (Why this update even was sent to us?\n");
|
||||||
}
|
}
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CODE_update_contact_registered:
|
case CODE_update_contact_registered:
|
||||||
@ -1161,28 +1152,29 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
|
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
|
||||||
tgl_peer_t *U = tgl_peer_get (user_id);
|
tgl_peer_t *U = tgl_peer_get (user_id);
|
||||||
fetch_int (); // date
|
fetch_int (); // date
|
||||||
print_start ();
|
tgl_state.callback.user_registered (U);
|
||||||
|
/*print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" User ");
|
printf (" User ");
|
||||||
print_user_name (user_id, U);
|
print_user_name (user_id, U);
|
||||||
printf (" registered\n");
|
printf (" registered\n");
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CODE_update_contact_link:
|
case CODE_update_contact_link:
|
||||||
{
|
{
|
||||||
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
|
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
|
||||||
tgl_peer_t *U = tgl_peer_get (user_id);
|
tgl_peer_t *U = tgl_peer_get (user_id);
|
||||||
print_start ();
|
/*print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
printf (" Updated link with user ");
|
printf (" Updated link with user ");
|
||||||
print_user_name (user_id, U);
|
print_user_name (user_id, U);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
pop_color ();
|
pop_color ();
|
||||||
print_end ();
|
print_end ();*/
|
||||||
unsigned t = fetch_int ();
|
unsigned t = fetch_int ();
|
||||||
assert (t == CODE_contacts_my_link_empty || t == CODE_contacts_my_link_requested || t == CODE_contacts_my_link_contact);
|
assert (t == CODE_contacts_my_link_empty || t == CODE_contacts_my_link_requested || t == CODE_contacts_my_link_contact);
|
||||||
if (t == CODE_contacts_my_link_requested) {
|
if (t == CODE_contacts_my_link_requested) {
|
||||||
@ -1246,9 +1238,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
case CODE_update_encryption:
|
case CODE_update_encryption:
|
||||||
{
|
{
|
||||||
struct tgl_secret_chat *E = tglf_fetch_alloc_encrypted_chat ();
|
struct tgl_secret_chat *E = tglf_fetch_alloc_encrypted_chat ();
|
||||||
if (verbosity >= 2) {
|
vlogprintf (E_DEBUG, "Secret chat state = %d\n", E->state);
|
||||||
logprintf ("Secret chat state = %d\n", E->state);
|
|
||||||
}
|
|
||||||
print_start ();
|
print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
print_date (time (0));
|
print_date (time (0));
|
||||||
@ -1415,7 +1405,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logprintf ("Unknown update type %08x\n", op);
|
vlogprintf (E_ERROR, "Unknown update type %08x\n", op);
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1476,9 +1466,7 @@ void work_update_short_chat_message (struct connection *c UU, long long msg_id U
|
|||||||
}
|
}
|
||||||
|
|
||||||
void work_container (struct connection *c, long long msg_id UU) {
|
void work_container (struct connection *c, long long msg_id UU) {
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "work_container: msg_id = %lld\n", msg_id);
|
||||||
logprintf ( "work_container: msg_id = %lld\n", msg_id);
|
|
||||||
}
|
|
||||||
assert (fetch_int () == CODE_msg_container);
|
assert (fetch_int () == CODE_msg_container);
|
||||||
int n = fetch_int ();
|
int n = fetch_int ();
|
||||||
int i;
|
int i;
|
||||||
@ -1499,9 +1487,7 @@ void work_container (struct connection *c, long long msg_id UU) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void work_new_session_created (struct connection *c, long long msg_id UU) {
|
void work_new_session_created (struct connection *c, long long msg_id UU) {
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "work_new_session_created: msg_id = %lld\n", msg_id);
|
||||||
logprintf ( "work_new_session_created: msg_id = %lld\n", msg_id);
|
|
||||||
}
|
|
||||||
assert (fetch_int () == (int)CODE_new_session_created);
|
assert (fetch_int () == (int)CODE_new_session_created);
|
||||||
fetch_long (); // first message id
|
fetch_long (); // first message id
|
||||||
//DC->session_id = fetch_long ();
|
//DC->session_id = fetch_long ();
|
||||||
@ -1511,26 +1497,20 @@ void work_new_session_created (struct connection *c, long long msg_id UU) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void work_msgs_ack (struct connection *c UU, long long msg_id UU) {
|
void work_msgs_ack (struct connection *c UU, long long msg_id UU) {
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "work_msgs_ack: msg_id = %lld\n", msg_id);
|
||||||
logprintf ( "work_msgs_ack: msg_id = %lld\n", msg_id);
|
|
||||||
}
|
|
||||||
assert (fetch_int () == CODE_msgs_ack);
|
assert (fetch_int () == CODE_msgs_ack);
|
||||||
assert (fetch_int () == CODE_vector);
|
assert (fetch_int () == CODE_vector);
|
||||||
int n = fetch_int ();
|
int n = fetch_int ();
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
long long id = fetch_long ();
|
long long id = fetch_long ();
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG + 1, "ack for %lld\n", id);
|
||||||
logprintf ("ack for %lld\n", id);
|
|
||||||
}
|
|
||||||
query_ack (id);
|
query_ack (id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void work_rpc_result (struct connection *c UU, long long msg_id UU) {
|
void work_rpc_result (struct connection *c UU, long long msg_id UU) {
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "work_rpc_result: msg_id = %lld\n", msg_id);
|
||||||
logprintf ( "work_rpc_result: msg_id = %lld\n", msg_id);
|
|
||||||
}
|
|
||||||
assert (fetch_int () == (int)CODE_rpc_result);
|
assert (fetch_int () == (int)CODE_rpc_result);
|
||||||
long long id = fetch_long ();
|
long long id = fetch_long ();
|
||||||
int op = prefetch_int ();
|
int op = prefetch_int ();
|
||||||
@ -1558,10 +1538,6 @@ void work_packed (struct connection *c, long long msg_id) {
|
|||||||
//assert (total_out % 4 == 0);
|
//assert (total_out % 4 == 0);
|
||||||
in_ptr = buf;
|
in_ptr = buf;
|
||||||
in_end = in_ptr + total_out / 4;
|
in_end = in_ptr + total_out / 4;
|
||||||
if (verbosity >= 4) {
|
|
||||||
logprintf ( "Unzipped data: ");
|
|
||||||
hexdump_in ();
|
|
||||||
}
|
|
||||||
rpc_execute_answer (c, msg_id);
|
rpc_execute_answer (c, msg_id);
|
||||||
in_ptr = end;
|
in_ptr = end;
|
||||||
in_end = eend;
|
in_end = eend;
|
||||||
@ -1601,7 +1577,7 @@ void work_new_detailed_info (struct connection *c UU, long long msg_id UU) {
|
|||||||
|
|
||||||
void work_updates_to_long (struct connection *c UU, long long msg_id UU) {
|
void work_updates_to_long (struct connection *c UU, long long msg_id UU) {
|
||||||
assert (fetch_int () == (int)CODE_updates_too_long);
|
assert (fetch_int () == (int)CODE_updates_too_long);
|
||||||
logprintf ("updates to long... Getting difference\n");
|
vlogprintf (E_NOTICE, "updates to long... Getting difference\n");
|
||||||
tgl_do_get_difference ();
|
tgl_do_get_difference ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1610,14 +1586,10 @@ void work_bad_msg_notification (struct connection *c UU, long long msg_id UU) {
|
|||||||
long long m1 = fetch_long ();
|
long long m1 = fetch_long ();
|
||||||
int s = fetch_int ();
|
int s = fetch_int ();
|
||||||
int e = fetch_int ();
|
int e = fetch_int ();
|
||||||
logprintf ("bad_msg_notification: msg_id = %lld, seq = %d, error = %d\n", m1, s, e);
|
vlogprintf (E_NOTICE, "bad_msg_notification: msg_id = %lld, seq = %d, error = %d\n", m1, s, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpc_execute_answer (struct connection *c, long long msg_id UU) {
|
void rpc_execute_answer (struct connection *c, long long msg_id UU) {
|
||||||
if (verbosity >= 5) {
|
|
||||||
logprintf ("rpc_execute_answer: fd=%d\n", c->fd);
|
|
||||||
hexdump_in ();
|
|
||||||
}
|
|
||||||
int op = prefetch_int ();
|
int op = prefetch_int ();
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case CODE_msg_container:
|
case CODE_msg_container:
|
||||||
@ -1666,17 +1638,14 @@ void rpc_execute_answer (struct connection *c, long long msg_id UU) {
|
|||||||
work_bad_msg_notification (c, msg_id);
|
work_bad_msg_notification (c, msg_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logprintf ( "Unknown message: \n");
|
vlogprintf (E_WARNING, "Unknown message: %08x\n", op);
|
||||||
hexdump_in ();
|
|
||||||
in_ptr = in_end; // Will not fail due to assertion in_ptr == in_end
|
in_ptr = in_end; // Will not fail due to assertion in_ptr == in_end
|
||||||
}
|
}
|
||||||
|
|
||||||
int process_rpc_message (struct connection *c UU, struct encrypted_message *enc, int len) {
|
int process_rpc_message (struct connection *c UU, struct encrypted_message *enc, int len) {
|
||||||
const int MINSZ = offsetof (struct encrypted_message, message);
|
const int MINSZ = offsetof (struct encrypted_message, message);
|
||||||
const int UNENCSZ = offsetof (struct encrypted_message, server_salt);
|
const int UNENCSZ = offsetof (struct encrypted_message, server_salt);
|
||||||
if (verbosity) {
|
vlogprintf (E_DEBUG, "process_rpc_message(), len=%d\n", len);
|
||||||
logprintf ( "process_rpc_message(), len=%d\n", len);
|
|
||||||
}
|
|
||||||
assert (len >= MINSZ && (len & 15) == (UNENCSZ & 15));
|
assert (len >= MINSZ && (len & 15) == (UNENCSZ & 15));
|
||||||
struct dc *DC = GET_DC(c);
|
struct dc *DC = GET_DC(c);
|
||||||
assert (enc->auth_key_id == DC->auth_key_id);
|
assert (enc->auth_key_id == DC->auth_key_id);
|
||||||
@ -1702,10 +1671,9 @@ int process_rpc_message (struct connection *c UU, struct encrypted_message *enc,
|
|||||||
}
|
}
|
||||||
double st = get_server_time (DC);
|
double st = get_server_time (DC);
|
||||||
if (this_server_time < st - 300 || this_server_time > st + 30) {
|
if (this_server_time < st - 300 || this_server_time > st + 30) {
|
||||||
logprintf ("salt = %lld, session_id = %lld, msg_id = %lld, seq_no = %d, st = %lf, now = %lf\n", enc->server_salt, enc->session_id, enc->msg_id, enc->seq_no, st, get_utime (CLOCK_REALTIME));
|
vlogprintf (E_WARNING, "salt = %lld, session_id = %lld, msg_id = %lld, seq_no = %d, st = %lf, now = %lf\n", enc->server_salt, enc->session_id, enc->msg_id, enc->seq_no, st, get_utime (CLOCK_REALTIME));
|
||||||
in_ptr = enc->message;
|
in_ptr = enc->message;
|
||||||
in_end = in_ptr + (enc->msg_len / 4);
|
in_end = in_ptr + (enc->msg_len / 4);
|
||||||
hexdump_in ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (this_server_time >= st - 300 && this_server_time <= st + 30);
|
assert (this_server_time >= st - 300 && this_server_time <= st + 30);
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
#include "mtproto-common.h"
|
#include "mtproto-common.h"
|
||||||
#include "interface.h"
|
|
||||||
#include "include.h"
|
#include "include.h"
|
||||||
|
|
||||||
#ifdef __MACH__
|
#ifdef __MACH__
|
||||||
@ -61,9 +60,7 @@ int get_random_bytes (unsigned char *buf, int n) {
|
|||||||
if (h >= 0) {
|
if (h >= 0) {
|
||||||
r = read (h, buf, n);
|
r = read (h, buf, n);
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
if (verbosity >= 3) {
|
vlogprintf (E_DEBUG, "added %d bytes of real entropy to secure random numbers seed\n", r);
|
||||||
logprintf ( "added %d bytes of real entropy to secure random numbers seed\n", r);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
r = 0;
|
r = 0;
|
||||||
}
|
}
|
||||||
@ -143,16 +140,14 @@ void prng_seed (const char *password_filename, int password_length) {
|
|||||||
if (password_filename && password_length > 0) {
|
if (password_filename && password_length > 0) {
|
||||||
int fd = open (password_filename, O_RDONLY);
|
int fd = open (password_filename, O_RDONLY);
|
||||||
if (fd < 0) {
|
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 {
|
} else {
|
||||||
unsigned char *a = talloc0 (password_length);
|
unsigned char *a = talloc0 (password_length);
|
||||||
int l = read (fd, a, password_length);
|
int l = read (fd, a, password_length);
|
||||||
if (l < 0) {
|
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 {
|
} else {
|
||||||
if (verbosity > 0) {
|
vlogprintf (E_DEBUG, "read %d bytes from password file.\n", l);
|
||||||
logprintf ( "read %d bytes from password file.\n", l);
|
|
||||||
}
|
|
||||||
RAND_add (a, l, l);
|
RAND_add (a, l, l);
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
|
@ -26,9 +26,11 @@
|
|||||||
#include <openssl/aes.h>
|
#include <openssl/aes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "interface.h"
|
//#include "interface.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "auto/constants.h"
|
#include "auto/constants.h"
|
||||||
|
|
||||||
|
#include "tgl.h"
|
||||||
/* DH key exchange protocol data structures */
|
/* DH key exchange protocol data structures */
|
||||||
#define CODE_req_pq 0x60469778
|
#define CODE_req_pq 0x60469778
|
||||||
#define CODE_resPQ 0x05162463
|
#define CODE_resPQ 0x05162463
|
||||||
@ -178,9 +180,7 @@ static inline int prefetch_strlen (void) {
|
|||||||
extern int verbosity;
|
extern int verbosity;
|
||||||
static inline char *fetch_str (int len) {
|
static inline char *fetch_str (int len) {
|
||||||
assert (len >= 0);
|
assert (len >= 0);
|
||||||
if (verbosity > 6) {
|
vlogprintf (E_DEBUG + 3, "fetch_string: len = %d\n", len);
|
||||||
logprintf ("fetch_string: len = %d\n", len);
|
|
||||||
}
|
|
||||||
if (len < 254) {
|
if (len < 254) {
|
||||||
char *str = (char *) in_ptr + 1;
|
char *str = (char *) in_ptr + 1;
|
||||||
in_ptr += 1 + (len >> 2);
|
in_ptr += 1 + (len >> 2);
|
||||||
@ -272,16 +272,12 @@ int fetch_bignum (BIGNUM *x);
|
|||||||
|
|
||||||
static inline int fetch_int (void) {
|
static inline int fetch_int (void) {
|
||||||
assert (in_ptr + 1 <= in_end);
|
assert (in_ptr + 1 <= in_end);
|
||||||
if (verbosity > 6) {
|
vlogprintf (E_DEBUG + 3, "fetch_int: 0x%08x (%d)\n", *in_ptr, *in_ptr);
|
||||||
logprintf ("fetch_int: 0x%08x (%d)\n", *in_ptr, *in_ptr);
|
|
||||||
}
|
|
||||||
return *(in_ptr ++);
|
return *(in_ptr ++);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int fetch_bool (void) {
|
static inline int fetch_bool (void) {
|
||||||
if (verbosity > 6) {
|
vlogprintf (E_DEBUG + 3, "fetch_bool: 0x%08x (%d)\n", *in_ptr, *in_ptr);
|
||||||
logprintf ("fetch_bool: 0x%08x (%d)\n", *in_ptr, *in_ptr);
|
|
||||||
}
|
|
||||||
assert (in_ptr + 1 <= in_end);
|
assert (in_ptr + 1 <= in_end);
|
||||||
assert (*(in_ptr) == (int)CODE_bool_true || *(in_ptr) == (int)CODE_bool_false);
|
assert (*(in_ptr) == (int)CODE_bool_true || *(in_ptr) == (int)CODE_bool_false);
|
||||||
return *(in_ptr ++) == (int)CODE_bool_true;
|
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);
|
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_encrypt (char *from, int from_len, char *to, int size);
|
||||||
int pad_aes_decrypt (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) {
|
static inline void hexdump_in (void) {
|
||||||
hexdump (in_ptr, in_end);
|
hexdump (in_ptr, in_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void hexdump_out (void) {
|
static inline void hexdump_out (void) {
|
||||||
hexdump (packet_buffer, packet_ptr);
|
hexdump (packet_buffer, packet_ptr);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#ifdef __MACH__
|
#ifdef __MACH__
|
||||||
#define CLOCK_REALTIME 0
|
#define CLOCK_REALTIME 0
|
||||||
|
3
net.h
3
net.h
@ -26,9 +26,6 @@ struct dc;
|
|||||||
#define TG_SERVER_TEST "173.240.5.253"
|
#define TG_SERVER_TEST "173.240.5.253"
|
||||||
#define TG_APP_HASH "36722c72256a24c1225de00eb6a1ca74"
|
#define TG_APP_HASH "36722c72256a24c1225de00eb6a1ca74"
|
||||||
#define TG_APP_ID 2899
|
#define TG_APP_ID 2899
|
||||||
#define TG_BUILD "209"
|
|
||||||
|
|
||||||
#define TG_VERSION "0.01-beta"
|
|
||||||
|
|
||||||
#define ACK_TIMEOUT 1
|
#define ACK_TIMEOUT 1
|
||||||
#define MAX_DC_ID 10
|
#define MAX_DC_ID 10
|
||||||
|
10
queries.h
10
queries.h
@ -50,10 +50,12 @@ struct query {
|
|||||||
struct dc *DC;
|
struct dc *DC;
|
||||||
struct session *session;
|
struct session *session;
|
||||||
void *extra;
|
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_ack (long long id);
|
||||||
void query_error (long long id);
|
void query_error (long long id);
|
||||||
void query_result (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);
|
double next_timer_in (void);
|
||||||
void work_timers (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);
|
double get_double_time (void);
|
||||||
|
|
||||||
|
|
||||||
// For binlog
|
// For binlog
|
||||||
|
|
||||||
int get_dh_config_on_answer (struct query *q);
|
//int get_dh_config_on_answer (struct query *q);
|
||||||
void fetch_dc_option (void);
|
//void fetch_dc_option (void);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1628,9 +1628,9 @@ void tglm_message_remove_unsent (struct tgl_message *M) {
|
|||||||
|
|
||||||
static void __send_msg (struct tgl_message *M) {
|
static void __send_msg (struct tgl_message *M) {
|
||||||
vlogprintf (E_NOTICE, "Resending message...\n");
|
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 ) {
|
void tglm_send_all_unsent (void ) {
|
||||||
|
16
tgl.c
16
tgl.c
@ -5,3 +5,19 @@
|
|||||||
#include "tgl.h"
|
#include "tgl.h"
|
||||||
struct tgl_state tgl_state;
|
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);
|
||||||
|
}
|
||||||
|
125
tgl.h
125
tgl.h
@ -6,7 +6,33 @@
|
|||||||
|
|
||||||
#define TGL_MAX_DC_NUM 100
|
#define TGL_MAX_DC_NUM 100
|
||||||
|
|
||||||
|
#define TGL_BUILD "1828"
|
||||||
|
#define TGL_VERSION "0.9-beta"
|
||||||
|
|
||||||
// Do not modify this structure, unless you know what you do
|
// Do not modify this structure, unless you know what you do
|
||||||
|
struct tgl_update_callback {
|
||||||
|
void (*new_msg)(struct tgl_message *M);
|
||||||
|
void (*marked_read)(int num, struct tgl_message *list[]);
|
||||||
|
void (*logprintf)(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
void (*type_notification)(tgl_peer_id_t id, struct tgl_user *U);
|
||||||
|
void (*type_in_chat_notification)(tgl_peer_id_t id, struct tgl_user *U, tgl_peer_id_t chat_id, struct tgl_chat *C);
|
||||||
|
void (*status_notification)(struct tgl_user *U);
|
||||||
|
void (*user_registered)(struct tgl_user *U);
|
||||||
|
};
|
||||||
|
|
||||||
|
#define vlogprintf(verbosity_level,...) \
|
||||||
|
do { \
|
||||||
|
if (tgl_state.verbosity >= verbosity_level) { \
|
||||||
|
tgl_state.callback.logprintf (__VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
#define E_ERROR 0
|
||||||
|
#define E_WARNING 1
|
||||||
|
#define E_NOTICE 2
|
||||||
|
#define E_DEBUG 3
|
||||||
|
|
||||||
struct tgl_state {
|
struct tgl_state {
|
||||||
int our_id; // ID of logged in user
|
int our_id; // ID of logged in user
|
||||||
int encr_root;
|
int encr_root;
|
||||||
@ -29,6 +55,12 @@ struct tgl_state {
|
|||||||
long long cur_uploaded_bytes;
|
long long cur_uploaded_bytes;
|
||||||
long long cur_downloading_bytes;
|
long long cur_downloading_bytes;
|
||||||
long long cur_downloaded_bytes;
|
long long cur_downloaded_bytes;
|
||||||
|
|
||||||
|
char *binlog_name;
|
||||||
|
char *auth_file;
|
||||||
|
char *downloads_directory;
|
||||||
|
|
||||||
|
struct tgl_update_callback callback;
|
||||||
};
|
};
|
||||||
extern struct tgl_state tgl_state;
|
extern struct tgl_state tgl_state;
|
||||||
|
|
||||||
@ -57,6 +89,12 @@ int tgl_complete_peer_list (int index, const char *text, int len, char **R);
|
|||||||
#define TGL_MK_CHAT(id) tgl_set_peer_id (TGL_PEER_CHAT,id)
|
#define TGL_MK_CHAT(id) tgl_set_peer_id (TGL_PEER_CHAT,id)
|
||||||
#define TGL_MK_GEO_CHAT(id) tgl_set_peer_id (TGL_PEER_GEO_CHAT,id)
|
#define TGL_MK_GEO_CHAT(id) tgl_set_peer_id (TGL_PEER_GEO_CHAT,id)
|
||||||
#define TGL_MK_ENCR_CHAT(id) tgl_set_peer_id (TGL_PEER_ENCR_CHAT,id)
|
#define TGL_MK_ENCR_CHAT(id) tgl_set_peer_id (TGL_PEER_ENCR_CHAT,id)
|
||||||
|
|
||||||
|
void tgl_set_binlog_mode (int mode);
|
||||||
|
void tgl_set_binlog_path (const char *path);
|
||||||
|
void tgl_set_auth_file_path (const char *path);
|
||||||
|
void tgl_set_download_directory (const char *path);
|
||||||
|
|
||||||
|
|
||||||
static inline int tgl_get_peer_type (tgl_peer_id_t id) {
|
static inline int tgl_get_peer_type (tgl_peer_id_t id) {
|
||||||
return id.type;
|
return id.type;
|
||||||
@ -89,52 +127,49 @@ static inline void tgl_set_test_mode (void) {
|
|||||||
tgl_state.test_mode ++;
|
tgl_state.test_mode ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tgl_do_send_code (const char *user);
|
void tgl_do_help_get_config (void (*callback)(void *callback_extra, int success), void *callback_extra);
|
||||||
void tgl_do_phone_call (const char *user);
|
void tgl_do_send_code (const char *user, void (*callback)(void *callback_extra, int success, int registered, const char *hash), void *callback_extra);
|
||||||
int tgl_do_send_code_result (const char *code);
|
void tgl_do_phone_call (const char *user, void (*callback)(void *callback_extra, int success), void *callback_extra);
|
||||||
void tgl_do_update_contact_list (void);
|
int tgl_do_send_code_result (const char *user, const char *code, void (*callback)(void *callback_extra, int success, struct tgl_user *Self), void *callback_extra) ;
|
||||||
void tgl_do_send_message (tgl_peer_id_t id, const char *msg, int len);
|
int tgl_do_send_code_result_auth (const char *user, const char *code, const char *first_name, const char *last_name, void (*callback)(void *callback_extra, int success, struct tgl_user *Self), void *callback_extra);
|
||||||
void tgl_do_send_text (tgl_peer_id_t id, char *file);
|
void tgl_do_update_contact_list (void (*callback) (void *callback_extra, int success, int size, struct tgl_user *contacts[]), void *callback_extra);
|
||||||
void tgl_do_get_history (tgl_peer_id_t id, int limit);
|
void tgl_do_send_message (tgl_peer_id_t id, const char *msg, int len, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
|
||||||
void tgl_do_get_dialog_list (void);
|
void tgl_do_send_msg (struct tgl_message *M, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
|
||||||
void tgl_do_get_dialog_list_ex (void);
|
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_send_photo (int type, tgl_peer_id_t to_id, char *file_name);
|
void tgl_do_mark_read (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success), void *callback_extra);
|
||||||
void tgl_do_get_chat_info (tgl_peer_id_t id);
|
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_user_list_info_silent (int num, int *list);
|
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_get_user_info (tgl_peer_id_t id);
|
void tgl_do_send_photo (int 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_forward_message (tgl_peer_id_t id, int n);
|
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);
|
||||||
void tgl_do_rename_chat (tgl_peer_id_t id, char *name);
|
void tgl_do_rename_chat (tgl_peer_id_t id, char *name, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
|
||||||
void tgl_do_load_encr_video (struct tgl_encr_video *V, int next);
|
void tgl_do_get_chat_info (tgl_peer_id_t id, int offline_mode, void (*callback)(void *callback_extra, int success, struct tgl_chat *C), void *callback_extra);
|
||||||
void tgl_do_create_encr_chat_request (int user_id);
|
void tgl_do_get_user_info (tgl_peer_id_t id, int offline_mode, void (*callback)(void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
|
||||||
void tgl_do_create_secret_chat (tgl_peer_id_t id);
|
void tgl_do_load_photo (struct tgl_photo *photo, void (*callback)(void *callback_extra, int success, char *filename), void *callback_extra);
|
||||||
void tgl_do_create_group_chat (tgl_peer_id_t id, char *chat_topic);
|
void tgl_do_load_video_thumb (struct tgl_video *video, void (*callback)(void *callback_extra, int success, char *filename), void *callback_extra);
|
||||||
void tgl_do_get_suggested (void);
|
void tgl_do_load_audio (struct tgl_video *V, void (*callback)(void *callback_extra, int success, char *filename), void *callback_extra);
|
||||||
|
void tgl_do_load_video (struct tgl_video *V, void (*callback)(void *callback_extra, int success, char *filename), void *callback_extra);
|
||||||
|
void tgl_do_load_document (struct tgl_document *V, void (*callback)(void *callback_extra, int success, char *filename), void *callback_extra);
|
||||||
|
void tgl_do_load_document_thumb (struct tgl_document *video, void (*callback)(void *callback_extra, int success, char *filename), void *callback_extra);
|
||||||
|
void tgl_do_load_encr_video (struct tgl_encr_video *V, void (*callback)(void *callback_extra, int success, char *filename), void *callback_extra);
|
||||||
|
void tgl_do_export_auth (int num, void (*callback) (void *callback_extra, int success), void *callback_extra);
|
||||||
|
void tgl_do_add_contact (const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, int force, void (*callback)(void *callback_extra, int success, int size, struct tgl_user *users[]), void *callback_extra);
|
||||||
|
void tgl_do_msg_search (tgl_peer_id_t id, int from, int to, int limit, const char *s, void (*callback)(void *callback_extra, int success, int size, struct tgl_message *list[]), void *callback_extra);
|
||||||
|
void tgl_do_contacts_search (int limit, const char *s, void (*callback) (void *callback_extra, int success, int size, struct tgl_user *users[]), void *callback_extra);
|
||||||
|
void tgl_do_create_encr_chat_request (int user_id, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
|
||||||
|
void tgl_do_create_secret_chat (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
|
||||||
|
void tgl_do_accept_encr_chat_request (struct tgl_secret_chat *E, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
|
||||||
|
void tgl_do_get_difference (int sync_from_start, void (*callback)(void *callback_extra, int success), void *callback_extra);
|
||||||
|
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_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);
|
||||||
|
|
||||||
|
void tgl_do_visualize_key (tgl_peer_id_t id, unsigned char buf[16]);
|
||||||
|
|
||||||
|
//void tgl_do_get_suggested (void);
|
||||||
|
|
||||||
void tgl_do_load_photo (struct tgl_photo *photo, int next);
|
|
||||||
void tgl_do_load_video_thumb (struct tgl_video *video, int next);
|
|
||||||
void tgl_do_load_audio (struct tgl_video *V, int next);
|
|
||||||
void tgl_do_load_video (struct tgl_video *V, int next);
|
|
||||||
void tgl_do_load_document (struct tgl_document *V, int next);
|
|
||||||
void tgl_do_load_document_thumb (struct tgl_document *video, int next);
|
|
||||||
void tgl_do_help_get_config (void);
|
|
||||||
int tgl_do_auth_check_phone (const char *user);
|
|
||||||
int tgl_do_get_nearest_dc (void);
|
|
||||||
int tgl_do_send_code_result_auth (const char *code, const char *first_name, const char *last_name);
|
|
||||||
void tgl_do_import_auth (int num);
|
|
||||||
void tgl_do_export_auth (int num);
|
|
||||||
void tgl_do_add_contact (const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, int force);
|
|
||||||
void tgl_do_msg_search (tgl_peer_id_t id, int from, int to, int limit, const char *s);
|
|
||||||
void tgl_do_accept_encr_chat_request (struct tgl_secret_chat *E);
|
|
||||||
void tgl_do_get_difference (void);
|
|
||||||
void tgl_do_mark_read (tgl_peer_id_t id);
|
|
||||||
void tgl_do_visualize_key (tgl_peer_id_t id);
|
|
||||||
void tgl_do_create_keys_end (struct tgl_secret_chat *U);
|
void tgl_do_create_keys_end (struct tgl_secret_chat *U);
|
||||||
void tgl_do_add_user_to_chat (tgl_peer_id_t chat_id, tgl_peer_id_t id, int limit);
|
|
||||||
void tgl_do_del_user_from_chat (tgl_peer_id_t chat_id, tgl_peer_id_t id);
|
|
||||||
void tgl_do_update_status (int online);
|
|
||||||
void tgl_do_contacts_search (int limit, const char *s);
|
|
||||||
void tgl_do_send_msg (struct tgl_message *M);
|
|
||||||
void tgl_do_delete_msg (long long id);
|
|
||||||
void tgl_do_restore_msg (long long id);
|
|
||||||
void tgl_do_send_encr_chat_layer (struct tgl_secret_chat *E);
|
void tgl_do_send_encr_chat_layer (struct tgl_secret_chat *E);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user