Improve logging system
This commit is contained in:
parent
c870e967db
commit
334101c406
13 changed files with 432 additions and 411 deletions
12
binlog.c
12
binlog.c
|
@ -55,7 +55,7 @@ void replay_log_event (struct telegram *instance) {
|
|||
int op = *bl->rptr;
|
||||
|
||||
if (verbosity >= 2) {
|
||||
logprintf ("log_pos %lld, op 0x%08x\n", bl->binlog_pos, op);
|
||||
debug ("log_pos %lld, op 0x%08x\n", bl->binlog_pos, op);
|
||||
}
|
||||
|
||||
self->in_ptr = bl->rptr;
|
||||
|
@ -73,7 +73,7 @@ void replay_log_event (struct telegram *instance) {
|
|||
int l2 = prefetch_strlen (self);
|
||||
char *ip = fetch_str (self, l2);
|
||||
int port = fetch_int (self);
|
||||
logprintf ( "id = %d, name = %.*s ip = %.*s port = %d\n", id, l1, name, l2, ip, port);
|
||||
debug ( "id = %d, name = %.*s ip = %.*s port = %d\n", id, l1, name, l2, ip, port);
|
||||
alloc_dc (instance->auth.DC_list, id, tstrndup (ip, l2), port);
|
||||
}
|
||||
bl->rptr = self->in_ptr;
|
||||
|
@ -1046,19 +1046,19 @@ void replay_log_event (struct telegram *instance) {
|
|||
bl->rptr = self->in_ptr;
|
||||
break;
|
||||
default:
|
||||
logprintf ("Unknown logevent [0x%08x] 0x%08x [0x%08x] at %lld\n", *(bl->rptr - 1), op, *(bl->rptr + 1), bl->binlog_pos);
|
||||
debug ("Unknown logevent [0x%08x] 0x%08x [0x%08x] at %lld\n", *(bl->rptr - 1), op, *(bl->rptr + 1), bl->binlog_pos);
|
||||
|
||||
assert (0);
|
||||
}
|
||||
if (verbosity >= 2) {
|
||||
logprintf ("Event end\n");
|
||||
debug ("Event end\n");
|
||||
}
|
||||
bl->in_replay_log = 0;
|
||||
bl->binlog_pos += (bl->rptr - start) * 4;
|
||||
}
|
||||
|
||||
void add_log_event (struct binlog *bl, struct mtproto_connection *self, const int *data, int len) {
|
||||
logprintf ("Add log event: magic = 0x%08x, len = %d\n", data[0], len);
|
||||
debug ("Add log event: magic = 0x%08x, len = %d\n", data[0], len);
|
||||
assert (!(len & 3));
|
||||
if (bl->in_replay_log) { return; }
|
||||
bl->rptr = (void *)data;
|
||||
|
@ -1067,7 +1067,7 @@ void add_log_event (struct binlog *bl, struct mtproto_connection *self, const in
|
|||
int *end = self->in_end;
|
||||
replay_log_event (self->connection->instance);
|
||||
if (bl->rptr != bl->wptr) {
|
||||
logprintf ("Unread %lld ints. Len = %d\n", (long long)(bl->wptr - bl->rptr), len);
|
||||
debug ("Unread %lld ints. Len = %d\n", (long long)(bl->wptr - bl->rptr), len);
|
||||
assert (bl->rptr == bl->wptr);
|
||||
}
|
||||
if (bl->binlog_enabled) {
|
||||
|
|
24
loop.c
24
loop.c
|
@ -50,7 +50,7 @@ int zero[512];
|
|||
|
||||
|
||||
void write_dc (int auth_file_fd, struct dc *DC) {
|
||||
logprintf("writing to auth_file: auth_file_fd: %d, port: %d, ip: %s\n", auth_file_fd, DC->port, DC->ip);
|
||||
debug("writing to auth_file: auth_file_fd: %d, port: %d, ip: %s\n", auth_file_fd, DC->port, DC->ip);
|
||||
assert (write (auth_file_fd, &DC->port, 4) == 4);
|
||||
int l = strlen (DC->ip);
|
||||
assert (write (auth_file_fd, &l, 4) == 4);
|
||||
|
@ -67,7 +67,7 @@ void write_dc (int auth_file_fd, struct dc *DC) {
|
|||
}
|
||||
|
||||
void write_auth_file (struct authorization_state *state, const char *filename) {
|
||||
logprintf("Writing to auth_file: %s\n", filename);
|
||||
debug("Writing to auth_file: %s\n", filename);
|
||||
int auth_file_fd = open (filename, O_CREAT | O_RDWR, 0600);
|
||||
assert (auth_file_fd >= 0);
|
||||
int x = DC_SERIALIZED_MAGIC_V2;
|
||||
|
@ -119,7 +119,7 @@ void empty_auth_file (const char *filename) {
|
|||
struct authorization_state state;
|
||||
memset(state.DC_list, 0, 11 * sizeof(void *));
|
||||
|
||||
logprintf("empty_auth_file()\n");
|
||||
debug("empty_auth_file()\n");
|
||||
alloc_dc (state.DC_list, 1, tstrdup (TG_SERVER), 443);
|
||||
state.dc_working_num = 1;
|
||||
state.auth_state = 0;
|
||||
|
@ -134,15 +134,15 @@ void empty_auth_file (const char *filename) {
|
|||
* path
|
||||
*/
|
||||
struct authorization_state read_auth_file (const char *filename) {
|
||||
logprintf("read_auth_file()\n");
|
||||
debug("read_auth_file()\n");
|
||||
|
||||
struct authorization_state state;
|
||||
memset(state.DC_list, 0, 11 * sizeof(void *));
|
||||
|
||||
int auth_file_fd = open (filename, O_RDWR, 0600);
|
||||
logprintf("fd: %d\n", auth_file_fd);
|
||||
debug("fd: %d\n", auth_file_fd);
|
||||
if (auth_file_fd < 0) {
|
||||
logprintf("auth_file does not exist, creating empty...\n");
|
||||
debug("auth_file does not exist, creating empty...\n");
|
||||
empty_auth_file (filename);
|
||||
}
|
||||
auth_file_fd = open (filename, O_RDWR, 0600);
|
||||
|
@ -153,7 +153,7 @@ struct authorization_state read_auth_file (const char *filename) {
|
|||
// magic number of file
|
||||
unsigned m;
|
||||
if (read (auth_file_fd, &m, 4) < 4 || (m != DC_SERIALIZED_MAGIC && m != DC_SERIALIZED_MAGIC_V2)) {
|
||||
logprintf("Invalid File content, wrong Magic numebr\n");
|
||||
debug("Invalid File content, wrong Magic numebr\n");
|
||||
close (auth_file_fd);
|
||||
empty_auth_file (filename);
|
||||
return state;
|
||||
|
@ -171,11 +171,11 @@ struct authorization_state read_auth_file (const char *filename) {
|
|||
assert (read (auth_file_fd, &y, 4) == 4);
|
||||
if (y) {
|
||||
read_dc (auth_file_fd, i, m, state.DC_list);
|
||||
logprintf("loaded dc[%d] - port: %d, ip: %s, auth_key_id: %lli, server_salt: %lli, has_auth: %d\n",
|
||||
debug("loaded dc[%d] - port: %d, ip: %s, auth_key_id: %lli, server_salt: %lli, has_auth: %d\n",
|
||||
i, state.DC_list[i]->port, state.DC_list[i]->ip, state.DC_list[i]->auth_key_id,
|
||||
state.DC_list[i]->server_salt, state.DC_list[i]->has_auth);
|
||||
} else {
|
||||
logprintf("loaded dc[%d] - NULL\n", i);
|
||||
debug("loaded dc[%d] - NULL\n", i);
|
||||
}
|
||||
}
|
||||
int l = read (auth_file_fd, &state.our_id, 4);
|
||||
|
@ -187,12 +187,12 @@ struct authorization_state read_auth_file (const char *filename) {
|
|||
if (m == DC_SERIALIZED_MAGIC) {
|
||||
DC_working->has_auth = 1;
|
||||
}
|
||||
logprintf("loaded authorization state - our_id: %d, auth_state: %d, dc_working_num: %d \n", state.our_id, state.auth_state, state.dc_working_num);
|
||||
debug("loaded authorization state - our_id: %d, auth_state: %d, dc_working_num: %d \n", state.our_id, state.auth_state, state.dc_working_num);
|
||||
return state;
|
||||
}
|
||||
|
||||
struct protocol_state read_state_file (const char *filename) {
|
||||
logprintf("read_state_file()\n");
|
||||
debug("read_state_file()\n");
|
||||
struct protocol_state state = {0, 0, 0, 0};
|
||||
|
||||
int state_file_fd = open (filename, O_CREAT | O_RDWR, 0600);
|
||||
|
@ -214,7 +214,7 @@ struct protocol_state read_state_file (const char *filename) {
|
|||
state.seq = x[2];
|
||||
state.last_date = x[3];
|
||||
close (state_file_fd);
|
||||
logprintf("loaded session state - pts: %d, qts: %d, seq: %d, last_date: %d.\n", state.pts,
|
||||
debug("loaded session state - pts: %d, qts: %d, seq: %d, last_date: %d.\n", state.pts,
|
||||
state.qts, state.seq, state.last_date);
|
||||
return state;
|
||||
}
|
||||
|
|
85
msglog.c
85
msglog.c
|
@ -1,18 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "debug.h"
|
||||
#include "purple-plugin/telegram-purple.h"
|
||||
|
||||
#define COLOR_RED "\033[0;31m"
|
||||
#define COLOR_REDB "\033[1;31m"
|
||||
#define COLOR_NORMAL "\033[0m"
|
||||
#define COLOR_GREEN "\033[32;1m"
|
||||
#define COLOR_GREY "\033[37;1m"
|
||||
#define COLOR_YELLOW "\033[33;1m"
|
||||
#define COLOR_BLUE "\033[34;1m"
|
||||
#define COLOR_MAGENTA "\033[35;1m"
|
||||
#define COLOR_CYAN "\033[36;1m"
|
||||
#define COLOR_LCYAN "\033[0;36m"
|
||||
|
||||
#define COLOR_INVERSE "\033[7m"
|
||||
#define COLOR_RED "\033[0;31m"
|
||||
#define COLOR_REDB "\033[1;31m"
|
||||
#define COLOR_GREEN "\033[32;1m"
|
||||
#define COLOR_NORMAL "\033[0m"
|
||||
|
||||
/**
|
||||
* Log a message to the telegram-cli message log, by
|
||||
|
@ -20,9 +16,7 @@
|
|||
*/
|
||||
void log_printf(const char *format, va_list ap)
|
||||
{
|
||||
printf (COLOR_GREY " *** ");
|
||||
vprintf (format, ap);
|
||||
printf (COLOR_NORMAL);
|
||||
vprintf (format, ap);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,39 +30,60 @@ void (*log_cb)(const char* format, va_list ap) = log_printf;
|
|||
*/
|
||||
void set_log_cb(void (*cb)(const char*, va_list ap))
|
||||
{
|
||||
log_cb = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message to the current message log
|
||||
*/
|
||||
void logprintf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
log_cb(format, ap);
|
||||
va_end (ap);
|
||||
log_cb = cb;
|
||||
}
|
||||
|
||||
void hexdump (int *in_ptr, int *in_end) {
|
||||
int *ptr = in_ptr;
|
||||
while (ptr < in_end) { printf (" %08x", *(ptr ++)); }
|
||||
printf ("\n");
|
||||
int *ptr = in_ptr;
|
||||
while (ptr < in_end) { printf (" %08x", *(ptr ++)); }
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: implement different log levels
|
||||
|
||||
void log_debug(const char* format, ...)
|
||||
void log_level_printf (const char* format, va_list ap, int level, char *color)
|
||||
{
|
||||
char buffer[256];
|
||||
vsnprintf(buffer, sizeof(buffer), format, ap);
|
||||
purple_debug(level, PLUGIN_ID, "%s%s%s ", color, buffer, COLOR_NORMAL);
|
||||
}
|
||||
|
||||
void log_warning(const char* format, ...)
|
||||
void debug(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
log_level_printf (format, ap, PURPLE_DEBUG_MISC, COLOR_NORMAL);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
void log_error(const char* format, ...)
|
||||
void info(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
log_level_printf (format, ap, PURPLE_DEBUG_INFO, COLOR_GREEN);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
void warning(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
log_level_printf (format, ap, PURPLE_DEBUG_WARNING, COLOR_YELLOW);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
void failure(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
log_level_printf (format, ap, PURPLE_DEBUG_ERROR, COLOR_YELLOW);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
void fatal(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
log_level_printf (format, ap, PURPLE_DEBUG_FATAL, COLOR_REDB);
|
||||
va_end (ap);
|
||||
info ("\n");
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
16
msglog.h
16
msglog.h
|
@ -5,17 +5,11 @@
|
|||
* to stdout
|
||||
*/
|
||||
void set_log_cb(void (*cb)(const char*, va_list ap));
|
||||
|
||||
/**
|
||||
* Log a message to the current message log
|
||||
*/
|
||||
void logprintf(const char *format, ...);
|
||||
|
||||
void hexdump (int *in_ptr, int *in_end);
|
||||
|
||||
/*
|
||||
void log_debug(const char* format, ...);
|
||||
void log_warning(const char* format, ...);
|
||||
void log_error(const char* format, ...);
|
||||
*/
|
||||
void debug(const char* format, ...);
|
||||
void info(const char* format, ...);
|
||||
void warning(const char* format, ...);
|
||||
void failure(const char* format, ...);
|
||||
void fatal(const char* format, ...);
|
||||
|
||||
|
|
138
mtproto-client.c
138
mtproto-client.c
|
@ -126,17 +126,17 @@ static int rsa_load_public_key (const char *public_key_name) {
|
|||
pubKey = NULL;
|
||||
FILE *f = fopen (public_key_name, "r");
|
||||
if (f == NULL) {
|
||||
logprintf ( "Couldn't open public key file: %s\n", public_key_name);
|
||||
debug ( "Couldn't open public key file: %s\n", public_key_name);
|
||||
return -1;
|
||||
}
|
||||
pubKey = PEM_read_RSAPublicKey (f, NULL, NULL, NULL);
|
||||
fclose (f);
|
||||
if (pubKey == NULL) {
|
||||
logprintf ( "PEM_read_RSAPublicKey returns NULL.\n");
|
||||
debug ( "PEM_read_RSAPublicKey returns NULL.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name);
|
||||
debug ( "public key '%s' loaded successfully\n", rsa_public_key_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ int encrypt_packet_buffer_aes_unauth (struct mtproto_connection *self, const cha
|
|||
|
||||
|
||||
int rpc_send_packet (struct connection *c) {
|
||||
logprintf("rpc_send_packet()\n");
|
||||
debug("rpc_send_packet()\n");
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
|
||||
int len = (self->packet_ptr - self->packet_buffer) * 4;
|
||||
|
@ -201,7 +201,7 @@ int rpc_send_packet (struct connection *c) {
|
|||
int rpc_send_message (struct connection *c, void *data, int len) {
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
|
||||
logprintf("rpc_send_message(...)\n");
|
||||
//debug("rpc_send_message(...)\n");
|
||||
assert (len > 0 && !(len & 0xfc000003));
|
||||
int total_len = len >> 2;
|
||||
if (total_len < 0x7f) {
|
||||
|
@ -241,7 +241,7 @@ unsigned long long gcd (unsigned long long a, unsigned long long b) {
|
|||
//typedef unsigned int uint128_t __attribute__ ((mode(TI)));
|
||||
|
||||
int process_respq_answer (struct connection *c, char *packet, int len) {
|
||||
logprintf ( "process_respq_answer(), len=%d\n", len);
|
||||
debug ( "process_respq_answer(), len=%d\n", len);
|
||||
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
int i;
|
||||
|
@ -264,7 +264,7 @@ int process_respq_answer (struct connection *c, char *packet, int len) {
|
|||
|
||||
self->p1 = 0, self->p2 = 0;
|
||||
|
||||
logprintf ( "%lld received\n", self->what);
|
||||
debug ( "%lld received\n", self->what);
|
||||
|
||||
int it = 0;
|
||||
unsigned long long g = 0;
|
||||
|
@ -309,7 +309,7 @@ int process_respq_answer (struct connection *c, char *packet, int len) {
|
|||
unsigned t = self->p1; self->p1 = self->p2; self->p2 = t;
|
||||
}
|
||||
|
||||
logprintf ( "Calculated primes: self->p1 = %d, self->p2 = %d, %d iterations\n", self->p1, self->p2, it);
|
||||
debug ( "Calculated primes: self->p1 = %d, self->p2 = %d, %d iterations\n", self->p1, self->p2, it);
|
||||
|
||||
/// ++p1; ///
|
||||
|
||||
|
@ -317,15 +317,15 @@ int process_respq_answer (struct connection *c, char *packet, int len) {
|
|||
int fingerprints_num = *(int *)(from + 4);
|
||||
assert (fingerprints_num >= 1 && fingerprints_num <= 64 && len == fingerprints_num * 8 + 8 + (from - packet));
|
||||
long long *fingerprints = (long long *) (from + 8);
|
||||
logprintf("Got %d fingerprints\n", fingerprints_num);
|
||||
debug("Got %d fingerprints\n", fingerprints_num);
|
||||
for (i = 0; i < fingerprints_num; i++) {
|
||||
if (fingerprints[i] == pk_fingerprint) {
|
||||
logprintf ( "found our public key at position %d\n", i);
|
||||
debug ( "found our public key at position %d\n", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == fingerprints_num) {
|
||||
logprintf ( "fatal: don't have any matching keys (%016llx expected)\n", pk_fingerprint);
|
||||
debug ( "fatal: don't have any matching keys (%016llx expected)\n", pk_fingerprint);
|
||||
exit (2);
|
||||
}
|
||||
// create inner part (P_Q_inner_data)
|
||||
|
@ -490,7 +490,7 @@ int check_g (unsigned char p[256], BIGNUM *g) {
|
|||
ok = 1;
|
||||
break;
|
||||
} else if (s[i] > p[i]) {
|
||||
logprintf ("i = %d (%d %d)\n", i, (int)s[i], (int)p[i]);
|
||||
debug ("i = %d (%d %d)\n", i, (int)s[i], (int)p[i]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -507,10 +507,10 @@ int check_g_bn (BIGNUM *p, BIGNUM *g) {
|
|||
}
|
||||
|
||||
int process_dh_answer (struct connection *c, char *packet, int len) {
|
||||
logprintf ( "process_dh_answer(), len=%d\n", len);
|
||||
debug ( "process_dh_answer(), len=%d\n", len);
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
if (len < 116) {
|
||||
logprintf ( "%u * %u = %llu", self->p1, self->p2, self->what);
|
||||
debug ( "%u * %u = %llu", self->p1, self->p2, self->what);
|
||||
}
|
||||
assert (len >= 116);
|
||||
assert (!*(long long *) packet);
|
||||
|
@ -550,7 +550,7 @@ int process_dh_answer (struct connection *c, char *packet, int len) {
|
|||
|
||||
GET_DC(c)->server_time_delta = server_time - time (0);
|
||||
GET_DC(c)->server_time_udelta = server_time - get_utime (CLOCK_MONOTONIC);
|
||||
//logprintf ( "server time is %d, delta = %d\n", server_time, server_time_delta);
|
||||
//debug ( "server time is %d, delta = %d\n", server_time, server_time_delta);
|
||||
|
||||
// Build set_client_DH_params answer
|
||||
clear_packet (self);
|
||||
|
@ -606,7 +606,7 @@ int process_dh_answer (struct connection *c, char *packet, int len) {
|
|||
|
||||
|
||||
int process_auth_complete (struct connection *c, char *packet, int len) {
|
||||
logprintf ( "process_auth_complete(), len=%d\n", len);
|
||||
debug ( "process_auth_complete(), len=%d\n", len);
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
assert (len == 72);
|
||||
assert (!*(long long *) packet);
|
||||
|
@ -628,7 +628,7 @@ int process_auth_complete (struct connection *c, char *packet, int len) {
|
|||
assert (!memcmp (packet + 56, sha1_buffer + 4, 16));
|
||||
GET_DC(c)->server_salt = *(long long *)self->server_nonce ^ *(long long *)self->new_nonce;
|
||||
|
||||
logprintf ( "auth_key_id=%016llx\n", GET_DC(c)->auth_key_id);
|
||||
debug ( "auth_key_id=%016llx\n", GET_DC(c)->auth_key_id);
|
||||
//kprintf ("OK\n");
|
||||
|
||||
//c->status = conn_error;
|
||||
|
@ -636,7 +636,7 @@ int process_auth_complete (struct connection *c, char *packet, int len) {
|
|||
|
||||
self->c_state = st_authorized;
|
||||
//return 1;
|
||||
logprintf ( "Auth success\n");
|
||||
debug ( "Auth success\n");
|
||||
self->auth_success ++;
|
||||
GET_DC(c)->flags |= 1;
|
||||
|
||||
|
@ -696,7 +696,7 @@ int aes_encrypt_message (struct mtproto_connection *self, struct dc *DC, struct
|
|||
sha1 ((unsigned char *) &enc->server_salt, enc_len, sha1_buffer);
|
||||
//printf ("enc_len is %d\n", enc_len);
|
||||
if (verbosity >= 2) {
|
||||
logprintf ( "sending message with sha1 %08x\n", *(int *)sha1_buffer);
|
||||
debug ( "sending message with sha1 %08x\n", *(int *)sha1_buffer);
|
||||
}
|
||||
memcpy (enc->msg_key, sha1_buffer + 4, 16);
|
||||
init_aes_auth (self, DC->auth_key, enc->msg_key, AES_ENCRYPT);
|
||||
|
@ -707,7 +707,7 @@ int aes_encrypt_message (struct mtproto_connection *self, struct dc *DC, struct
|
|||
long long encrypt_send_message (struct mtproto_connection *self, int *msg, int msg_ints, int useful) {
|
||||
struct connection *c = self->connection;
|
||||
|
||||
logprintf("encrypt_send_message(...)\n");
|
||||
//debug("encrypt_send_message(...)\n");
|
||||
struct dc *DC = GET_DC(c);
|
||||
struct session *S = c->session;
|
||||
assert (S);
|
||||
|
@ -746,7 +746,7 @@ void fetch_pts (struct mtproto_connection *self) {
|
|||
if (p <= self->pts) { return; }
|
||||
if (p != self->pts + 1) {
|
||||
if (self->pts) {
|
||||
//logprintf ("Hole in pts p = %d, pts = %d\n", p, pts);
|
||||
//debug ("Hole in pts p = %d, pts = %d\n", p, pts);
|
||||
|
||||
// get difference should be here
|
||||
self->pts = p;
|
||||
|
@ -764,7 +764,7 @@ void fetch_qts (struct mtproto_connection *self) {
|
|||
if (p <= self->qts) { return; }
|
||||
if (p != self->qts + 1) {
|
||||
if (self->qts) {
|
||||
//logprintf ("Hole in qts\n");
|
||||
//debug ("Hole in qts\n");
|
||||
// get difference should be here
|
||||
self->qts = p;
|
||||
} else {
|
||||
|
@ -787,7 +787,7 @@ void fetch_date (struct mtproto_connection *self) {
|
|||
void fetch_seq (struct mtproto_connection *self) {
|
||||
int x = fetch_int (self);
|
||||
if (x > self->seq + 1) {
|
||||
logprintf ("Hole in seq: seq = %d, x = %d\n", self->seq, x);
|
||||
debug ("Hole in seq: seq = %d, x = %d\n", self->seq, x);
|
||||
//do_get_difference ();
|
||||
//seq = x;
|
||||
} else if (x == self->seq + 1) {
|
||||
|
@ -867,11 +867,11 @@ void work_update (struct mtproto_connection *self, long long msg_id UU) {
|
|||
struct binlog *bl = self->bl;
|
||||
|
||||
unsigned op = fetch_int (self);
|
||||
logprintf("work_update(): OP:%d\n", op);
|
||||
debug("work_update(): OP:%d\n", op);
|
||||
switch (op) {
|
||||
case CODE_update_new_message:
|
||||
{
|
||||
logprintf ("CODE_update_new_message\n");
|
||||
debug ("CODE_update_new_message\n");
|
||||
struct message *M UU = fetch_alloc_message (self, tg);
|
||||
assert (M);
|
||||
fetch_pts (self);
|
||||
|
@ -883,7 +883,7 @@ void work_update (struct mtproto_connection *self, long long msg_id UU) {
|
|||
};
|
||||
case CODE_update_message_i_d:
|
||||
{
|
||||
logprintf ("CODE_update_message\n");
|
||||
debug ("CODE_update_message\n");
|
||||
int id = fetch_int (self); // id
|
||||
int new = fetch_long (self); // random_id
|
||||
struct message *M = message_get (bl, new);
|
||||
|
@ -894,7 +894,7 @@ void work_update (struct mtproto_connection *self, long long msg_id UU) {
|
|||
break;
|
||||
case CODE_update_read_messages:
|
||||
{
|
||||
logprintf ("CODE_update_read_message\n");
|
||||
debug ("CODE_update_read_message\n");
|
||||
assert (fetch_int (self) == (int)CODE_vector);
|
||||
int n = fetch_int (self);
|
||||
int i;
|
||||
|
@ -918,7 +918,7 @@ void work_update (struct mtproto_connection *self, long long msg_id UU) {
|
|||
break;
|
||||
case CODE_update_user_typing:
|
||||
{
|
||||
logprintf ("CODE_update_user_typing\n");
|
||||
debug ("CODE_update_user_typing\n");
|
||||
peer_id_t id = MK_USER (fetch_int (self));
|
||||
peer_t *U UU = user_chat_get (bl, id);
|
||||
event_update_user_typing (tg, U);
|
||||
|
@ -1220,7 +1220,7 @@ void work_update (struct mtproto_connection *self, long long msg_id UU) {
|
|||
{
|
||||
struct secret_chat *E = fetch_alloc_encrypted_chat (self);
|
||||
if (verbosity >= 2) {
|
||||
logprintf ("Secret chat state = %d\n", E->state);
|
||||
debug ("Secret chat state = %d\n", E->state);
|
||||
}
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
|
@ -1370,13 +1370,13 @@ void work_update (struct mtproto_connection *self, long long msg_id UU) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
logprintf ("Unknown update type %08x\n", op);
|
||||
debug ("Unknown update type %08x\n", op);
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void work_update_short (struct connection *c, long long msg_id) {
|
||||
logprintf ("work_update_short\n");
|
||||
debug ("work_update_short\n");
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
|
||||
assert (fetch_int (self) == CODE_update_short);
|
||||
|
@ -1385,7 +1385,7 @@ void work_update_short (struct connection *c, long long msg_id) {
|
|||
}
|
||||
|
||||
void work_updates (struct connection *c, long long msg_id) {
|
||||
logprintf ("work_updates(\n)");
|
||||
debug ("work_updates(\n)");
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
|
||||
assert (fetch_int (c->mtconnection) == CODE_updates);
|
||||
|
@ -1410,7 +1410,7 @@ void work_updates (struct connection *c, long long msg_id) {
|
|||
}
|
||||
|
||||
void work_update_short_message (struct connection *c UU, long long msg_id UU) {
|
||||
logprintf ("work_update_short_message(\n)");
|
||||
debug ("work_update_short_message(\n)");
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
|
||||
assert (fetch_int (c->mtconnection) == (int)CODE_update_short_message);
|
||||
|
@ -1425,7 +1425,7 @@ void work_update_short_message (struct connection *c UU, long long msg_id UU) {
|
|||
}
|
||||
|
||||
void work_update_short_chat_message (struct connection *c, long long msg_id UU) {
|
||||
logprintf ("work_update_chat_message(\n)");
|
||||
debug ("work_update_chat_message(\n)");
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
|
||||
assert (fetch_int (self) == CODE_update_short_chat_message);
|
||||
|
@ -1440,7 +1440,7 @@ void work_update_short_chat_message (struct connection *c, long long msg_id UU)
|
|||
}
|
||||
|
||||
void work_container (struct connection *c, long long msg_id UU) {
|
||||
logprintf ( "work_container: msg_id = %lld\n", msg_id);
|
||||
debug ( "work_container: msg_id = %lld\n", msg_id);
|
||||
assert (fetch_int (c->mtconnection) == CODE_msg_container);
|
||||
int n = fetch_int (c->mtconnection);
|
||||
int i;
|
||||
|
@ -1461,30 +1461,30 @@ void work_container (struct connection *c, long long msg_id UU) {
|
|||
}
|
||||
|
||||
void work_new_session_created (struct connection *c, long long msg_id UU) {
|
||||
logprintf ( "work_new_session_created: msg_id = %lld\n", msg_id);
|
||||
debug ( "work_new_session_created: msg_id = %lld\n", msg_id);
|
||||
assert (fetch_int (c->mtconnection) == (int)CODE_new_session_created);
|
||||
fetch_long (c->mtconnection); // first message id
|
||||
//DC->session_id = fetch_long ();
|
||||
fetch_long (c->mtconnection); // unique_id
|
||||
GET_DC(c)->server_salt = fetch_long (c->mtconnection);
|
||||
logprintf ("new server_salt = %lld\n", GET_DC(c)->server_salt);
|
||||
debug ("new server_salt = %lld\n", GET_DC(c)->server_salt);
|
||||
}
|
||||
|
||||
void work_msgs_ack (struct connection *c UU, long long msg_id UU) {
|
||||
logprintf ( "work_msgs_ack: msg_id = %lld\n", msg_id);
|
||||
debug ( "work_msgs_ack: msg_id = %lld\n", msg_id);
|
||||
assert (fetch_int (c->mtconnection) == CODE_msgs_ack);
|
||||
assert (fetch_int (c->mtconnection) == CODE_vector);
|
||||
int n = fetch_int (c->mtconnection);
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
long long id = fetch_long (c->mtconnection);
|
||||
logprintf ("ack for %lld\n", id);
|
||||
debug ("ack for %lld\n", id);
|
||||
query_ack (c->instance, id);
|
||||
}
|
||||
}
|
||||
|
||||
void work_rpc_result (struct connection *c UU, long long msg_id UU) {
|
||||
logprintf ( "work_rpc_result: msg_id = %lld\n", msg_id);
|
||||
debug ( "work_rpc_result: msg_id = %lld\n", msg_id);
|
||||
assert (fetch_int (c->mtconnection) == (int)CODE_rpc_result);
|
||||
long long id = fetch_long (c->mtconnection);
|
||||
int op = prefetch_int (c->mtconnection);
|
||||
|
@ -1497,7 +1497,7 @@ void work_rpc_result (struct connection *c UU, long long msg_id UU) {
|
|||
|
||||
#define MAX_PACKED_SIZE (1 << 24)
|
||||
void work_packed (struct connection *c, long long msg_id) {
|
||||
logprintf ("work_packet()\n");
|
||||
debug ("work_packet()\n");
|
||||
assert (fetch_int (c->mtconnection) == CODE_gzip_packed);
|
||||
static int in_gzip;
|
||||
static int buf[MAX_PACKED_SIZE >> 2];
|
||||
|
@ -1514,7 +1514,7 @@ void work_packed (struct connection *c, long long msg_id) {
|
|||
c->mtconnection->in_ptr = buf;
|
||||
c->mtconnection->in_end = c->mtconnection->in_ptr + total_out / 4;
|
||||
if (verbosity >= 4) {
|
||||
logprintf ( "Unzipped data: ");
|
||||
debug ( "Unzipped data: ");
|
||||
hexdump_in (c->mtconnection);
|
||||
}
|
||||
rpc_execute_answer (c, msg_id);
|
||||
|
@ -1524,7 +1524,7 @@ void work_packed (struct connection *c, long long msg_id) {
|
|||
}
|
||||
|
||||
void work_bad_server_salt (struct connection *c UU, long long msg_id UU) {
|
||||
logprintf ("work_bad_server_salt()\n");
|
||||
debug ("work_bad_server_salt()\n");
|
||||
assert (fetch_int (c->mtconnection) == (int)CODE_bad_server_salt);
|
||||
long long id = fetch_long (c->mtconnection);
|
||||
query_restart (c->instance, id);
|
||||
|
@ -1535,14 +1535,14 @@ void work_bad_server_salt (struct connection *c UU, long long msg_id UU) {
|
|||
}
|
||||
|
||||
void work_pong (struct connection *c UU, long long msg_id UU) {
|
||||
logprintf ("work_pong()\n");
|
||||
debug ("work_pong()\n");
|
||||
assert (fetch_int (c->mtconnection) == CODE_pong);
|
||||
fetch_long (c->mtconnection); // msg_id
|
||||
fetch_long (c->mtconnection); // ping_id
|
||||
}
|
||||
|
||||
void work_detailed_info (struct connection *c UU, long long msg_id UU) {
|
||||
logprintf ("work_detailed_info()\n");
|
||||
debug ("work_detailed_info()\n");
|
||||
assert (fetch_int (c->mtconnection) == CODE_msg_detailed_info);
|
||||
fetch_long (c->mtconnection); // msg_id
|
||||
fetch_long (c->mtconnection); // answer_msg_id
|
||||
|
@ -1551,7 +1551,7 @@ void work_detailed_info (struct connection *c UU, long long msg_id UU) {
|
|||
}
|
||||
|
||||
void work_new_detailed_info (struct connection *c UU, long long msg_id UU) {
|
||||
logprintf ("work_new_detailed_info()\n");
|
||||
debug ("work_new_detailed_info()\n");
|
||||
assert (fetch_int (c->mtconnection) == (int)CODE_msg_new_detailed_info);
|
||||
fetch_long (c->mtconnection); // answer_msg_id
|
||||
fetch_int (c->mtconnection); // bytes
|
||||
|
@ -1560,7 +1560,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) {
|
||||
assert (fetch_int (c->mtconnection) == (int)CODE_updates_too_long);
|
||||
logprintf ("updates to long... Getting difference\n");
|
||||
debug ("updates to long... Getting difference\n");
|
||||
do_get_difference (c->instance, 0);
|
||||
}
|
||||
|
||||
|
@ -1569,12 +1569,12 @@ void work_bad_msg_notification (struct connection *c UU, long long msg_id UU) {
|
|||
long long m1 = fetch_long (c->mtconnection);
|
||||
int s = fetch_int (c->mtconnection);
|
||||
int e = fetch_int (c->mtconnection);
|
||||
logprintf ("bad_msg_notification: msg_id = %lld, seq = %d, error = %d\n", m1, s, e);
|
||||
debug ("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) {
|
||||
if (verbosity >= 5) {
|
||||
logprintf ("rpc_execute_answer: fd=%d\n", c->fd);
|
||||
debug ("rpc_execute_answer: fd=%d\n", c->fd);
|
||||
hexdump_in (c->mtconnection);
|
||||
}
|
||||
int op = prefetch_int (c->mtconnection);
|
||||
|
@ -1625,7 +1625,7 @@ void rpc_execute_answer (struct connection *c, long long msg_id UU) {
|
|||
work_bad_msg_notification (c, msg_id);
|
||||
return;
|
||||
}
|
||||
logprintf ( "Unknown message: \n");
|
||||
debug ( "Unknown message: \n");
|
||||
hexdump_in (c->mtconnection);
|
||||
c->mtconnection->in_ptr = c->mtconnection->in_end; // Will not fail due to assertion in_ptr == in_end
|
||||
}
|
||||
|
@ -1633,7 +1633,7 @@ void rpc_execute_answer (struct connection *c, long long msg_id UU) {
|
|||
int process_rpc_message (struct connection *c UU, struct encrypted_message *enc, int len) {
|
||||
const int MINSZ = offsetof (struct encrypted_message, message);
|
||||
const int UNENCSZ = offsetof (struct encrypted_message, server_salt);
|
||||
logprintf ( "process_rpc_message(), len=%d\n", len);
|
||||
debug ( "process_rpc_message(), len=%d\n", len);
|
||||
assert (len >= MINSZ && (len & 15) == (UNENCSZ & 15));
|
||||
struct dc *DC = GET_DC(c);
|
||||
assert (enc->auth_key_id == DC->auth_key_id);
|
||||
|
@ -1659,7 +1659,7 @@ int process_rpc_message (struct connection *c UU, struct encrypted_message *enc,
|
|||
}
|
||||
double st = get_server_time (DC);
|
||||
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",
|
||||
debug ("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));
|
||||
c->mtconnection->in_ptr = enc->message;
|
||||
c->mtconnection->in_end = c->mtconnection->in_ptr + (enc->msg_len / 4);
|
||||
|
@ -1668,7 +1668,7 @@ int process_rpc_message (struct connection *c UU, struct encrypted_message *enc,
|
|||
|
||||
assert (this_server_time >= st - 300 && this_server_time <= st + 30);
|
||||
//assert (enc->msg_id > server_last_msg_id && (enc->msg_id & 3) == 1);
|
||||
logprintf ( "received mesage id %016llx\n", enc->msg_id);
|
||||
debug ( "received mesage id %016llx\n", enc->msg_id);
|
||||
hexdump_in (c->mtconnection);
|
||||
c->mtconnection->server_last_msg_id = enc->msg_id;
|
||||
|
||||
|
@ -1693,7 +1693,7 @@ int process_rpc_message (struct connection *c UU, struct encrypted_message *enc,
|
|||
|
||||
|
||||
int rpc_execute (struct connection *c, int op, int len) {
|
||||
logprintf ("outbound rpc connection #%d : received rpc answer %d with %d content bytes\n", c->fd, op, len);
|
||||
debug ("outbound rpc connection #%d : received rpc answer %d with %d content bytes\n", c->fd, op, len);
|
||||
struct mtproto_connection *self = c->mtconnection;
|
||||
struct telegram *instance = c->instance;
|
||||
|
||||
|
@ -1705,19 +1705,19 @@ int rpc_execute (struct connection *c, int op, int len) {
|
|||
*/
|
||||
|
||||
if (len >= MAX_RESPONSE_SIZE/* - 12*/ || len < 0/*12*/) {
|
||||
logprintf ( "answer too long (%d bytes), skipping\n", len);
|
||||
debug ( "answer too long (%d bytes), skipping\n", len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Response_len = len;
|
||||
|
||||
if (verbosity >= 2) {
|
||||
logprintf ("Response_len = %d\n", Response_len);
|
||||
debug ("Response_len = %d\n", Response_len);
|
||||
}
|
||||
assert (read_in (c, Response, Response_len) == Response_len);
|
||||
Response[Response_len] = 0;
|
||||
if (verbosity >= 2) {
|
||||
logprintf ( "have %d Response bytes\n", Response_len);
|
||||
debug ( "have %d Response bytes\n", Response_len);
|
||||
}
|
||||
|
||||
int o = c->mtconnection->c_state;
|
||||
|
@ -1732,14 +1732,14 @@ int rpc_execute (struct connection *c, int op, int len) {
|
|||
case st_client_dh_sent:
|
||||
process_auth_complete (c, Response/* + 8*/, Response_len/* - 12*/);
|
||||
self->queries_num --;
|
||||
logprintf ("queries_num=%d\n", c->mtconnection->queries_num);
|
||||
debug ("queries_num=%d\n", c->mtconnection->queries_num);
|
||||
if (self->on_ready) {
|
||||
self->on_ready(self, self->on_ready_data);
|
||||
}
|
||||
return 0;
|
||||
case st_authorized:
|
||||
if (op < 0 && op >= -999) {
|
||||
logprintf ("Server error %d\n", op);
|
||||
debug ("Server error %d\n", op);
|
||||
char code[12] = {0};
|
||||
snprintf (code, 12, "%d", op);
|
||||
c->mtconnection->c_state = st_error;
|
||||
|
@ -1749,7 +1749,7 @@ int rpc_execute (struct connection *c, int op, int len) {
|
|||
}
|
||||
return 0;
|
||||
default:
|
||||
logprintf ( "fatal: cannot receive answer in state %d\n", c->mtconnection->c_state);
|
||||
debug ( "fatal: cannot receive answer in state %d\n", c->mtconnection->c_state);
|
||||
exit (2);
|
||||
}
|
||||
|
||||
|
@ -1758,12 +1758,12 @@ int rpc_execute (struct connection *c, int op, int len) {
|
|||
|
||||
|
||||
int tc_close (struct connection *c, int who) {
|
||||
logprintf ( "outbound http connection #%d : closing by %d\n", c->fd, who);
|
||||
debug ( "outbound http connection #%d : closing by %d\n", c->fd, who);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tc_becomes_ready (struct connection *c) {
|
||||
logprintf ( "outbound connection #%d becomes ready\n", c->fd);
|
||||
debug ( "outbound connection #%d becomes ready\n", c->fd);
|
||||
char byte = 0xef;
|
||||
assert (write_out (c, &byte, 1) == 1);
|
||||
flush_out (c);
|
||||
|
@ -1775,7 +1775,7 @@ int tc_becomes_ready (struct connection *c) {
|
|||
switch (o) {
|
||||
case st_init:
|
||||
c->mtconnection->queries_num ++;
|
||||
logprintf ("queries_num=%d\n", c->mtconnection->queries_num);
|
||||
debug ("queries_num=%d\n", c->mtconnection->queries_num);
|
||||
send_req_pq_packet (c);
|
||||
break;
|
||||
case st_authorized:
|
||||
|
@ -1783,7 +1783,7 @@ int tc_becomes_ready (struct connection *c) {
|
|||
//telegram_change_state (c->instance, STATE_AUTHORIZED, NULL);
|
||||
break;
|
||||
default:
|
||||
logprintf ( "c_state = %d\n", c->mtconnection->c_state);
|
||||
debug ( "c_state = %d\n", c->mtconnection->c_state);
|
||||
assert (0);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1860,7 +1860,7 @@ void mtproto_connect(struct mtproto_connection *c)
|
|||
* cleanup tasks
|
||||
*/
|
||||
void mtproto_close(struct mtproto_connection *mtp) {
|
||||
logprintf ("closing mtproto_connection...\n");
|
||||
debug ("closing mtproto_connection...\n");
|
||||
mtp->destroy = 1;
|
||||
|
||||
// send all pending acks on this connection so the server won't
|
||||
|
@ -1882,7 +1882,7 @@ void mtproto_close(struct mtproto_connection *mtp) {
|
|||
* Close the underlying file descriptor
|
||||
*/
|
||||
void mtproto_destroy (struct mtproto_connection *self) {
|
||||
logprintf("destroying mtproto_connection: %p\n", self);
|
||||
debug("destroying mtproto_connection: %p\n", self);
|
||||
self->instance->config->proxy_close_cb(self->handle);
|
||||
fd_close_connection(self->connection);
|
||||
tfree(self, sizeof(struct mtproto_connection));
|
||||
|
@ -1896,7 +1896,7 @@ void mtproto_close_foreign (struct telegram *instance)
|
|||
if (c &&
|
||||
!c->destroy &&
|
||||
c->connection->session->dc->id != instance->auth.dc_working_num) {
|
||||
logprintf ("closing connection for working_dc=%d, dc=%d\n",
|
||||
debug ("closing connection for working_dc=%d, dc=%d\n",
|
||||
instance->auth.dc_working_num, c->connection->session->dc->id);
|
||||
mtproto_close (c);
|
||||
}
|
||||
|
@ -1911,11 +1911,11 @@ void mtproto_free_closed (struct telegram *tg) {
|
|||
for (i = 0; i < 100; i++) {
|
||||
if (tg->Cs[i] == NULL) continue;
|
||||
struct mtproto_connection *c = tg->Cs[i];
|
||||
logprintf ("checking mtproto_connection %d: c_state:%d destroy:%d, quries_num:%d\n",
|
||||
debug ("checking mtproto_connection %d: c_state:%d destroy:%d, quries_num:%d\n",
|
||||
i, c->c_state, c->destroy, c->queries_num);
|
||||
if (c->destroy == 0) continue;
|
||||
if (c->connection->out_bytes > 0) {
|
||||
logprintf ("still %d bytes ouput left, skipping connection...\n", c->connection->out_bytes);
|
||||
debug ("still %d bytes ouput left, skipping connection...\n", c->connection->out_bytes);
|
||||
continue;
|
||||
}
|
||||
mtproto_destroy (c);
|
||||
|
|
|
@ -337,7 +337,7 @@ extern int verbosity;
|
|||
static inline char *fetch_str (struct mtproto_connection *self, int len) {
|
||||
assert (len >= 0);
|
||||
if (verbosity > 6) {
|
||||
logprintf ("fetch_string: len = %d\n", len);
|
||||
debug ("fetch_string: len = %d\n", len);
|
||||
}
|
||||
if (len < 254) {
|
||||
char *str = (char *) self->in_ptr + 1;
|
||||
|
@ -431,14 +431,14 @@ int fetch_bignum (struct mtproto_connection *self, BIGNUM *x);
|
|||
static inline int fetch_int (struct mtproto_connection *self) {
|
||||
assert (self->in_ptr + 1 <= self->in_end);
|
||||
if (verbosity > 6) {
|
||||
logprintf ("fetch_int: 0x%08x (%d)\n", *self->in_ptr, *self->in_ptr);
|
||||
debug ("fetch_int: 0x%08x (%d)\n", *self->in_ptr, *self->in_ptr);
|
||||
}
|
||||
return *(self->in_ptr ++);
|
||||
}
|
||||
|
||||
static inline int fetch_bool (struct mtproto_connection *self) {
|
||||
if (verbosity > 6) {
|
||||
logprintf ("fetch_bool: 0x%08x (%d)\n", *self->in_ptr, *self->in_ptr);
|
||||
debug ("fetch_bool: 0x%08x (%d)\n", *self->in_ptr, *self->in_ptr);
|
||||
}
|
||||
assert (self->in_ptr + 1 <= self->in_end);
|
||||
assert (*(self->in_ptr) == (int)CODE_bool_true || *(self->in_ptr) == (int)CODE_bool_false);
|
||||
|
|
|
@ -15,7 +15,7 @@ int get_random_bytes (unsigned char *buf, int n) {
|
|||
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);
|
||||
debug ( "added %d bytes of real entropy to secure random numbers seed\n", r);
|
||||
}
|
||||
} else {
|
||||
r = 0;
|
||||
|
@ -96,14 +96,14 @@ void prng_seed (struct mtproto_connection *self, const char *password_filename,
|
|||
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);
|
||||
debug ( "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);
|
||||
debug ( "Warning: fail to read password file - \"%s\", %m.\n", password_filename);
|
||||
} else {
|
||||
logprintf ( "read %d bytes from password file.\n", l);
|
||||
debug ( "read %d bytes from password file.\n", l);
|
||||
RAND_add (a, l, l);
|
||||
}
|
||||
close (fd);
|
||||
|
|
31
net.c
31
net.c
|
@ -64,12 +64,12 @@ void start_ping_timer (struct connection *c);
|
|||
int ping_alarm (struct connection *c) {
|
||||
assert (c->state == conn_ready || c->state == conn_connecting);
|
||||
if (get_double_time () - c->last_receive_time > 20 * PING_TIMEOUT) {
|
||||
logprintf ( "fail connection: reason: ping timeout\n");
|
||||
warning ( "fail connection: reason: ping timeout\n");
|
||||
c->state = conn_failed;
|
||||
fail_connection (c);
|
||||
|
||||
} else if (get_double_time () - c->last_receive_time > 5 * PING_TIMEOUT && c->state == conn_ready) {
|
||||
logprintf ("sending PING...\n");
|
||||
debug ("sending PING...\n");
|
||||
int x[3];
|
||||
x[0] = CODE_ping;
|
||||
*(long long *)(x + 1) = lrand48 () * (1ll << 32) + lrand48 ();
|
||||
|
@ -239,7 +239,7 @@ void restart_connection (struct connection *c) {
|
|||
c->last_connect_time = time (0);
|
||||
int fd = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (fd == -1) {
|
||||
logprintf ("Can not create socket: %m\n");
|
||||
debug ("Can not create socket: %m\n");
|
||||
exit (1);
|
||||
}
|
||||
assert (fd >= 0 && fd < MAX_CONNECTIONS);
|
||||
|
@ -261,7 +261,7 @@ void restart_connection (struct connection *c) {
|
|||
|
||||
if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) == -1) {
|
||||
if (errno != EINPROGRESS) {
|
||||
logprintf ( "Can not connect to %s:%d %m\n", c->ip, c->port);
|
||||
debug ( "Can not connect to %s:%d %m\n", c->ip, c->port);
|
||||
start_fail_timer (c);
|
||||
close (fd);
|
||||
return;
|
||||
|
@ -301,13 +301,13 @@ void fail_connection (struct connection *c) {
|
|||
c->out_bytes = c->in_bytes = 0;
|
||||
close (c->fd);
|
||||
Connections[c->fd] = 0;
|
||||
logprintf ("Lost connection to server... %s:%d\n", c->ip, c->port);
|
||||
debug ("Lost connection to server... %s:%d\n", c->ip, c->port);
|
||||
restart_connection (c);
|
||||
}
|
||||
|
||||
extern FILE *log_net_f;
|
||||
int try_write (struct connection *c) {
|
||||
logprintf ( "try write: fd = %d\n", c->fd);
|
||||
debug ( "try write: fd = %d\n", c->fd);
|
||||
int x = 0;
|
||||
while (c->out_head) {
|
||||
int r = write (c->fd, c->out_head->rptr, c->out_head->wptr - c->out_head->rptr);
|
||||
|
@ -341,7 +341,7 @@ int try_write (struct connection *c) {
|
|||
delete_connection_buffer (b);
|
||||
} else {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
logprintf ("fail_connection: write_error %m\n");
|
||||
debug ("fail_connection: write_error %m\n");
|
||||
fail_connection (c);
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -349,7 +349,7 @@ int try_write (struct connection *c) {
|
|||
}
|
||||
}
|
||||
}
|
||||
logprintf ( "Sent %d bytes to %d\n", x, c->fd);
|
||||
debug ( "Sent %d bytes to %d\n", x, c->fd);
|
||||
c->out_bytes -= x;
|
||||
return x;
|
||||
}
|
||||
|
@ -417,7 +417,7 @@ void try_rpc_read (struct connection *c) {
|
|||
}
|
||||
|
||||
void try_read (struct connection *c) {
|
||||
logprintf ( "try read: fd = %d\n", c->fd);
|
||||
debug ( "try read: fd = %d\n", c->fd);
|
||||
if (!c->in_tail) {
|
||||
c->in_head = c->in_tail = new_connection_buffer (1 << 20);
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ void try_read (struct connection *c) {
|
|||
c->in_tail = b;
|
||||
} else {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
logprintf ("fail_connection: read_error %m\n");
|
||||
debug ("fail_connection: read_error %m\n");
|
||||
fail_connection (c);
|
||||
return;
|
||||
} else {
|
||||
|
@ -457,7 +457,8 @@ void try_read (struct connection *c) {
|
|||
}
|
||||
}
|
||||
}
|
||||
logprintf ( "Received %d bytes from %d\n", x, c->fd);
|
||||
debug ( "Received %d bytes from fd=#%d and DC %d(%s, %d)\n", x,
|
||||
c->fd, c->session->dc->id, c->session->dc->ip, c->session->dc->port);
|
||||
c->in_bytes += x;
|
||||
if (x) {
|
||||
try_rpc_read (c);
|
||||
|
@ -465,9 +466,9 @@ void try_read (struct connection *c) {
|
|||
}
|
||||
|
||||
int send_all_acks (struct session *S) {
|
||||
logprintf ("send_all_acks()\n");
|
||||
info ("send_all_acks(dc=%d)\n", S->dc->id);
|
||||
if (!S->c) {
|
||||
logprintf ("WARNING: cannot send acks, session has no active connection");
|
||||
warning ("WARNING: cannot send acks, session has no active connection");
|
||||
return -1;
|
||||
}
|
||||
struct mtproto_connection *mt = S->c->mtconnection;
|
||||
|
@ -487,7 +488,7 @@ int send_all_acks (struct session *S) {
|
|||
|
||||
void insert_msg_id (struct session *S, long long id) {
|
||||
if (!S->ack_tree) {
|
||||
logprintf ("Creating ack_tree pointing to session %p\n");
|
||||
debug ("Creating ack_tree pointing to session %p\n");
|
||||
S->ev.alarm = (void *)send_all_acks;
|
||||
S->ev.self = (void *)S;
|
||||
S->ev.timeout = get_double_time () + ACK_TIMEOUT;
|
||||
|
@ -525,7 +526,7 @@ struct connection *fd_create_connection (struct dc *DC, int fd,
|
|||
c->methods = methods;
|
||||
c->instance = instance;
|
||||
c->last_receive_time = get_double_time ();
|
||||
logprintf ( "connect to %s:%d successful\n", DC->ip, DC->port);
|
||||
debug ( "connect to %s:%d successful\n", DC->ip, DC->port);
|
||||
|
||||
if (!DC->sessions[0]) {
|
||||
struct session *S = talloc0 (sizeof (*S));
|
||||
|
|
|
@ -98,7 +98,7 @@ static const char *chat_id_get_comp_val (PurpleConnection *gc, int id, char *val
|
|||
*/
|
||||
static PurpleConversation *chat_show (PurpleConnection *gc, int id)
|
||||
{
|
||||
logprintf ("show chat");
|
||||
debug ("show chat");
|
||||
telegram_conn *conn = purple_connection_get_protocol_data(gc);
|
||||
|
||||
PurpleConversation *convo = purple_find_chat(gc, id);
|
||||
|
@ -159,7 +159,7 @@ static void tgprpl_tooltip_text(PurpleBuddy * buddy, PurpleNotifyUserInfo * info
|
|||
{
|
||||
purple_debug_info(PLUGIN_ID, "tgprpl_tooltip_text()\n");
|
||||
|
||||
logprintf ("purple_buddy_get_protocol_data: %s\n", buddy->name);
|
||||
debug ("purple_buddy_get_protocol_data: %s\n", buddy->name);
|
||||
peer_id_t *peer = purple_buddy_get_protocol_data(buddy);
|
||||
if(peer == NULL)
|
||||
{
|
||||
|
@ -184,11 +184,11 @@ static void tgprpl_output_cb(gpointer data, gint source, PurpleInputCondition co
|
|||
{
|
||||
mtproto_handle *conn = data;
|
||||
if (!conn->mtp) {
|
||||
logprintf ("connection no loner existing, do nothing. \n");
|
||||
debug ("connection no loner existing, do nothing. \n");
|
||||
return;
|
||||
}
|
||||
if (mtp_write_output(conn->mtp) == 0) {
|
||||
logprintf("no output, removing output...\n");
|
||||
debug("no output, removing output...\n");
|
||||
purple_input_remove(conn->wh);
|
||||
conn->wh = 0;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ static void tgprpl_output_cb(gpointer data, gint source, PurpleInputCondition co
|
|||
*/
|
||||
static void tgprpl_has_output(void *handle)
|
||||
{
|
||||
logprintf("tgprpl_has_output(%p)\n", handle);
|
||||
debug("tgprpl_has_output(%p)\n", handle);
|
||||
mtproto_handle *conn = handle;
|
||||
if (! conn->wh) {
|
||||
conn->wh = purple_input_add(conn->fd, PURPLE_INPUT_WRITE, tgprpl_output_cb, handle);
|
||||
|
@ -212,9 +212,9 @@ static void tgprpl_has_output(void *handle)
|
|||
static void tgprpl_input_cb(gpointer data, gint source, PurpleInputCondition cond)
|
||||
{
|
||||
mtproto_handle *conn = data;
|
||||
logprintf("tgprpl_input_cb()\n");
|
||||
debug("tgprpl_input_cb()\n");
|
||||
if (!conn->fd) {
|
||||
logprintf("conn for handle no longer existing, not reading input\n");
|
||||
debug("conn for handle no longer existing, not reading input\n");
|
||||
return;
|
||||
}
|
||||
mtp_read_input(conn->mtp);
|
||||
|
@ -234,11 +234,11 @@ static void tgprpl_input_cb(gpointer data, gint source, PurpleInputCondition con
|
|||
*/
|
||||
static void tgprpl_has_input(void *handle)
|
||||
{
|
||||
logprintf("tgprpl_has_input()\n");
|
||||
debug("tgprpl_has_input()\n");
|
||||
mtproto_handle *conn = handle;
|
||||
if (! conn->rh) {
|
||||
conn->rh = purple_input_add(conn->fd, PURPLE_INPUT_READ, tgprpl_input_cb, handle);
|
||||
logprintf("Attached read handle: %u ", conn->rh);
|
||||
debug("Attached read handle: %u ", conn->rh);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,7 @@ void telegram_on_proxy_request(struct telegram *tg, struct proxy_request *req)
|
|||
void telegram_on_proxy_close(void *handle)
|
||||
{
|
||||
mtproto_handle *conn = handle;
|
||||
logprintf ("Closing proxy-handles - fd: %d, write-handle: %d, read-handle: %d\n",
|
||||
debug ("Closing proxy-handles - fd: %d, write-handle: %d, read-handle: %d\n",
|
||||
conn->fd, conn->wh, conn->rh);
|
||||
if (conn->rh) {
|
||||
purple_input_remove (conn->rh);
|
||||
|
@ -315,13 +315,13 @@ void client_registration_canceled (gpointer data)
|
|||
}
|
||||
|
||||
gboolean queries_timerfunc (gpointer data) {
|
||||
logprintf ("queries_timerfunc()\n");
|
||||
debug ("queries_timerfunc()\n");
|
||||
telegram_conn *conn = data;
|
||||
work_timers (conn->tg);
|
||||
telegram_flush (conn->tg);
|
||||
|
||||
if (conn->updated) {
|
||||
logprintf ("State updated, storing current session...\n");
|
||||
debug ("State updated, storing current session...\n");
|
||||
conn->updated = 0;
|
||||
telegram_store_session (conn->tg);
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ void tgprpl_login_on_connected(gpointer *data, gint fd, const gchar *error_messa
|
|||
struct telegram *tg = req->tg;
|
||||
|
||||
if (fd == -1) {
|
||||
logprintf("purple_proxy_connect failed: %s\n", error_message);
|
||||
failure("purple_proxy_connect failed: %s\n", error_message);
|
||||
telegram_destroy(tg);
|
||||
return;
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ void tgprpl_login_on_connected(gpointer *data, gint fd, const gchar *error_messa
|
|||
|
||||
void telegram_on_disconnected (struct telegram *tg)
|
||||
{
|
||||
logprintf ("telegram_on_disconnected()\n");
|
||||
debug ("telegram_on_disconnected()\n");
|
||||
assert (0);
|
||||
}
|
||||
|
||||
|
@ -493,14 +493,14 @@ static int chat_add_message(struct telegram *tg, struct message *M)
|
|||
|
||||
void message_allocated_handler(struct telegram *tg, struct message *M)
|
||||
{
|
||||
logprintf ("message_allocated_handler\n");
|
||||
debug ("message_allocated_handler\n");
|
||||
telegram_conn *conn = tg->extra;
|
||||
PurpleConnection *gc = conn->gc;
|
||||
|
||||
if (M->service) {
|
||||
// TODO: handle service messages properly, currently adding them
|
||||
// causes a segfault for an unknown reason
|
||||
logprintf ("service message, skipping...\n");
|
||||
debug ("service message, skipping...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -510,12 +510,12 @@ void message_allocated_handler(struct telegram *tg, struct message *M)
|
|||
char *to = g_strdup_printf("%d", to_id.id);
|
||||
switch (to_id.type) {
|
||||
case PEER_CHAT:
|
||||
logprintf ("PEER_CHAT\n");
|
||||
debug ("PEER_CHAT\n");
|
||||
chat_add_message(tg, M);
|
||||
break;
|
||||
|
||||
case PEER_USER:
|
||||
logprintf ("PEER_USER\n");
|
||||
debug ("PEER_USER\n");
|
||||
if (M->from_id.id == tg->our_id) {
|
||||
serv_got_im(gc, to, M->message, PURPLE_MESSAGE_SEND, time((time_t *) &M->date));
|
||||
} else {
|
||||
|
@ -605,10 +605,10 @@ void peer_allocated_handler(struct telegram *tg, void *usr)
|
|||
|
||||
peer_t *user = usr;
|
||||
gchar *name = peer_get_peer_id_as_string(user); //g_strdup_printf("%d", get_peer_id(user->id));
|
||||
logprintf("Allocated peer: %s\n", name);
|
||||
debug("Allocated peer: %s\n", name);
|
||||
switch (user->id.type) {
|
||||
case PEER_USER: {
|
||||
logprintf("Peer type: user.\n");
|
||||
debug("Peer type: user.\n");
|
||||
// TODO: this should probably be freed again somwhere
|
||||
char *alias = malloc(BUDDYNAME_MAX_LENGTH);
|
||||
if (user_get_alias(user, alias, BUDDYNAME_MAX_LENGTH) < 0) {
|
||||
|
@ -638,7 +638,7 @@ void peer_allocated_handler(struct telegram *tg, void *usr)
|
|||
}
|
||||
break;
|
||||
case PEER_CHAT: {
|
||||
logprintf("Peer type: chat.\n");
|
||||
debug("Peer type: chat.\n");
|
||||
PurpleChat *ch = blist_find_chat_by_id(gc, name);
|
||||
if (!ch) {
|
||||
gchar *admin = g_strdup_printf("%d", user->chat.admin_id);
|
||||
|
@ -646,7 +646,7 @@ void peer_allocated_handler(struct telegram *tg, void *usr)
|
|||
g_hash_table_insert(htable, g_strdup("subject"), user->chat.title);
|
||||
g_hash_table_insert(htable, g_strdup("id"), name);
|
||||
g_hash_table_insert(htable, g_strdup("owner"), admin);
|
||||
logprintf("Adding chat to blist: %s (%s, %s)\n", user->chat.title, name, admin);
|
||||
debug("Adding chat to blist: %s (%s, %s)\n", user->chat.title, name, admin);
|
||||
ch = purple_chat_new(pa, user->chat.title, htable);
|
||||
purple_blist_add_chat(ch, NULL, NULL);
|
||||
}
|
||||
|
@ -668,7 +668,7 @@ void peer_allocated_handler(struct telegram *tg, void *usr)
|
|||
// peer_id_t u = MK_USER (cu->user_id);
|
||||
// peer_t *uchat = user_chat_get(u);
|
||||
const char *cuname = g_strdup_printf("%d", cu->user_id);
|
||||
logprintf("Adding user %s to chat %s\n", cuname, name);
|
||||
debug("Adding user %s to chat %s\n", cuname, name);
|
||||
purple_conv_chat_add_user(purple_conversation_get_chat_data(conv), cuname, "",
|
||||
PURPLE_CBFLAGS_NONE | (!strcmp(owner, cuname) ? PURPLE_CBFLAGS_FOUNDER : 0), FALSE);
|
||||
}
|
||||
|
@ -676,13 +676,13 @@ void peer_allocated_handler(struct telegram *tg, void *usr)
|
|||
}
|
||||
break;
|
||||
case PEER_GEO_CHAT:
|
||||
logprintf("Peer type: geo-chat.\n");
|
||||
debug("Peer type: geo-chat.\n");
|
||||
break;
|
||||
case PEER_ENCR_CHAT:
|
||||
logprintf("Peer type: encrypted chat.\n");
|
||||
debug("Peer type: encrypted chat.\n");
|
||||
break;
|
||||
case PEER_UNKNOWN:
|
||||
logprintf("Peer type: unknown.\n");
|
||||
debug("Peer type: unknown.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -699,7 +699,7 @@ PurpleNotifyUserInfo *create_user_notify_info(struct user *usr)
|
|||
|
||||
void user_info_received_handler(struct telegram *tg, struct user *usr, int show_info)
|
||||
{
|
||||
logprintf("Get user info. \n %d", show_info);
|
||||
debug("Get user info. \n %d", show_info);
|
||||
char *who = g_strdup_printf("%d", usr->id.id);
|
||||
if (usr->photo.sizes_num == 0 && show_info)
|
||||
{
|
||||
|
@ -718,7 +718,7 @@ void user_info_received_handler(struct telegram *tg, struct user *usr, int show_
|
|||
|
||||
void download_finished_handler(struct telegram *tg, struct download *D)
|
||||
{
|
||||
logprintf("download_finished_handler %s type %d\n", D->name, D->type);
|
||||
debug("download_finished_handler %s type %d\n", D->name, D->type);
|
||||
//TODO: We need a type for user-photos!
|
||||
if(D->type == 0)
|
||||
{
|
||||
|
@ -729,7 +729,7 @@ void download_finished_handler(struct telegram *tg, struct download *D)
|
|||
GError *err = NULL;
|
||||
g_file_get_contents(D->name, &data, &len, &err);
|
||||
int imgStoreId = purple_imgstore_add_with_id(g_memdup(data, len), len, NULL);
|
||||
logprintf("Imagestore id: %d\n", imgStoreId);
|
||||
debug("Imagestore id: %d\n", imgStoreId);
|
||||
//Create user info
|
||||
char *who = g_strdup_printf("%d", usr->id.id);
|
||||
telegram_conn *conn = tg->extra;
|
||||
|
@ -1018,32 +1018,32 @@ static void tgprpl_chat_join(PurpleConnection * gc, GHashTable * data)
|
|||
|
||||
char *id = g_hash_table_lookup(data, "id");
|
||||
if (!id) {
|
||||
logprintf ("Got no chat id, aborting...\n");
|
||||
debug ("Got no chat id, aborting...\n");
|
||||
return;
|
||||
}
|
||||
if (!purple_find_chat(gc, atoi(id))) {
|
||||
logprintf ("chat now known\n");
|
||||
debug ("chat now known\n");
|
||||
char *subject, *owner, *part;
|
||||
do_get_chat_info (conn->tg, MK_CHAT(atoi(id)));
|
||||
telegram_flush (conn->tg);
|
||||
} else {
|
||||
logprintf ("chat already known\n");
|
||||
debug ("chat already known\n");
|
||||
serv_got_joined_chat(conn->gc, atoi(id), groupname);
|
||||
}
|
||||
}
|
||||
|
||||
void on_chat_joined (struct telegram *instance, peer_id_t chatid)
|
||||
{
|
||||
logprintf ("on_chat_joined(%d)\n", chatid.id);
|
||||
debug ("on_chat_joined(%d)\n", chatid.id);
|
||||
telegram_conn *conn = instance->extra;
|
||||
|
||||
peer_t *peer = user_chat_get (instance->bl, chatid);
|
||||
if (!peer) {
|
||||
logprintf ("ERROR: chat with given id %d is not existing.\n", chatid.id);
|
||||
warning ("WARNING: chat with given id %d is not existing.\n", chatid.id);
|
||||
return;
|
||||
}
|
||||
if (!peer->id.type == PEER_CHAT) {
|
||||
logprintf ("ERROR: peer with given id %d and type %d is not a chat.\n", peer->id.id, peer->id.type);
|
||||
warning ("WARNING: peer with given id %d and type %d is not a chat.\n", peer->id.id, peer->id.type);
|
||||
return;
|
||||
}
|
||||
PurpleConversation *conv = serv_got_joined_chat(conn->gc, chatid.id, peer->chat.title);
|
||||
|
@ -1054,7 +1054,7 @@ void on_chat_joined (struct telegram *instance, peer_id_t chatid)
|
|||
peer_id_t part_id = MK_USER((curr + i)->user_id);
|
||||
char *name = g_strdup_printf ("%d", part_id.id);
|
||||
int flags = PURPLE_CBFLAGS_NONE | peer->chat.admin_id == part_id.id ? PURPLE_CBFLAGS_FOUNDER : 0;
|
||||
logprintf ("purple_conv_chat_add_user (..., name=%s, ..., flags=%d)", name, flags);
|
||||
debug ("purple_conv_chat_add_user (..., name=%s, ..., flags=%d)", name, flags);
|
||||
purple_conv_chat_add_user(
|
||||
purple_conversation_get_chat_data(conv),
|
||||
name,
|
||||
|
@ -1064,14 +1064,14 @@ void on_chat_joined (struct telegram *instance, peer_id_t chatid)
|
|||
);
|
||||
}
|
||||
struct message *M = 0;
|
||||
logprintf ("g_queue_pop_head()\n");
|
||||
debug ("g_queue_pop_head()\n");
|
||||
|
||||
while (M = g_queue_pop_head (conn->new_messages)) {
|
||||
logprintf ("adding msg-id\n");
|
||||
debug ("adding msg-id\n");
|
||||
int id = get_peer_id(M->from_id);
|
||||
if (!chat_add_message(instance, M)) {
|
||||
// chat still not working?
|
||||
logprintf ("WARNING, chat %d still not existing... \n", chatid.id);
|
||||
warning ("WARNING, chat %d still not existing... \n", chatid.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1215,7 +1215,7 @@ static void tgprpl_init(PurplePlugin *plugin)
|
|||
int len = strlen (dir) + strlen (pw->pw_dir) + 2;
|
||||
tgconf.base_config_path = talloc (len);
|
||||
tsnprintf (tgconf.base_config_path, len, "%s/%s", pw->pw_dir, dir);
|
||||
logprintf ("base configuration path: %s", tgconf.base_config_path);
|
||||
debug ("base configuration path: %s", tgconf.base_config_path);
|
||||
}
|
||||
|
||||
PurpleAccountOption *option;
|
||||
|
@ -1263,7 +1263,7 @@ static GList *tgprpl_actions(PurplePlugin * plugin, gpointer context)
|
|||
return (GList *)NULL;
|
||||
}
|
||||
|
||||
static PurplePluginInfo info = {
|
||||
static PurplePluginInfo plugin_info = {
|
||||
PURPLE_PLUGIN_MAGIC,
|
||||
PURPLE_MAJOR_VERSION,
|
||||
PURPLE_MINOR_VERSION,
|
||||
|
@ -1293,5 +1293,5 @@ static PurplePluginInfo info = {
|
|||
};
|
||||
|
||||
|
||||
PURPLE_INIT_PLUGIN(telegram, tgprpl_init, info)
|
||||
PURPLE_INIT_PLUGIN(telegram, tgprpl_init, plugin_info)
|
||||
|
||||
|
|
279
queries.c
279
queries.c
|
@ -90,7 +90,7 @@ struct query *query_get (struct telegram *instance, long long id) {
|
|||
int alarm_query (struct query *q) {
|
||||
assert (q);
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
logprintf ("Alarm query %lld\n", q->msg_id);
|
||||
debug ("Alarm query %lld\n", q->msg_id);
|
||||
q->ev.timeout = get_double_time () + QUERY_TIMEOUT;
|
||||
insert_event_timer (mtp->connection->instance, &q->ev);
|
||||
|
||||
|
@ -119,8 +119,7 @@ void query_restart (struct telegram *instance, long long id) {
|
|||
}
|
||||
|
||||
struct query *send_query (struct telegram *instance, struct dc *DC, int ints, void *data, struct query_methods *methods, void *extra) {
|
||||
logprintf("send_query(...)\n");
|
||||
logprintf ( "Sending query of size %d to DC (%s:%d)\n", 4 * ints, DC->ip, DC->port);
|
||||
info ("SEND_QUERY() size %d to DC %d(%s:%d)\n", 4 * ints, DC->id, DC->ip, DC->port);
|
||||
struct query *q = talloc0 (sizeof (*q));
|
||||
q->data_len = ints;
|
||||
q->data = talloc (4 * ints);
|
||||
|
@ -128,18 +127,18 @@ struct query *send_query (struct telegram *instance, struct dc *DC, int ints, vo
|
|||
q->msg_id = encrypt_send_message (DC->sessions[0]->c->mtconnection, data, ints, 1);
|
||||
q->session = DC->sessions[0];
|
||||
q->seq_no = DC->sessions[0]->seq_no - 1;
|
||||
logprintf ( "Msg_id is %lld %p\n", q->msg_id, q);
|
||||
//debug ( "Msg_id is %lld %p\n", q->msg_id, q);
|
||||
q->methods = methods;
|
||||
q->DC = DC;
|
||||
if (instance->queries_tree) {
|
||||
if (verbosity >= 2) {
|
||||
logprintf ( "%lld %lld\n", q->msg_id, instance->queries_tree->x->msg_id);
|
||||
debug ( "%lld %lld\n", q->msg_id, instance->queries_tree->x->msg_id);
|
||||
}
|
||||
}
|
||||
|
||||
instance->queries_tree = tree_insert_query (instance->queries_tree, q, lrand48 ());
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
logprintf("queries_num: %d\n", ++ mtp->queries_num);
|
||||
++ mtp->queries_num;
|
||||
|
||||
q->ev.alarm = (void *)alarm_query;
|
||||
q->ev.timeout = get_double_time () + QUERY_TIMEOUT;
|
||||
|
@ -166,21 +165,21 @@ void query_error (struct telegram *instance, long long id) {
|
|||
assert (fetch_int (mtp) == CODE_rpc_error);
|
||||
int error_code = fetch_int (mtp);
|
||||
int error_len = prefetch_strlen (mtp);
|
||||
char *error = fetch_str (mtp, error_len);
|
||||
logprintf ( "error for query #%lld: #%d :%.*s\n", id, error_code, error_len, error);
|
||||
char *err = fetch_str (mtp, error_len);
|
||||
failure ( "error for query #%lld: #%d :%.*s\n", id, error_code, error_len, err);
|
||||
if (!q) {
|
||||
logprintf ( "No such query\n");
|
||||
failure ( "No such query\n");
|
||||
} else {
|
||||
if (!(q->flags & QUERY_ACK_RECEIVED)) {
|
||||
remove_event_timer (instance, &q->ev);
|
||||
}
|
||||
instance->queries_tree = tree_delete_query (instance->queries_tree, q);
|
||||
logprintf("queries_num: %d\n", -- mtp->queries_num);
|
||||
-- mtp->queries_num;
|
||||
|
||||
if (q->methods && q->methods->on_error) {
|
||||
q->methods->on_error (q, error_code, error_len, error);
|
||||
q->methods->on_error (q, error_code, error_len, err);
|
||||
} else {
|
||||
logprintf ( "error for query #%lld: #%d :%.*s\n", id, error_code, error_len, error);
|
||||
failure ( "error for query #%lld: #%d :%.*s\n", id, error_code, error_len, err);
|
||||
}
|
||||
tfree (q->data, q->data_len * 4);
|
||||
tfree (q, sizeof (*q));
|
||||
|
@ -193,9 +192,9 @@ void query_result (struct telegram *instance, long long id UU) {
|
|||
struct query *q = query_get (instance, id);
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
|
||||
logprintf ( "result for query #%lld\n", id);
|
||||
debug ( "result for query #%lld\n", id);
|
||||
if (verbosity >= 4) {
|
||||
logprintf ( "result: ");
|
||||
debug ( "result: ");
|
||||
hexdump_in (mtp);
|
||||
}
|
||||
|
||||
|
@ -213,19 +212,19 @@ void query_result (struct telegram *instance, long long id UU) {
|
|||
mtp->in_ptr = instance->packed_buffer;
|
||||
mtp->in_end = mtp->in_ptr + total_out / 4;
|
||||
if (verbosity >= 4) {
|
||||
logprintf ( "Unzipped data: ");
|
||||
debug ( "Unzipped data: ");
|
||||
hexdump_in (mtp);
|
||||
}
|
||||
}
|
||||
if (!q) {
|
||||
logprintf ( "No such query\n");
|
||||
warning ( "No such query\n");
|
||||
mtp->in_ptr = mtp->in_end;
|
||||
} else {
|
||||
if (!(q->flags & QUERY_ACK_RECEIVED)) {
|
||||
remove_event_timer (instance, &q->ev);
|
||||
}
|
||||
instance->queries_tree = tree_delete_query (instance->queries_tree, q);
|
||||
logprintf("queries_num: %d\n", -- mtp->queries_num);
|
||||
debug("queries_num: %d\n", -- mtp->queries_num);
|
||||
|
||||
if (q->methods && q->methods->on_answer) {
|
||||
q->methods->on_answer (q);
|
||||
|
@ -242,12 +241,12 @@ void query_result (struct telegram *instance, long long id UU) {
|
|||
|
||||
|
||||
void insert_event_timer (struct telegram *instance, struct event_timer *ev) {
|
||||
// logprintf ( "INSERT: %lf %p %p\n", ev->timeout, ev->self, ev->alarm);
|
||||
// debug ( "INSERT: %lf %p %p\n", ev->timeout, ev->self, ev->alarm);
|
||||
instance->timer_tree = tree_insert_timer (instance->timer_tree, ev, lrand48 ());
|
||||
}
|
||||
|
||||
void remove_event_timer (struct telegram *instance, struct event_timer *ev) {
|
||||
// logprintf ( "REMOVE: %lf %p %p\n", ev->timeout, ev->self, ev->alarm);
|
||||
// debug ( "REMOVE: %lf %p %p\n", ev->timeout, ev->self, ev->alarm);
|
||||
instance->timer_tree = tree_delete_timer (instance->timer_tree, ev);
|
||||
}
|
||||
|
||||
|
@ -257,7 +256,7 @@ double next_timer_in (struct telegram *instance) {
|
|||
}
|
||||
|
||||
void work_timers (struct telegram *instance) {
|
||||
logprintf ("work_timers ()\n");
|
||||
debug ("work_timers ()\n");
|
||||
double t = get_double_time ();
|
||||
while (instance->timer_tree) {
|
||||
struct event_timer *ev = tree_get_min_timer (instance->timer_tree);
|
||||
|
@ -265,7 +264,7 @@ void work_timers (struct telegram *instance) {
|
|||
if (ev->timeout > t) { break; }
|
||||
remove_event_timer (instance, ev);
|
||||
assert (ev->alarm);
|
||||
logprintf ("Alarm\n");
|
||||
debug ("Alarm\n");
|
||||
ev->alarm (ev->self);
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +274,7 @@ void free_timers (struct telegram *instance)
|
|||
while (instance->timer_tree) {
|
||||
struct event_timer *ev = tree_get_min_timer (instance->timer_tree);
|
||||
assert (ev);
|
||||
logprintf ("freeing event timer with timeout: %d\n", ev->timeout);
|
||||
debug ("freeing event timer with timeout: %d\n", ev->timeout);
|
||||
remove_event_timer (instance, ev);
|
||||
//tfree (ev, sizeof(struct event_timer));
|
||||
}
|
||||
|
@ -286,7 +285,7 @@ void free_queries (struct telegram *instance)
|
|||
while (instance->queries_tree) {
|
||||
struct query *q = tree_get_min_query (instance->queries_tree);
|
||||
assert (q);
|
||||
logprintf ("freeing query with msg_id %d and len\n", q->msg_id, q->data_len);
|
||||
debug ("freeing query with msg_id %d and len\n", q->msg_id, q->data_len);
|
||||
tfree (q->data, 4 * q->data_len);
|
||||
instance->queries_tree = tree_delete_query (instance->queries_tree, q);
|
||||
//tfree (q, sizeof (struct query));
|
||||
|
@ -328,6 +327,7 @@ void do_insert_header (struct mtproto_connection *mtp) {
|
|||
/* {{{ Get config */
|
||||
|
||||
void fetch_dc_option (struct telegram *instance) {
|
||||
info ("fetch_dc_option()\n");
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
|
||||
assert (fetch_int (mtp) == CODE_dc_option);
|
||||
|
@ -337,7 +337,7 @@ void fetch_dc_option (struct telegram *instance) {
|
|||
int l2 = prefetch_strlen (mtp);
|
||||
char *ip = fetch_str (mtp, l2);
|
||||
int port = fetch_int (mtp);
|
||||
logprintf ( "id = %d, name = %.*s ip = %.*s port = %d\n", id, l1, name, l2, ip, port);
|
||||
debug ( "id = %d, name = %.*s ip = %.*s port = %d\n", id, l1, name, l2, ip, port);
|
||||
|
||||
bl_do_dc_option (mtp->bl, mtp, id, l1, name, l2, ip, port, instance);
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ int help_get_config_on_answer (struct query *q UU) {
|
|||
assert (test_mode == CODE_bool_true || test_mode == CODE_bool_false);
|
||||
assert (test_mode == CODE_bool_false || test_mode == CODE_bool_true);
|
||||
int this_dc = fetch_int (mtp);
|
||||
logprintf ( "this_dc = %d\n", this_dc);
|
||||
debug ( "this_dc = %d\n", this_dc);
|
||||
assert (fetch_int (mtp) == CODE_vector);
|
||||
int n = fetch_int (mtp);
|
||||
assert (n <= 10);
|
||||
|
@ -366,7 +366,7 @@ int help_get_config_on_answer (struct query *q UU) {
|
|||
if (op == CODE_config) {
|
||||
instance->max_bcast_size = fetch_int (mtp);
|
||||
}
|
||||
logprintf ( "max_chat_size = %d\n", instance->max_chat_size);
|
||||
debug ( "max_chat_size = %d\n", instance->max_chat_size);
|
||||
|
||||
telegram_change_state(instance, STATE_CONFIG_RECEIVED, NULL);
|
||||
return 0;
|
||||
|
@ -377,9 +377,10 @@ struct query_methods help_get_config_methods = {
|
|||
};
|
||||
|
||||
void do_help_get_config (struct telegram *instance) {
|
||||
info ("do_help_get_config()\n");
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
|
||||
logprintf ("mtp: %p:%p\n", mtp->packet_ptr, mtp->packet_buffer);
|
||||
debug ("mtp: %p:%p\n", mtp->packet_ptr, mtp->packet_buffer);
|
||||
clear_packet (mtp);
|
||||
out_int (mtp, CODE_help_get_config);
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
|
@ -398,7 +399,7 @@ int send_code_on_answer (struct query *q UU) {
|
|||
int l = prefetch_strlen (mtp);
|
||||
char *phone_code_hash = tstrndup (fetch_str (mtp, l), l);
|
||||
instance->phone_code_hash = phone_code_hash;
|
||||
logprintf("telegram: phone_code_hash: %s\n", phone_code_hash);
|
||||
debug("telegram: phone_code_hash: %s\n", phone_code_hash);
|
||||
fetch_int (mtp);
|
||||
fetch_bool (mtp);
|
||||
instance->want_dc_num = -1;
|
||||
|
@ -407,7 +408,7 @@ int send_code_on_answer (struct query *q UU) {
|
|||
} else if (instance->session_state == STATE_CLIENT_CODE_REQUESTED) {
|
||||
telegram_change_state(instance, STATE_CLIENT_CODE_NOT_ENTERED, NULL);
|
||||
} else {
|
||||
logprintf("send_code_on_answer(): Invalid State %d ", instance->session_state);
|
||||
debug("send_code_on_answer(): Invalid State %d ", instance->session_state);
|
||||
telegram_change_state(instance, STATE_ERROR, NULL);
|
||||
}
|
||||
return 0;
|
||||
|
@ -427,7 +428,7 @@ int send_code_on_error (struct query *q UU, int error_code, int l, char *error)
|
|||
tg->auth.dc_working_num = want_dc_num;
|
||||
telegram_change_state(tg, STATE_ERROR, error);
|
||||
} else {
|
||||
logprintf ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
fatal ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
assert (0);
|
||||
}
|
||||
return 0;
|
||||
|
@ -439,9 +440,9 @@ struct query_methods send_code_methods = {
|
|||
};
|
||||
|
||||
void do_send_code (struct telegram *instance, const char *user) {
|
||||
info ("do_send_code()\n");
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
|
||||
logprintf ("sending code\n");
|
||||
instance->suser = tstrdup (user);
|
||||
instance->want_dc_num = 0;
|
||||
clear_packet (mtp);
|
||||
|
@ -453,14 +454,14 @@ void do_send_code (struct telegram *instance, const char *user) {
|
|||
out_string (mtp, TG_APP_HASH);
|
||||
out_string (mtp, "en");
|
||||
|
||||
logprintf ("send_code: dc_num = %d\n", instance->auth.dc_working_num);
|
||||
debug ("send_code: dc_num = %d\n", instance->auth.dc_working_num);
|
||||
send_query (instance, telegram_get_working_dc(instance), mtp->packet_ptr - mtp->packet_buffer, mtp->packet_buffer, &send_code_methods, instance);
|
||||
if (instance->session_state == STATE_PHONE_NOT_REGISTERED) {
|
||||
telegram_change_state(instance, STATE_PHONE_CODE_REQUESTED, NULL);
|
||||
} else if (instance->session_state == STATE_CLIENT_NOT_REGISTERED) {
|
||||
telegram_change_state(instance, STATE_CLIENT_CODE_REQUESTED, NULL);
|
||||
} else {
|
||||
logprintf("do_send_code() Invalid State %d, erroring\n", instance->session_state);
|
||||
debug("do_send_code() Invalid State %d, erroring\n", instance->session_state);
|
||||
telegram_change_state(instance, STATE_ERROR, NULL);
|
||||
}
|
||||
// TODO: Phone Code Hash
|
||||
|
@ -475,7 +476,7 @@ int phone_call_on_answer (struct query *q UU) {
|
|||
}
|
||||
|
||||
int phone_call_on_error (struct query *q UU, int error_code, int l, char *error) {
|
||||
logprintf ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
debug ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
assert (0);
|
||||
return 0;
|
||||
}
|
||||
|
@ -488,7 +489,7 @@ struct query_methods phone_call_methods = {
|
|||
void do_phone_call (struct telegram *instance, const char *user) {
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
|
||||
logprintf ("calling user\n");
|
||||
debug ("calling user\n");
|
||||
instance->suser = tstrdup (user);
|
||||
instance->want_dc_num = 0;
|
||||
clear_packet (mtp);
|
||||
|
@ -497,7 +498,7 @@ void do_phone_call (struct telegram *instance, const char *user) {
|
|||
out_string (mtp, user);
|
||||
out_string (mtp, instance->phone_code_hash);
|
||||
|
||||
logprintf ("do_phone_call: dc_num = %d\n", instance->auth.dc_working_num);
|
||||
info ("do_phone_call: dc_num = %d\n", instance->auth.dc_working_num);
|
||||
send_query (instance, telegram_get_working_dc(instance), mtp->packet_ptr - mtp->packet_buffer, mtp->packet_buffer, &phone_call_methods, instance);
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -516,7 +517,7 @@ int check_phone_on_answer (struct query *q UU) {
|
|||
fetch_bool (mtp);
|
||||
|
||||
assert (mtp->connection->instance->session_state == STATE_CONFIG_RECEIVED);
|
||||
logprintf ("check_phone_result=%d\n", check_phone_result);
|
||||
debug ("check_phone_result=%d\n", check_phone_result);
|
||||
telegram_change_state (mtp->connection->instance,
|
||||
check_phone_result ? STATE_CLIENT_NOT_REGISTERED : STATE_PHONE_NOT_REGISTERED, NULL);
|
||||
return 0;
|
||||
|
@ -542,7 +543,7 @@ int check_phone_on_error (struct query *q UU, int error_code, int l, char *error
|
|||
|
||||
//check_phone_result = 1;
|
||||
} else {
|
||||
logprintf ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
failure ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
telegram_change_state(instance, STATE_ERROR, error);
|
||||
}
|
||||
telegram_change_state(instance,
|
||||
|
@ -577,7 +578,7 @@ int nearest_dc_on_answer (struct query *q UU) {
|
|||
|
||||
assert (fetch_int (mtp) == (int)CODE_nearest_dc);
|
||||
char *country = fetch_str_dup (mtp);
|
||||
logprintf ("Server thinks that you are in %s\n", country);
|
||||
debug ("Server thinks that you are in %s\n", country);
|
||||
fetch_int (mtp); // this_dc
|
||||
instance->nearest_dc_num = fetch_int (mtp);
|
||||
assert (instance->nearest_dc_num >= 0);
|
||||
|
@ -585,7 +586,7 @@ int nearest_dc_on_answer (struct query *q UU) {
|
|||
}
|
||||
|
||||
int fail_on_error (struct query *q UU, int error_code UU, int l UU, char *error UU) {
|
||||
fprintf (stderr, "error #%d: %.*s\n", error_code, l, error);
|
||||
fatal ("error #%d: %.*s\n", error_code, l, error);
|
||||
assert (0);
|
||||
return 0;
|
||||
}
|
||||
|
@ -610,7 +611,7 @@ void do_get_nearest_dc (struct telegram *instance) {
|
|||
/* {{{ Sign in / Sign up */
|
||||
|
||||
int sign_in_on_answer (struct query *q) {
|
||||
logprintf ("sign_in_on_answer()\n");
|
||||
info ("sign_in_on_answer()\n");
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
struct telegram *instance = mtp->connection->instance;
|
||||
|
||||
|
@ -622,7 +623,7 @@ int sign_in_on_answer (struct query *q) {
|
|||
instance->our_id = get_peer_id (instance->User.id);
|
||||
bl_do_set_our_id (mtp->bl, mtp, instance->our_id);
|
||||
}
|
||||
logprintf ( "telegram: authorized successfully: name = '%s %s', phone = '%s', expires = %d\n",
|
||||
debug ( "telegram: authorized successfully: name = '%s %s', phone = '%s', expires = %d\n",
|
||||
instance->User.first_name, instance->User.last_name, instance->User.phone, (int)(expires - get_double_time ()));
|
||||
DC_working->has_auth = 1;
|
||||
|
||||
|
@ -632,9 +633,9 @@ int sign_in_on_answer (struct query *q) {
|
|||
}
|
||||
|
||||
int sign_in_on_error (struct query *q UU, int error_code, int l, char *error) {
|
||||
logprintf ("sign_in_on_error()\n");
|
||||
info ("sign_in_on_error()\n");
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
logprintf ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
failure ( "error_code = %d, error = %.*s\n", error_code, l, error);
|
||||
telegram_change_state (mtp->connection->instance, STATE_CLIENT_CODE_NOT_ENTERED, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
@ -645,7 +646,7 @@ struct query_methods sign_in_methods = {
|
|||
};
|
||||
|
||||
void do_send_code_result (struct telegram *instance, const char *code) {
|
||||
logprintf ("do_send_code_result()\n");
|
||||
info ("do_send_code_result()\n");
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
assert (instance->session_state == STATE_CLIENT_CODE_NOT_ENTERED);
|
||||
|
||||
|
@ -795,7 +796,7 @@ void encr_finish (struct mtproto_connection *mtp, struct secret_chat *E) {
|
|||
int msg_send_encr_on_answer (struct query *q UU) {
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
assert (fetch_int (mtp) == CODE_messages_sent_encrypted_message);
|
||||
logprintf ("Sent\n");
|
||||
debug ("Sent\n");
|
||||
struct message *M = q->extra;
|
||||
//M->date = fetch_int (mtp);
|
||||
fetch_int (mtp);
|
||||
|
@ -846,14 +847,14 @@ int msg_send_on_answer (struct query *q UU) {
|
|||
}
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("Link with user ");
|
||||
debug ("Link with user ");
|
||||
//print_user_name (U->id, (void *)U);
|
||||
logprintf (" changed\n");
|
||||
debug (" changed\n");
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
}
|
||||
}
|
||||
logprintf ("Sent: id = %d\n", id);
|
||||
debug ("Sent: id = %d\n", id);
|
||||
bl_do_set_message_sent (mtp->bl, mtp, M);
|
||||
return 0;
|
||||
}
|
||||
|
@ -861,7 +862,7 @@ int msg_send_on_answer (struct query *q UU) {
|
|||
int msg_send_on_error (struct query *q, int error_code, int error_len, char *error) {
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
|
||||
logprintf ( "error for query #%lld: #%d :%.*s\n", q->msg_id, error_code, error_len, error);
|
||||
debug ( "error for query #%lld: #%d :%.*s\n", q->msg_id, error_code, error_len, error);
|
||||
struct message *M = q->extra;
|
||||
bl_do_delete_msg (mtp->bl, mtp, M);
|
||||
return 0;
|
||||
|
@ -924,17 +925,17 @@ void do_send_message (struct telegram *instance, peer_id_t id, const char *msg,
|
|||
if (get_peer_type (id) == PEER_ENCR_CHAT) {
|
||||
peer_t *P = user_chat_get (mtp->bl, id);
|
||||
if (!P) {
|
||||
logprintf ("Can not send to unknown encrypted chat\n");
|
||||
warning ("Can not send to unknown encrypted chat\n");
|
||||
return;
|
||||
}
|
||||
if (P->encr_chat.state != sc_ok) {
|
||||
logprintf ("Chat is not yet initialized\n");
|
||||
warning ("Chat is not yet initialized\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
long long t;
|
||||
secure_random (&t, 8);
|
||||
logprintf ("t = %lld, len = %d\n", t, len);
|
||||
debug ("t = %lld, len = %d\n", t, len);
|
||||
bl_do_send_message_text (mtp->bl, mtp, t, instance->our_id, get_peer_type (id), get_peer_id (id), time (0), len, msg);
|
||||
struct message *M = message_get (mtp->bl, t);
|
||||
assert (M);
|
||||
|
@ -947,7 +948,7 @@ void do_send_message (struct telegram *instance, peer_id_t id, const char *msg,
|
|||
void do_send_text (struct telegram *instance, peer_id_t id, char *file_name) {
|
||||
int fd = open (file_name, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
logprintf ("No such file '%s'\n", file_name);
|
||||
warning ("No such file '%s'\n", file_name);
|
||||
tfree_str (file_name);
|
||||
return;
|
||||
}
|
||||
|
@ -955,7 +956,7 @@ void do_send_text (struct telegram *instance, peer_id_t id, char *file_name) {
|
|||
int x = read (fd, buf, (1 << 20) + 1);
|
||||
assert (x >= 0);
|
||||
if (x == (1 << 20) + 1) {
|
||||
logprintf ("Too big file '%s'\n", file_name);
|
||||
warning ("Too big file '%s'\n", file_name);
|
||||
tfree_str (file_name);
|
||||
close (fd);
|
||||
} else {
|
||||
|
@ -1022,12 +1023,12 @@ void do_mark_read (struct telegram *instance, peer_id_t id) {
|
|||
|
||||
peer_t *P = user_chat_get (mtp->bl, id);
|
||||
if (!P) {
|
||||
logprintf ("Unknown peer\n");
|
||||
debug ("Unknown peer\n");
|
||||
return;
|
||||
}
|
||||
if (get_peer_type (id) == PEER_USER || get_peer_type (id) == PEER_CHAT) {
|
||||
if (!P->last) {
|
||||
logprintf ("Unknown last peer message\n");
|
||||
debug ("Unknown last peer message\n");
|
||||
return;
|
||||
}
|
||||
do_messages_mark_read (instance, id, P->last->id);
|
||||
|
@ -1060,7 +1061,7 @@ int get_history_on_answer (struct query *q UU) {
|
|||
int x = fetch_int (mtp);
|
||||
if (x == (int)CODE_messages_messages_slice) {
|
||||
fetch_int (mtp);
|
||||
logprintf ("...\n");
|
||||
debug ("...\n");
|
||||
} else {
|
||||
assert (x == (int)CODE_messages_messages);
|
||||
}
|
||||
|
@ -1191,15 +1192,15 @@ int get_dialogs_on_answer (struct query *q UU) {
|
|||
switch (get_peer_type (plist[i])) {
|
||||
case PEER_USER:
|
||||
UC = user_chat_get (mtp->bl, plist[i]);
|
||||
logprintf ("User ");
|
||||
debug ("User ");
|
||||
//print_user_name (plist[i], UC);
|
||||
logprintf (": %d unread\n", dlist[2 * i + 1]);
|
||||
debug (": %d unread\n", dlist[2 * i + 1]);
|
||||
break;
|
||||
case PEER_CHAT:
|
||||
UC = user_chat_get (mtp->bl, plist[i]);
|
||||
logprintf ("Chat ");
|
||||
debug ("Chat ");
|
||||
//print_chat_name (plist[i], UC);
|
||||
logprintf (": %d unread\n", dlist[2 * i + 1]);
|
||||
debug (": %d unread\n", dlist[2 * i + 1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1380,7 +1381,7 @@ void send_part (struct telegram *instance, struct send_file *f) {
|
|||
}
|
||||
out_cstring (mtp, buf, x);
|
||||
if (verbosity >= 2) {
|
||||
logprintf ("offset=%lld size=%lld\n", f->offset, f->size);
|
||||
debug ("offset=%lld size=%lld\n", f->offset, f->size);
|
||||
}
|
||||
if (f->offset == f->size) {
|
||||
close (f->fd);
|
||||
|
@ -1549,7 +1550,7 @@ void send_file_thumb (struct telegram *instance, struct send_file *f) {
|
|||
void do_send_photo (struct telegram *instance, int type, peer_id_t to_id, char *file_name) {
|
||||
int fd = open (file_name, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
logprintf ("No such file '%s'\n", file_name);
|
||||
warning ("No such file '%s'\n", file_name);
|
||||
tfree_str (file_name);
|
||||
return;
|
||||
}
|
||||
|
@ -1557,7 +1558,7 @@ void do_send_photo (struct telegram *instance, int type, peer_id_t to_id, char *
|
|||
fstat (fd, &buf);
|
||||
long long size = buf.st_size;
|
||||
if (size <= 0) {
|
||||
logprintf ("File has zero length\n");
|
||||
debug ("File has zero length\n");
|
||||
tfree_str (file_name);
|
||||
close (fd);
|
||||
return;
|
||||
|
@ -1575,7 +1576,7 @@ void do_send_photo (struct telegram *instance, int type, peer_id_t to_id, char *
|
|||
|
||||
if (f->part_size > (512 << 10)) {
|
||||
close (fd);
|
||||
logprintf ("Too big file. Maximal supported size is %d.\n", (512 << 10) * 1000);
|
||||
failure ("Too big file. Maximal supported size is %d.\n", (512 << 10) * 1000);
|
||||
tfree (f, sizeof (*f));
|
||||
tfree_str (file_name);
|
||||
return;
|
||||
|
@ -1640,7 +1641,7 @@ void do_forward_message (struct telegram *instance, peer_id_t id, int n) {
|
|||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
if (get_peer_type (id) == PEER_ENCR_CHAT) {
|
||||
logprintf ("Can not forward messages from secret chat\n");
|
||||
warning ("Can not forward messages from secret chat\n");
|
||||
return;
|
||||
}
|
||||
clear_packet (mtp);
|
||||
|
@ -1702,21 +1703,21 @@ void print_chat_info (struct chat *C) {
|
|||
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("Chat ");
|
||||
debug ("Chat ");
|
||||
//print_chat_name (U->id, U);
|
||||
logprintf (" members:\n");
|
||||
debug (" members:\n");
|
||||
int i;
|
||||
for (i = 0; i < C->user_list_size; i++) {
|
||||
logprintf ("\t\t");
|
||||
debug ("\t\t");
|
||||
//print_user_name (MK_USER (C->user_list[i].user_id), user_chat_get (mtp->bl, MK_USER (C->user_list[i].user_id)));
|
||||
logprintf (" invited by ");
|
||||
debug (" invited by ");
|
||||
//print_user_name (MK_USER (C->user_list[i].inviter_id), user_chat_get (mtp->bl, MK_USER (C->user_list[i].inviter_id)));
|
||||
logprintf (" at ");
|
||||
debug (" at ");
|
||||
//print_date_full (C->user_list[i].date);
|
||||
if (C->user_list[i].user_id == C->admin_id) {
|
||||
logprintf (" admin");
|
||||
debug (" admin");
|
||||
}
|
||||
logprintf ("\n");
|
||||
debug ("\n");
|
||||
}
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
|
@ -1734,13 +1735,13 @@ struct query_methods chat_info_methods = {
|
|||
};
|
||||
|
||||
void do_get_chat_info (struct telegram *instance, peer_id_t id) {
|
||||
logprintf ("do_get_chat_info (peer_id=%d)", id.id);
|
||||
debug ("do_get_chat_info (peer_id=%d)", id.id);
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
if (offline_mode) {
|
||||
peer_t *C = user_chat_get (mtp->bl, id);
|
||||
if (!C) {
|
||||
logprintf ("No such chat\n");
|
||||
warning ("No such chat\n");
|
||||
} else {
|
||||
//print_chat_info (&C->chat);
|
||||
}
|
||||
|
@ -1762,17 +1763,17 @@ void print_user_info (struct user *U) {
|
|||
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("User ");
|
||||
debug ("User ");
|
||||
//print_user_name (U->id, C);
|
||||
logprintf (":\n");
|
||||
logprintf ("\treal name: %s %s\n", U->real_first_name, U->real_last_name);
|
||||
logprintf ("\tphone: %s\n", U->phone);
|
||||
debug (":\n");
|
||||
debug ("\treal name: %s %s\n", U->real_first_name, U->real_last_name);
|
||||
debug ("\tphone: %s\n", U->phone);
|
||||
if (U->status.online > 0) {
|
||||
logprintf ("\tonline\n");
|
||||
debug ("\tonline\n");
|
||||
} else {
|
||||
logprintf ("\toffline (was online ");
|
||||
debug ("\toffline (was online ");
|
||||
//print_date_full (U->status.when);
|
||||
logprintf (")\n");
|
||||
debug (")\n");
|
||||
}
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
|
@ -1798,7 +1799,7 @@ struct query_methods user_info_methods = {
|
|||
};
|
||||
|
||||
void do_get_user_info (struct telegram *instance, peer_id_t id, int showInfo) {
|
||||
logprintf ("do_get_user_info\n");
|
||||
info ("do_get_user_info\n");
|
||||
struct show_info_extra *extra = talloc(sizeof(struct show_info_extra));
|
||||
extra->show_info = showInfo;
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
|
@ -1816,7 +1817,7 @@ void do_get_user_info (struct telegram *instance, peer_id_t id, int showInfo) {
|
|||
out_int (mtp, get_peer_id (id));
|
||||
}
|
||||
send_query (instance, DC_working, mtp->packet_ptr - mtp->packet_buffer, mtp->packet_buffer, &user_info_methods, extra);
|
||||
logprintf ("do_get_user_info ready\n");
|
||||
debug ("do_get_user_info ready\n");
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -1859,11 +1860,11 @@ void end_load (struct telegram *instance, struct download *D) {
|
|||
instance->cur_downloaded_bytes -= D->size;
|
||||
//update_prompt ();
|
||||
close (D->fd);
|
||||
logprintf ("Done: %s\n", D->name);
|
||||
debug ("Done: %s\n", D->name);
|
||||
event_download_finished_handler(instance, D);
|
||||
instance->dl_curr = 0;
|
||||
if (D->dc != telegram_get_working_dc(instance)->id) {
|
||||
logprintf ("%d Not the working dc %d, closing...\n", D->dc,
|
||||
debug ("%d Not the working dc %d, closing...\n", D->dc,
|
||||
telegram_get_working_dc(instance)->id);
|
||||
}
|
||||
if (D->iv) {
|
||||
|
@ -1939,7 +1940,7 @@ void load_next_part (struct telegram *instance, struct download *D) {
|
|||
l = tsnprintf (buf, sizeof (buf), "%s/download_%lld", instance->download_path, D->id);
|
||||
}
|
||||
if (l >= (int) sizeof (buf)) {
|
||||
logprintf ("Download filename is too long");
|
||||
fatal ("Download filename is too long");
|
||||
exit (1);
|
||||
}
|
||||
D->name = tstrdup (buf);
|
||||
|
@ -1949,7 +1950,7 @@ void load_next_part (struct telegram *instance, struct download *D) {
|
|||
if (D->offset >= D->size) {
|
||||
instance->cur_downloading_bytes += D->size;
|
||||
instance->cur_downloaded_bytes += D->offset;
|
||||
logprintf ("Already downloaded\n");
|
||||
info ("Already downloaded\n");
|
||||
end_load (instance, D);
|
||||
return;
|
||||
}
|
||||
|
@ -1959,6 +1960,7 @@ void load_next_part (struct telegram *instance, struct download *D) {
|
|||
instance->cur_downloaded_bytes += D->offset;
|
||||
//update_prompt ();
|
||||
}
|
||||
info ("do_upload_get_file()\n");
|
||||
clear_packet (mtp);
|
||||
out_int (mtp, CODE_upload_get_file);
|
||||
if (!D->id) {
|
||||
|
@ -1988,7 +1990,7 @@ void load_next_part (struct telegram *instance, struct download *D) {
|
|||
|
||||
void do_load_photo_size (struct telegram *instance, struct photo_size *P, void *extra) {
|
||||
if (!P->loc.dc) {
|
||||
logprintf ("Bad video thumb\n");
|
||||
failure ("Bad video thumb\n");
|
||||
return;
|
||||
}
|
||||
assert (P);
|
||||
|
@ -2144,6 +2146,7 @@ struct query_methods export_auth_methods = {
|
|||
};
|
||||
|
||||
void do_export_auth (struct telegram *instance, int num, void (*cb)(char *export_auth_str, int len, void *extra), void *extra) {
|
||||
info ("do_export_auth(num=%d)\n", num);
|
||||
instance->export_auth_str = 0;
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
clear_packet (mtp);
|
||||
|
@ -2186,7 +2189,7 @@ struct query_methods import_auth_methods = {
|
|||
};
|
||||
|
||||
void do_import_auth (struct telegram *instance, int num, void (*cb)(void *extra), void *extra) {
|
||||
logprintf ("do_import_auth(num=%d, our_id=%d, export_auth_str=%s)\n", num, instance->our_id, instance->export_auth_str);
|
||||
info ("do_import_auth(num=%d, our_id=%d, export_auth_str=)\n", num, instance->our_id);
|
||||
struct import_info *info = talloc0(sizeof (struct import_info));
|
||||
info->cb = cb;
|
||||
info->extra = extra;
|
||||
|
@ -2214,9 +2217,9 @@ int add_contact_on_answer (struct query *q UU) {
|
|||
assert (fetch_int (mtp) == CODE_vector);
|
||||
int n = fetch_int (mtp);
|
||||
if (n > 0) {
|
||||
logprintf ("Added successfully");
|
||||
debug ("Added successfully");
|
||||
} else {
|
||||
logprintf ("Not added");
|
||||
debug ("Not added");
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < n ; i++) {
|
||||
|
@ -2230,27 +2233,27 @@ int add_contact_on_answer (struct query *q UU) {
|
|||
struct user *U = fetch_alloc_user (mtp);
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("User #%d: ", get_peer_id (U->id));
|
||||
debug ("User #%d: ", get_peer_id (U->id));
|
||||
//print_user_name (U->id, (peer_t *)U);
|
||||
//push_color (COLOR_GREEN);
|
||||
logprintf (" (");
|
||||
logprintf ("%s", U->print_name);
|
||||
debug (" (");
|
||||
debug ("%s", U->print_name);
|
||||
if (U->phone) {
|
||||
logprintf (" ");
|
||||
logprintf ("%s", U->phone);
|
||||
debug (" ");
|
||||
debug ("%s", U->phone);
|
||||
}
|
||||
logprintf (") ");
|
||||
debug (") ");
|
||||
//pop_color ();
|
||||
if (U->status.online > 0) {
|
||||
logprintf ("online\n");
|
||||
debug ("online\n");
|
||||
} else {
|
||||
if (U->status.online < 0) {
|
||||
logprintf ("offline. Was online ");
|
||||
debug ("offline. Was online ");
|
||||
//print_date_full (U->status.when);
|
||||
} else {
|
||||
logprintf ("offline permanent");
|
||||
debug ("offline permanent");
|
||||
}
|
||||
logprintf ("\n");
|
||||
debug ("\n");
|
||||
}
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
|
@ -2293,7 +2296,7 @@ void do_msg_search (struct telegram *instance, peer_id_t id, int from, int to, i
|
|||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
if (get_peer_type (id) == PEER_ENCR_CHAT) {
|
||||
logprintf ("Can not search in secure chat\n");
|
||||
warning ("Can not search in secure chat\n");
|
||||
return;
|
||||
}
|
||||
clear_packet (mtp);
|
||||
|
@ -2332,11 +2335,11 @@ int contacts_search_on_answer (struct query *q UU) {
|
|||
//push_color (COLOR_YELLOW);
|
||||
for (i = 0; i < n; i++) {
|
||||
struct user *U = fetch_alloc_user (mtp);
|
||||
logprintf ("User ");
|
||||
debug ("User ");
|
||||
//push_color (COLOR_RED);
|
||||
logprintf ("%s %s", U->first_name, U->last_name);
|
||||
debug ("%s %s", U->first_name, U->last_name);
|
||||
//pop_color ();
|
||||
logprintf (". Phone %s\n", U->phone);
|
||||
debug (". Phone %s\n", U->phone);
|
||||
}
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
|
@ -2367,17 +2370,17 @@ int send_encr_accept_on_answer (struct query *q UU) {
|
|||
if (E->state == sc_ok) {
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("Encrypted connection with ");
|
||||
debug ("Encrypted connection with ");
|
||||
////print_encr_chat_name (E->id, (void *)E);
|
||||
logprintf (" established\n");
|
||||
debug (" established\n");
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
} else {
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("Encrypted connection with ");
|
||||
debug ("Encrypted connection with ");
|
||||
////print_encr_chat_name (E->id, (void *)E);
|
||||
logprintf (" failed\n");
|
||||
debug (" failed\n");
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
}
|
||||
|
@ -2390,17 +2393,17 @@ int send_encr_request_on_answer (struct query *q UU) {
|
|||
if (E->state == sc_deleted) {
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("Encrypted connection with ");
|
||||
debug ("Encrypted connection with ");
|
||||
//print_encr_chat_name (E->id, (void *)E);
|
||||
logprintf (" can not be established\n");
|
||||
debug (" can not be established\n");
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
} else {
|
||||
//print_start ();
|
||||
//push_color (COLOR_YELLOW);
|
||||
logprintf ("Establishing connection with ");
|
||||
debug ("Establishing connection with ");
|
||||
//print_encr_chat_name (E->id, (void *)E);
|
||||
logprintf ("\n");
|
||||
debug ("\n");
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
|
||||
|
@ -2512,13 +2515,13 @@ void do_create_keys_end (struct telegram *instance, struct secret_chat *U) {
|
|||
sha1 ((void *)U->key, 256, sha_buffer);
|
||||
long long k = *(long long *)(sha_buffer + 12);
|
||||
if (k != U->key_fingerprint) {
|
||||
logprintf ("version = %d\n", instance->encr_param_version);
|
||||
debug ("version = %d\n", instance->encr_param_version);
|
||||
hexdump ((void *)U->nonce, (void *)(U->nonce + 256));
|
||||
hexdump ((void *)U->g_key, (void *)(U->g_key + 256));
|
||||
hexdump ((void *)U->key, (void *)(U->key + 64));
|
||||
hexdump ((void *)t, (void *)(t + 256));
|
||||
hexdump ((void *)sha_buffer, (void *)(sha_buffer + 20));
|
||||
logprintf ("!!Key fingerprint mismatch (my 0x%llx 0x%llx)\n", (unsigned long long)k, (unsigned long long)U->key_fingerprint);
|
||||
failure ("!!Key fingerprint mismatch (my 0x%llx 0x%llx)\n", (unsigned long long)k, (unsigned long long)U->key_fingerprint);
|
||||
U->state = sc_deleted;
|
||||
}
|
||||
|
||||
|
@ -2688,7 +2691,7 @@ int get_state_on_answer (struct query *q UU) {
|
|||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
struct telegram *instance = q->extra;
|
||||
|
||||
logprintf("get_state_on_answer()\n");
|
||||
debug("get_state_on_answer()\n");
|
||||
assert (fetch_int (mtp) == (int)CODE_updates_state);
|
||||
bl_do_set_pts (mtp->bl, mtp, fetch_int (mtp));
|
||||
bl_do_set_qts (mtp->bl, mtp, fetch_int (mtp));
|
||||
|
@ -2704,7 +2707,7 @@ int get_difference_on_answer (struct query *q UU) {
|
|||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
struct telegram *instance = q->extra;
|
||||
|
||||
logprintf("get_difference_on_answer()\n");
|
||||
debug("get_difference_on_answer()\n");
|
||||
instance->get_difference_active = 0;
|
||||
unsigned x = fetch_int (mtp);
|
||||
if (x == CODE_updates_difference_empty) {
|
||||
|
@ -2738,13 +2741,13 @@ int get_difference_on_answer (struct query *q UU) {
|
|||
}
|
||||
assert (fetch_int (mtp) == CODE_vector);
|
||||
n = fetch_int (mtp);
|
||||
logprintf("Found %d chats\n", n);
|
||||
debug("Found %d chats\n", n);
|
||||
for (i = 0; i < n; i++) {
|
||||
fetch_alloc_chat (mtp);
|
||||
}
|
||||
assert (fetch_int (mtp) == CODE_vector);
|
||||
n = fetch_int (mtp);
|
||||
logprintf("Found %d users\n", n);
|
||||
debug("Found %d users\n", n);
|
||||
for (i = 0; i < n; i++) {
|
||||
fetch_alloc_user (mtp);
|
||||
}
|
||||
|
@ -2754,7 +2757,7 @@ int get_difference_on_answer (struct query *q UU) {
|
|||
bl_do_set_date (mtp->bl, mtp, fetch_int (mtp));
|
||||
bl_do_set_seq (mtp->bl, mtp, fetch_int (mtp));
|
||||
instance->unread_messages = fetch_int (mtp);
|
||||
logprintf ("UNREAD MESSAGES: %d\n", ml_pos);
|
||||
debug ("UNREAD MESSAGES: %d\n", ml_pos);
|
||||
//write_state_file ();
|
||||
for (i = 0; i < ml_pos; i++) {
|
||||
event_update_new_message (instance, instance->ML[i]);
|
||||
|
@ -2781,7 +2784,7 @@ struct query_methods get_difference_methods = {
|
|||
};
|
||||
|
||||
void do_get_difference (struct telegram *instance, int sync_from_start) {
|
||||
logprintf ("do_get_difference()\n");
|
||||
info ("do_get_difference()\n");
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
|
||||
|
@ -2789,7 +2792,7 @@ void do_get_difference (struct telegram *instance, int sync_from_start) {
|
|||
//difference_got = 0;
|
||||
clear_packet (mtp);
|
||||
do_insert_header (mtp);
|
||||
logprintf("do_get_difference(pts:%d, last_date:%d, qts: %d)\n", instance->proto.pts, instance->proto.last_date, instance->proto.qts);
|
||||
debug("do_get_difference(pts:%d, last_date:%d, qts: %d)\n", instance->proto.pts, instance->proto.last_date, instance->proto.qts);
|
||||
if (instance->proto.seq > 0 || sync_from_start) {
|
||||
if (instance->proto.pts == 0) { instance->proto.pts = 1; }
|
||||
if (instance->proto.qts == 0) { instance->proto.qts = 1; }
|
||||
|
@ -2801,7 +2804,7 @@ void do_get_difference (struct telegram *instance, int sync_from_start) {
|
|||
out_int (mtp, instance->proto.qts);
|
||||
send_query (instance, DC_working, mtp->packet_ptr - mtp->packet_buffer, mtp->packet_buffer, &get_difference_methods, instance);
|
||||
} else {
|
||||
logprintf("do_updates_get_state()\n",
|
||||
debug("do_updates_get_state()\n",
|
||||
instance->proto.pts, instance->proto.last_date, instance->proto.qts);
|
||||
out_int (mtp, CODE_updates_get_state);
|
||||
send_query (instance, DC_working, mtp->packet_ptr - mtp->packet_buffer, mtp->packet_buffer, &get_state_methods, instance);
|
||||
|
@ -2817,7 +2820,7 @@ void do_visualize_key (struct binlog *bl, peer_id_t id) {
|
|||
peer_t *P = user_chat_get (bl, id);
|
||||
assert (P);
|
||||
if (P->encr_chat.state != sc_ok) {
|
||||
logprintf ("Chat is not initialized yet\n");
|
||||
warning ("Chat is not initialized yet\n");
|
||||
return;
|
||||
}
|
||||
unsigned char buf[20];
|
||||
|
@ -2830,12 +2833,12 @@ void do_visualize_key (struct binlog *bl, peer_id_t id) {
|
|||
for (j = 0; j < 4; j ++) {
|
||||
////push_color (colors[x & 3]);
|
||||
////push_color (COLOR_INVERSE);
|
||||
//logprintf (" ");
|
||||
//debug (" ");
|
||||
////pop_color ();
|
||||
////pop_color ();
|
||||
x = x >> 2;
|
||||
}
|
||||
if (i & 1) { logprintf ("\n"); }
|
||||
if (i & 1) { debug ("\n"); }
|
||||
}
|
||||
//print_end ();
|
||||
}
|
||||
|
@ -2848,7 +2851,7 @@ int get_suggested_on_answer (struct query *q UU) {
|
|||
assert (fetch_int (mtp) == CODE_contacts_suggested);
|
||||
assert (fetch_int (mtp) == CODE_vector);
|
||||
int n = fetch_int (mtp);
|
||||
logprintf ("n = %d\n", n);
|
||||
debug ("n = %d\n", n);
|
||||
assert (n <= 200);
|
||||
int l[400];
|
||||
int i;
|
||||
|
@ -2866,7 +2869,7 @@ int get_suggested_on_answer (struct query *q UU) {
|
|||
peer_t *U = (void *)fetch_alloc_user (mtp);
|
||||
assert (get_peer_id (U->id) == l[2 * i]);
|
||||
//print_user_name (U->id, U);
|
||||
logprintf (" phone %s: %d mutual friends\n", U->user.phone, l[2 * i + 1]);
|
||||
debug (" phone %s: %d mutual friends\n", U->user.phone, l[2 * i + 1]);
|
||||
}
|
||||
//pop_color ();
|
||||
//print_end ();
|
||||
|
@ -2894,6 +2897,7 @@ struct query_methods add_user_to_chat_methods = {
|
|||
};
|
||||
|
||||
void do_add_user_to_chat (struct telegram *instance, peer_id_t chat_id, peer_id_t id, int limit) {
|
||||
info ("do_add_user_to_chat()\n");
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
clear_packet (mtp);
|
||||
|
@ -2915,6 +2919,7 @@ void do_add_user_to_chat (struct telegram *instance, peer_id_t chat_id, peer_id_
|
|||
}
|
||||
|
||||
void do_del_user_from_chat (struct telegram *instance, peer_id_t chat_id, peer_id_t id) {
|
||||
info ("do_del_user_from_chat()\n");
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
clear_packet (mtp);
|
||||
|
@ -2939,11 +2944,12 @@ void do_del_user_from_chat (struct telegram *instance, peer_id_t chat_id, peer_i
|
|||
char *create_print_name (struct binlog *bl, peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
|
||||
|
||||
void do_create_secret_chat (struct telegram *instance, peer_id_t id) {
|
||||
info ("do_create_secret_chat()\n");
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
assert (get_peer_type (id) == PEER_USER);
|
||||
peer_t *U = user_chat_get (mtp->bl, id);
|
||||
if (!U) {
|
||||
logprintf ("Can not create chat with unknown user\n");
|
||||
warning ("Can not create chat with unknown user\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2957,11 +2963,12 @@ struct query_methods create_group_chat_methods = {
|
|||
};
|
||||
|
||||
void do_create_group_chat (struct telegram *instance, peer_id_t id, char *chat_topic) {
|
||||
info ("do_create_group_chat()\n");
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
assert (get_peer_type (id) == PEER_USER);
|
||||
peer_t *U = user_chat_get (mtp->bl, id);
|
||||
if (!U) {
|
||||
logprintf ("Can not create chat with unknown user\n");
|
||||
warning ("Can not create chat with unknown user\n");
|
||||
return;
|
||||
}
|
||||
clear_packet (mtp);
|
||||
|
@ -2990,7 +2997,7 @@ int delete_msg_on_answer (struct query *q UU) {
|
|||
assert (fetch_int (mtp) == CODE_vector);
|
||||
int n = fetch_int (mtp);
|
||||
fetch_skip (mtp, n);
|
||||
logprintf ("Deleted %d messages\n", n);
|
||||
debug ("Deleted %d messages\n", n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2999,6 +3006,7 @@ struct query_methods delete_msg_methods = {
|
|||
};
|
||||
|
||||
void do_delete_msg (struct telegram *instance, long long id) {
|
||||
info ("do_delete_msg()\n");
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
clear_packet (mtp);
|
||||
|
@ -3018,7 +3026,7 @@ int restore_msg_on_answer (struct query *q UU) {
|
|||
assert (fetch_int (mtp) == CODE_vector);
|
||||
int n = fetch_int (mtp);
|
||||
fetch_skip (mtp, n);
|
||||
logprintf ("Restored %d messages\n", n);
|
||||
debug ("Restored %d messages\n", n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3027,6 +3035,7 @@ struct query_methods restore_msg_methods = {
|
|||
};
|
||||
|
||||
void do_restore_msg (struct telegram *instance, long long id) {
|
||||
info ("do_restore_msg()\n");
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
clear_packet (mtp);
|
||||
|
@ -3049,6 +3058,7 @@ struct query_methods update_status_methods = {
|
|||
};
|
||||
|
||||
void do_update_status (struct telegram *instance, int online UU) {
|
||||
info ("do_update_status()\n");
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
clear_packet (mtp);
|
||||
|
@ -3067,6 +3077,7 @@ struct query_methods update_typing_methods = {
|
|||
};
|
||||
|
||||
void do_update_typing (struct telegram *instance, peer_id_t id) {
|
||||
info ("do_update_typing()\n");
|
||||
struct dc *DC_working = telegram_get_working_dc(instance);
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
|
||||
|
|
72
structures.c
72
structures.c
|
@ -49,7 +49,7 @@ int verbosity;
|
|||
|
||||
void fetch_skip_photo (struct mtproto_connection *mtp);
|
||||
|
||||
#define code_assert(x) if (!(x)) { logprintf ("Can not parse at line %d\n", __LINE__); assert (0); return -1; }
|
||||
#define code_assert(x) if (!(x)) { fatal ("Can not parse at line %d\n", __LINE__); assert (0); return -1; }
|
||||
#define code_try(x) if ((x) == -1) { return -1; }
|
||||
|
||||
/*
|
||||
|
@ -304,7 +304,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
|
||||
if (x == CODE_encrypted_chat_discarded) {
|
||||
if (new) {
|
||||
logprintf ("Unknown chat in deleted state. May be we forgot something...\n");
|
||||
warning ("Unknown chat in deleted state. May be we forgot something...\n");
|
||||
return;
|
||||
}
|
||||
bl_do_encr_chat_delete (mtp->bl, mtp, U);
|
||||
|
@ -322,7 +322,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
int user_id = fetch_int (mtp) + admin_id - instance->our_id;
|
||||
|
||||
if (x == CODE_encrypted_chat_waiting) {
|
||||
logprintf ("Unknown chat in waiting state. May be we forgot something...\n");
|
||||
warning ("Unknown chat in waiting state. May be we forgot something...\n");
|
||||
return;
|
||||
}
|
||||
if (x == CODE_encrypted_chat_requested || x == CODE_encrypted_chat) {
|
||||
|
@ -332,7 +332,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
|
||||
int l = prefetch_strlen (mtp);
|
||||
char *s = fetch_str (mtp, l);
|
||||
if (l != 256) { logprintf ("l = %d\n", l); }
|
||||
if (l != 256) { debug ("l = %d\n", l); }
|
||||
if (l < 256) {
|
||||
memcpy (g_key + 256 - l, s, l);
|
||||
} else {
|
||||
|
@ -341,7 +341,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
|
||||
/*l = prefetch_strlen (mtp);
|
||||
s = fetch_str (mtp, l);
|
||||
if (l != 256) { logprintf ("l = %d\n", l); }
|
||||
if (l != 256) { debug ("l = %d\n", l); }
|
||||
if (l < 256) {
|
||||
memcpy (nonce + 256 - l, s, l);
|
||||
} else {
|
||||
|
@ -353,7 +353,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
}
|
||||
|
||||
if (x == CODE_encrypted_chat) {
|
||||
logprintf ("Unknown chat in ok state. May be we forgot something...\n");
|
||||
warning ("Unknown chat in ok state. May be we forgot something...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -363,11 +363,11 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
bl_do_set_encr_chat_access_hash (mtp->bl, mtp, U, fetch_long (mtp));
|
||||
bl_do_set_encr_chat_date (mtp->bl, mtp, U, fetch_int (mtp));
|
||||
if (fetch_int (mtp) != U->admin_id) {
|
||||
logprintf ("Changed admin in secret chat. WTF?\n");
|
||||
failure ("Changed admin in secret chat. WTF?\n");
|
||||
return;
|
||||
}
|
||||
if (U->user_id != U->admin_id + fetch_int (mtp) - instance->our_id) {
|
||||
logprintf ("Changed partner in secret chat. WTF?\n");
|
||||
failure ("Changed partner in secret chat. WTF?\n");
|
||||
return;
|
||||
}
|
||||
if (x == CODE_encrypted_chat_waiting) {
|
||||
|
@ -383,7 +383,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
|
||||
int l = prefetch_strlen (mtp);
|
||||
char *s = fetch_str (mtp, l);
|
||||
if (l != 256) { logprintf ("l = %d\n", l); }
|
||||
if (l != 256) { debug ("l = %d\n", l); }
|
||||
if (l < 256) {
|
||||
memcpy (g_key + 256 - l, s, l);
|
||||
} else {
|
||||
|
@ -392,7 +392,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U
|
|||
|
||||
/*l = prefetch_strlen (mtp);
|
||||
s = fetch_str (mtp, l);
|
||||
if (l != 256) { logprintf ("l = %d\n", l); }
|
||||
if (l != 256) { debug ("l = %d\n", l); }
|
||||
if (l < 256) {
|
||||
memcpy (nonce + 256 - l, s, l);
|
||||
} else {
|
||||
|
@ -602,7 +602,7 @@ void fetch_photo_size (struct mtproto_connection *mtp, struct photo_size *S) {
|
|||
unsigned x = fetch_int (mtp);
|
||||
assert (x == CODE_photo_size || x == CODE_photo_cached_size || x == CODE_photo_size_empty);
|
||||
S->type = fetch_str_dup (mtp);
|
||||
logprintf("s->type %s\n", S->type);
|
||||
debug("s->type %s\n", S->type);
|
||||
if (x != CODE_photo_size_empty) {
|
||||
fetch_file_location (mtp, &S->loc);
|
||||
S->w = fetch_int (mtp);
|
||||
|
@ -668,7 +668,7 @@ void fetch_photo (struct mtproto_connection *mtp, struct photo *P) {
|
|||
fetch_geo (mtp, &P->geo);
|
||||
assert (fetch_int (mtp) == CODE_vector);
|
||||
P->sizes_num = fetch_int (mtp);
|
||||
logprintf("sizes_num %d \n", P->sizes_num);
|
||||
debug("sizes_num %d \n", P->sizes_num);
|
||||
P->sizes = talloc (sizeof (struct photo_size) * P->sizes_num);
|
||||
int i;
|
||||
for (i = 0; i < P->sizes_num; i++) {
|
||||
|
@ -784,7 +784,7 @@ void fetch_message_action (struct mtproto_connection *mtp, struct message_action
|
|||
char *s = fetch_str (mtp, l);
|
||||
int l2 = prefetch_strlen (mtp); // checkin
|
||||
char *s2 = fetch_str (mtp, l2);
|
||||
logprintf ("Message action: Created geochat %.*s in address %.*s\n", l, s, l2, s2);
|
||||
debug ("Message action: Created geochat %.*s in address %.*s\n", l, s, l2, s2);
|
||||
}
|
||||
break;
|
||||
case CODE_message_action_geo_chat_checkin:
|
||||
|
@ -951,7 +951,7 @@ void fetch_message_media (struct mtproto_connection *mtp, struct message_media *
|
|||
memcpy (M->data, fetch_str (mtp, M->data_size), M->data_size);
|
||||
break;
|
||||
default:
|
||||
logprintf ("type = 0x%08x\n", M->type);
|
||||
debug ("type = 0x%08x\n", M->type);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
@ -995,7 +995,7 @@ void fetch_skip_message_media (struct mtproto_connection *mtp) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
logprintf ("type = 0x%08x\n", x);
|
||||
debug ("type = 0x%08x\n", x);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
@ -1069,7 +1069,7 @@ void fetch_skip_message_media_encrypted (struct mtproto_connection *mtp) {
|
|||
fetch_skip (mtp, 1);
|
||||
break;
|
||||
default:
|
||||
logprintf ("type = 0x%08x\n", x);
|
||||
debug ("type = 0x%08x\n", x);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
@ -1218,7 +1218,7 @@ void fetch_message_media_encrypted (struct mtproto_connection *mtp, struct messa
|
|||
M->user_id = fetch_int (mtp);
|
||||
break;
|
||||
default:
|
||||
logprintf ("type = 0x%08x\n", x);
|
||||
debug ("type = 0x%08x\n", x);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
@ -1230,7 +1230,7 @@ void fetch_skip_message_action_encrypted (struct mtproto_connection *mtp) {
|
|||
fetch_skip (mtp, 1);
|
||||
break;
|
||||
default:
|
||||
logprintf ("x = 0x%08x\n", x);
|
||||
debug ("x = 0x%08x\n", x);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
@ -1243,7 +1243,7 @@ void fetch_message_action_encrypted (struct mtproto_connection *mtp, struct mess
|
|||
M->ttl = fetch_int (mtp);
|
||||
break;
|
||||
default:
|
||||
logprintf ("x = 0x%08x\n", x);
|
||||
debug ("x = 0x%08x\n", x);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
@ -1389,7 +1389,7 @@ int decrypt_encrypted_message (struct secret_chat *E) {
|
|||
sha1 ((void *)decr_ptr, 4 + x, sha1a_buffer);
|
||||
|
||||
if (memcmp (sha1a_buffer + 4, msg_key, 16)) {
|
||||
logprintf ("Sha1 mismatch\n");
|
||||
failure ("Sha1 mismatch\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -1409,7 +1409,7 @@ void fetch_encrypted_message (struct mtproto_connection *mtp, struct message *M)
|
|||
|
||||
peer_t *P = user_chat_get (bl, chat);
|
||||
if (!P) {
|
||||
logprintf ("Encrypted message to unknown chat. Dropping\n");
|
||||
warning ("Encrypted message to unknown chat. Dropping\n");
|
||||
M->flags |= FLAG_MESSAGE_EMPTY;
|
||||
}
|
||||
|
||||
|
@ -1421,7 +1421,7 @@ void fetch_encrypted_message (struct mtproto_connection *mtp, struct message *M)
|
|||
int ok = 0;
|
||||
if (P) {
|
||||
if (*(long long *)decr_ptr != P->encr_chat.key_fingerprint) {
|
||||
logprintf ("Encrypted message with bad fingerprint to chat %s\n", P->print_name);
|
||||
warning ("Encrypted message with bad fingerprint to chat %s\n", P->print_name);
|
||||
P = 0;
|
||||
}
|
||||
decr_ptr += 2;
|
||||
|
@ -1525,7 +1525,7 @@ static int id_cmp (struct message *M1, struct message *M2) {
|
|||
struct user *fetch_alloc_user (struct mtproto_connection *mtp) {
|
||||
struct binlog *bl = mtp->instance->bl;
|
||||
|
||||
logprintf("fetch_alloc_user()\n");
|
||||
debug("fetch_alloc_user()\n");
|
||||
int data[2];
|
||||
prefetch_data (mtp, data, 8);
|
||||
peer_t *U = user_chat_get (bl, MK_USER (data[1]));
|
||||
|
@ -1549,7 +1549,7 @@ struct user *fetch_alloc_user (struct mtproto_connection *mtp) {
|
|||
struct secret_chat *fetch_alloc_encrypted_chat (struct mtproto_connection *mtp) {
|
||||
struct binlog *bl = mtp->bl;
|
||||
|
||||
logprintf("fetch_alloc_encrypted_chat()\n");
|
||||
debug("fetch_alloc_encrypted_chat()\n");
|
||||
int data[2];
|
||||
prefetch_data (mtp, data, 8);
|
||||
peer_t *U = user_chat_get (bl, MK_ENCR_CHAT (data[1]));
|
||||
|
@ -1679,7 +1679,7 @@ void free_message_media (struct message_media *M) {
|
|||
case 0:
|
||||
break;
|
||||
default:
|
||||
logprintf ("%08x\n", M->type);
|
||||
debug ("%08x\n", M->type);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
@ -1813,7 +1813,7 @@ void message_del_peer (struct message *M) {
|
|||
struct message *fetch_alloc_message (struct mtproto_connection *mtp, struct telegram *instance) {
|
||||
struct binlog *bl = mtp->bl;
|
||||
|
||||
logprintf("fetch_alloc_message()\n");
|
||||
debug("fetch_alloc_message()\n");
|
||||
int data[2];
|
||||
prefetch_data (mtp, data, 8);
|
||||
struct message *M = message_get (bl, data[1]);
|
||||
|
@ -1832,7 +1832,7 @@ struct message *fetch_alloc_message (struct mtproto_connection *mtp, struct tele
|
|||
}
|
||||
|
||||
struct message *fetch_alloc_geo_message (struct mtproto_connection *mtp, struct telegram *instance) {
|
||||
logprintf("fetch_alloc_geo_message()\n");
|
||||
debug("fetch_alloc_geo_message()\n");
|
||||
struct message *M = talloc (sizeof (*M));
|
||||
M->instance = instance;
|
||||
fetch_geo_message (mtp, M);
|
||||
|
@ -1859,7 +1859,7 @@ struct message *fetch_alloc_geo_message (struct mtproto_connection *mtp, struct
|
|||
struct message *fetch_alloc_encrypted_message (struct mtproto_connection *mtp,
|
||||
struct telegram *instance) {
|
||||
struct binlog *bl = mtp->bl;
|
||||
logprintf("fetch_alloc_encrypted_message()\n");
|
||||
debug("fetch_alloc_encrypted_message()\n");
|
||||
int data[3];
|
||||
prefetch_data (mtp, data, 12);
|
||||
struct message *M = message_get (bl, *(long long *)(data + 1));
|
||||
|
@ -1871,7 +1871,7 @@ struct message *fetch_alloc_encrypted_message (struct mtproto_connection *mtp,
|
|||
message_insert_tree (M);
|
||||
mtp->bl->messages_allocated ++;
|
||||
assert (message_get (bl, M->id) == M);
|
||||
logprintf ("id = %lld\n", M->id);
|
||||
debug ("id = %lld\n", M->id);
|
||||
}
|
||||
fetch_encrypted_message (mtp, M);
|
||||
return M;
|
||||
|
@ -1914,12 +1914,12 @@ struct message *fetch_alloc_message_short_chat (struct mtproto_connection *mtp,
|
|||
|
||||
struct chat *fetch_alloc_chat (struct mtproto_connection *mtp) {
|
||||
struct binlog *bl = mtp->bl;
|
||||
logprintf("fetch_alloc_chat()\n");
|
||||
debug("fetch_alloc_chat()\n");
|
||||
int data[2];
|
||||
prefetch_data (mtp, data, 8);
|
||||
peer_t *U = user_chat_get (bl, MK_CHAT (data[1]));
|
||||
logprintf("id %d\n", U->id.id);
|
||||
logprintf("type %d\n", U->id.type);
|
||||
debug("id %d\n", U->id.id);
|
||||
debug("type %d\n", U->id.type);
|
||||
if (!U) {
|
||||
bl->chats_allocated ++;
|
||||
U = talloc0 (sizeof (*U));
|
||||
|
@ -2020,7 +2020,7 @@ void message_remove_unsent (struct message *M) {
|
|||
}
|
||||
|
||||
void __send_msg (struct message *M) {
|
||||
logprintf ("Resending message...\n");
|
||||
debug ("Resending message...\n");
|
||||
//print_message (M);
|
||||
|
||||
assert(M->instance);
|
||||
|
@ -2033,13 +2033,13 @@ void send_all_unsent (struct binlog *bl) {
|
|||
|
||||
void peer_insert_name (struct binlog *bl, peer_t *P) {
|
||||
//if (!P->print_name || !strlen (P->print_name)) { return; }
|
||||
//logprintf ("+%s\n", P->print_name);
|
||||
//debug ("+%s\n", P->print_name);
|
||||
bl->peer_by_name_tree = tree_insert_peer_by_name (bl->peer_by_name_tree, P, lrand48 ());
|
||||
}
|
||||
|
||||
void peer_delete_name (struct binlog *bl, peer_t *P) {
|
||||
//if (!P->print_name || !strlen (P->print_name)) { return; }
|
||||
//logprintf ("-%s\n", P->print_name);
|
||||
//debug ("-%s\n", P->print_name);
|
||||
bl->peer_by_name_tree = tree_delete_peer_by_name (bl->peer_by_name_tree, P);
|
||||
}
|
||||
|
||||
|
@ -2055,7 +2055,7 @@ void free_messages (struct binlog *bl)
|
|||
while (bl->message_tree) {
|
||||
struct message *M = tree_get_min_message (bl->message_tree);
|
||||
assert (M);
|
||||
logprintf ("freeing message: %lld\n", M->id);
|
||||
debug ("freeing message: %lld\n", M->id);
|
||||
bl->message_tree = tree_delete_message (bl->message_tree, M);
|
||||
bl->messages_allocated --;
|
||||
free_message (M);
|
||||
|
|
68
telegram.c
68
telegram.c
|
@ -108,20 +108,20 @@ int telegram_is_registered(struct telegram *tg) {
|
|||
void telegram_change_state (struct telegram *instance, int state, void *data)
|
||||
{
|
||||
instance->session_state = state;
|
||||
logprintf("on_state_change: %d\n", state);
|
||||
debug("on_state_change: %d\n", state);
|
||||
switch (state) {
|
||||
case STATE_ERROR: {
|
||||
const char* err = data;
|
||||
if (err == NULL) {
|
||||
err = "<no description>";
|
||||
}
|
||||
logprintf("telegram errored: %s\n", err);
|
||||
debug("telegram errored: %s\n", err);
|
||||
mtproto_close (instance->connection);
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_AUTHORIZED:
|
||||
logprintf("requesting configuration\n");
|
||||
debug("requesting configuration\n");
|
||||
telegram_change_state(instance, STATE_CONFIG_REQUESTED, NULL);
|
||||
if (telegram_is_registered(instance)) {
|
||||
telegram_change_state (instance, STATE_READY, NULL);
|
||||
|
@ -131,36 +131,36 @@ void telegram_change_state (struct telegram *instance, int state, void *data)
|
|||
break;
|
||||
|
||||
case STATE_CONFIG_RECEIVED:
|
||||
logprintf("received network configuration, checking whether phone is registered.\n");
|
||||
debug("received network configuration, checking whether phone is registered.\n");
|
||||
telegram_store_session(instance);
|
||||
do_auth_check_phone(instance, instance->login);
|
||||
break;
|
||||
|
||||
case STATE_PHONE_NOT_REGISTERED:
|
||||
logprintf("phone is not registered, need to register phone number.\n");
|
||||
debug("phone is not registered, need to register phone number.\n");
|
||||
do_send_code(instance, instance->login);
|
||||
break;
|
||||
|
||||
case STATE_PHONE_CODE_NOT_ENTERED:
|
||||
logprintf("phone authenticion, user needs to enter code, first and last name.\n");
|
||||
debug("phone authenticion, user needs to enter code, first and last name.\n");
|
||||
assert (instance->config->on_phone_registration_required);
|
||||
instance->config->on_phone_registration_required (instance);
|
||||
break;
|
||||
|
||||
case STATE_CLIENT_NOT_REGISTERED:
|
||||
logprintf("phone is already registered, need to register client.\n");
|
||||
debug("phone is already registered, need to register client.\n");
|
||||
do_send_code(instance, instance->login);
|
||||
break;
|
||||
|
||||
case STATE_CLIENT_CODE_NOT_ENTERED:
|
||||
logprintf("client authentication, user needs to enter code.\n");
|
||||
debug("client authentication, user needs to enter code.\n");
|
||||
assert (instance->config->on_client_registration_required);
|
||||
instance->config->on_client_registration_required (instance);
|
||||
// wait for user input ...
|
||||
break;
|
||||
|
||||
case STATE_READY:
|
||||
logprintf("telegram is registered and ready.\n");
|
||||
debug("telegram is registered and ready.\n");
|
||||
telegram_store_session (instance);
|
||||
instance->config->on_ready (instance);
|
||||
break;
|
||||
|
@ -170,7 +170,7 @@ void telegram_change_state (struct telegram *instance, int state, void *data)
|
|||
// the current mtproto_connection to be disconnected
|
||||
|
||||
int target_dc = *(int*) data;
|
||||
logprintf ("Disconnected: Migrate to data center %d\n", target_dc);
|
||||
debug ("Disconnected: Migrate to data center %d\n", target_dc);
|
||||
|
||||
// close old connection and mark it for destruction
|
||||
mtproto_close (instance->connection);
|
||||
|
@ -203,12 +203,12 @@ struct telegram *telegram_new(struct dc *DC, const char* login, struct telegram_
|
|||
this->state_path = telegram_get_config(this, "state");
|
||||
this->secret_path = telegram_get_config(this, "secret");
|
||||
|
||||
logprintf("%s\n", this->login);
|
||||
logprintf("%s\n", this->config_path);
|
||||
logprintf("%s\n", this->download_path);
|
||||
logprintf("%s\n", this->auth_path);
|
||||
logprintf("%s\n", this->state_path);
|
||||
logprintf("%s\n", this->secret_path);
|
||||
debug("%s\n", this->login);
|
||||
debug("%s\n", this->config_path);
|
||||
debug("%s\n", this->download_path);
|
||||
debug("%s\n", this->auth_path);
|
||||
debug("%s\n", this->state_path);
|
||||
debug("%s\n", this->secret_path);
|
||||
|
||||
telegram_change_state(this, STATE_INITIALISED, NULL);
|
||||
return this;
|
||||
|
@ -265,7 +265,7 @@ void free_auth (struct dc* DC_list[], int count)
|
|||
|
||||
void assert_file_usable(const char *file)
|
||||
{
|
||||
logprintf ("assert_file_usable (%s)\n", file);
|
||||
debug ("assert_file_usable (%s)\n", file);
|
||||
assert(access(file, W_OK | R_OK | F_OK) != -1);
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ void on_authorized(struct mtproto_connection *c, void* data);
|
|||
void telegram_main_connected (struct proxy_request *req)
|
||||
{
|
||||
struct telegram *instance = req->data;
|
||||
logprintf("Authorized... storing current session %d.\n",
|
||||
debug("Authorized... storing current session %d.\n",
|
||||
instance->connection->connection->session[0]);
|
||||
telegram_store_session(instance);
|
||||
telegram_change_state(instance, STATE_AUTHORIZED, NULL);
|
||||
|
@ -352,9 +352,9 @@ void telegram_main_connected (struct proxy_request *req)
|
|||
*/
|
||||
void telegram_connect (struct telegram *instance)
|
||||
{
|
||||
logprintf ("telegram_network_connect()\n");
|
||||
debug ("telegram_network_connect()\n");
|
||||
if (! instance->auth.DC_list) {
|
||||
logprintf("telegram_network_connect(): cannot connect, restore / init a session first.\n");
|
||||
debug("telegram_network_connect(): cannot connect, restore / init a session first.\n");
|
||||
assert(0);
|
||||
}
|
||||
struct dc *DC_working = telegram_get_working_dc (instance);
|
||||
|
@ -372,7 +372,7 @@ void telegram_connect (struct telegram *instance)
|
|||
|
||||
void on_auth_imported (void *extra)
|
||||
{
|
||||
logprintf ("on_auth_imported()\n");
|
||||
debug ("on_auth_imported()\n");
|
||||
struct download *dl = extra;
|
||||
struct mtproto_connection *c = dl->c;
|
||||
struct telegram *tg = c->instance;
|
||||
|
@ -384,7 +384,7 @@ void on_auth_imported (void *extra)
|
|||
|
||||
void on_auth_exported (char *export_auth_str UU, int len UU, void *extra)
|
||||
{
|
||||
logprintf ("on_auth_exported()\n");
|
||||
debug ("on_auth_exported()\n");
|
||||
struct download *dl = extra;
|
||||
do_import_auth (dl->c->instance, dl->dc, on_auth_imported, extra);
|
||||
telegram_flush (dl->c->instance);
|
||||
|
@ -392,7 +392,7 @@ void on_auth_exported (char *export_auth_str UU, int len UU, void *extra)
|
|||
|
||||
void telegram_dl_connected (struct proxy_request *req)
|
||||
{
|
||||
logprintf ("telegram_dl_connected(dc=%d)\n", req->DC->id);
|
||||
debug ("telegram_dl_connected(dc=%d)\n", req->DC->id);
|
||||
struct telegram *tg = req->tg;
|
||||
// TODO: error handling
|
||||
|
||||
|
@ -413,7 +413,7 @@ void telegram_dl_connected (struct proxy_request *req)
|
|||
*/
|
||||
void telegram_dl_add (struct telegram *instance, struct download *dl)
|
||||
{
|
||||
logprintf ("telegram_connect_dl(dc_num=%d, dc=%d)\n", dl->dc, instance->auth.DC_list[dl->dc]);
|
||||
debug ("telegram_connect_dl(dc_num=%d, dc=%d)\n", dl->dc, instance->auth.DC_list[dl->dc]);
|
||||
if (!instance->dl_queue) {
|
||||
instance->dl_queue = g_queue_new ();
|
||||
}
|
||||
|
@ -435,23 +435,23 @@ void telegram_dl_next (struct telegram *instance)
|
|||
req->data = dl;
|
||||
instance->dl_curr = dl;
|
||||
|
||||
logprintf ("telegrma_dl_start(workin_dc=%d, ): starting new download..\n", instance->auth.dc_working_num);
|
||||
debug ("telegrma_dl_start(workin_dc=%d, ): starting new download..\n", instance->auth.dc_working_num);
|
||||
if (dl->dc == instance->auth.dc_working_num) {
|
||||
logprintf ("is working DC, start download...\n");
|
||||
debug ("is working DC, start download...\n");
|
||||
assert (telegram_get_working_dc(instance)->sessions[0]->c);
|
||||
req->conn = instance->connection;
|
||||
dl->c = req->conn;
|
||||
telegram_dl_connected (req);
|
||||
} else {
|
||||
logprintf ("is remote DC, requesting connection...\n");
|
||||
debug ("is remote DC, requesting connection...\n");
|
||||
instance->config->proxy_request_cb (instance, req);
|
||||
}
|
||||
} else {
|
||||
logprintf ("telegrma_dl_start(): no more downloads, DONE!\n");
|
||||
debug ("telegrma_dl_start(): no more downloads, DONE!\n");
|
||||
mtproto_close_foreign (instance);
|
||||
}
|
||||
} else {
|
||||
logprintf ("telegrma_dl_start(): download busy...\n");
|
||||
debug ("telegrma_dl_start(): download busy...\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -461,7 +461,7 @@ void telegram_dl_next (struct telegram *instance)
|
|||
int telegram_login(struct telegram *instance)
|
||||
{
|
||||
if (instance->session_state != STATE_AUTHORIZED) {
|
||||
logprintf("Cannot log in, invalid state: %d \n", instance->session_state);
|
||||
debug("Cannot log in, invalid state: %d \n", instance->session_state);
|
||||
return -1;
|
||||
}
|
||||
do_help_get_config(instance);
|
||||
|
@ -471,7 +471,7 @@ int telegram_login(struct telegram *instance)
|
|||
|
||||
void on_authorized(struct mtproto_connection *c UU, void *data)
|
||||
{
|
||||
logprintf ("on_authorized()...\n");
|
||||
debug ("on_authorized()...\n");
|
||||
struct proxy_request *req = data;
|
||||
assert (req->done);
|
||||
req->done (req);
|
||||
|
@ -510,18 +510,18 @@ int telegram_authenticated (struct telegram *instance)
|
|||
|
||||
void telegram_flush (struct telegram *instance)
|
||||
{
|
||||
logprintf ("telegram flush()\n");
|
||||
debug ("telegram flush()\n");
|
||||
int i;
|
||||
for (i = 0; i < 100; i++) {
|
||||
struct mtproto_connection *c = instance->Cs[i];
|
||||
if (!c) continue;
|
||||
if (!c->connection) continue;
|
||||
if (c->connection->out_bytes) {
|
||||
logprintf ("connection %d has %d bytes, triggering on_output.\n",
|
||||
debug ("connection %d has %d bytes, triggering on_output.\n",
|
||||
i, c->connection->out_bytes);
|
||||
instance->config->on_output(c->handle);
|
||||
} else {
|
||||
logprintf ("connection %d has no bytes, skipping\n", i);
|
||||
debug ("connection %d has no bytes, skipping\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
tools.c
20
tools.c
|
@ -76,14 +76,14 @@ void tfree (void *ptr, int size __attribute__ ((unused))) {
|
|||
total_allocated_bytes -= size;
|
||||
ptr -= RES_PRE;
|
||||
if (size != (int)((*(int *)ptr) ^ 0xbedabeda)) {
|
||||
logprintf ("size = %d, ptr = %d\n", size, (*(int *)ptr) ^ 0xbedabeda);
|
||||
debug ("size = %d, ptr = %d\n", size, (*(int *)ptr) ^ 0xbedabeda);
|
||||
}
|
||||
assert (*(int *)ptr == (int)((size) ^ 0xbedabeda));
|
||||
assert (*(int *)(ptr + RES_PRE + size) == (int)((size) ^ 0x7bed7bed));
|
||||
assert (*(int *)(ptr + 4) == size);
|
||||
int block_num = *(int *)(ptr + 4 + RES_PRE + size);
|
||||
if (block_num >= used_blocks) {
|
||||
logprintf ("block_num = %d, used = %d\n", block_num, used_blocks);
|
||||
debug ("block_num = %d, used = %d\n", block_num, used_blocks);
|
||||
}
|
||||
assert (block_num < used_blocks);
|
||||
if (block_num < used_blocks - 1) {
|
||||
|
@ -182,7 +182,7 @@ char *tstrndup (const char *s, size_t n) {
|
|||
|
||||
void ensure (int r) {
|
||||
if (!r) {
|
||||
logprintf ("Open SSL error\n");
|
||||
debug ("Open SSL error\n");
|
||||
ERR_print_errors_fp (stderr);
|
||||
assert (0);
|
||||
}
|
||||
|
@ -206,12 +206,12 @@ int tinflate (void *input, int ilen, void *output, int olen) {
|
|||
if (err == Z_OK || err == Z_STREAM_END) {
|
||||
total_out = (int) strm.total_out;
|
||||
if (err == Z_STREAM_END && verbosity >= 2) {
|
||||
logprintf ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
debug ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
}
|
||||
}
|
||||
if (err != Z_STREAM_END) {
|
||||
logprintf ( "inflate error = %d\n", err);
|
||||
logprintf ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
debug ( "inflate error = %d\n", err);
|
||||
debug ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
}
|
||||
inflateEnd (&strm);
|
||||
return total_out;
|
||||
|
@ -234,25 +234,25 @@ void tcheck (void) {
|
|||
for (j = 0; j < l; j++) {
|
||||
if (*(char *)(ptr + 4 + j)) {
|
||||
hexdump (ptr + 8, ptr + 8 + l + ((-l) & 3));
|
||||
logprintf ("Used freed memory size = %d. ptr = %p\n", l + 4 - RES_PRE - RES_AFTER, ptr);
|
||||
debug ("Used freed memory size = %d. ptr = %p\n", l + 4 - RES_PRE - RES_AFTER, ptr);
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
logprintf ("ok. Used_blocks = %d. Free blocks = %d\n", used_blocks, free_blocks_cnt);
|
||||
debug ("ok. Used_blocks = %d. Free blocks = %d\n", used_blocks, free_blocks_cnt);
|
||||
}
|
||||
|
||||
void texists (void *ptr, int size) {
|
||||
ptr -= RES_PRE;
|
||||
if (size != (int)((*(int *)ptr) ^ 0xbedabeda)) {
|
||||
logprintf ("size = %d, ptr = %d\n", size, (*(int *)ptr) ^ 0xbedabeda);
|
||||
debug ("size = %d, ptr = %d\n", size, (*(int *)ptr) ^ 0xbedabeda);
|
||||
}
|
||||
assert (*(int *)ptr == (int)((size) ^ 0xbedabeda));
|
||||
assert (*(int *)(ptr + RES_PRE + size) == (int)((size) ^ 0x7bed7bed));
|
||||
assert (*(int *)(ptr + 4) == size);
|
||||
int block_num = *(int *)(ptr + 4 + RES_PRE + size);
|
||||
if (block_num >= used_blocks) {
|
||||
logprintf ("block_num = %d, used = %d\n", block_num, used_blocks);
|
||||
debug ("block_num = %d, used = %d\n", block_num, used_blocks);
|
||||
}
|
||||
assert (block_num < used_blocks);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue