Log all output of verbosity-level 1 to libpurple log
This commit is contained in:
parent
e4bb5bf5a6
commit
54091b26e3
8 changed files with 55 additions and 86 deletions
4
binlog.c
4
binlog.c
|
@ -96,9 +96,7 @@ void replay_log_event (struct telegram *instance) {
|
|||
int l2 = prefetch_strlen (self);
|
||||
char *ip = fetch_str (self, l2);
|
||||
int port = fetch_int (self);
|
||||
if (verbosity) {
|
||||
logprintf ( "id = %d, name = %.*s ip = %.*s port = %d\n", id, l1, name, l2, ip, port);
|
||||
}
|
||||
logprintf ( "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;
|
||||
|
|
|
@ -154,9 +154,7 @@ static int rsa_load_public_key (const char *public_key_name) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name);
|
||||
}
|
||||
logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1441,9 +1439,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) {
|
||||
if (verbosity) {
|
||||
logprintf ( "work_container: msg_id = %lld\n", msg_id);
|
||||
}
|
||||
logprintf ( "work_container: msg_id = %lld\n", msg_id);
|
||||
assert (fetch_int (c->mtconnection) == CODE_msg_container);
|
||||
int n = fetch_int (c->mtconnection);
|
||||
int i;
|
||||
|
@ -1464,38 +1460,47 @@ void work_container (struct connection *c, long long msg_id UU) {
|
|||
}
|
||||
|
||||
void work_new_session_created (struct connection *c, long long msg_id UU) {
|
||||
if (verbosity) {
|
||||
logprintf ( "work_new_session_created: msg_id = %lld\n", msg_id);
|
||||
}
|
||||
logprintf ( "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);
|
||||
|
||||
|
||||
/*
|
||||
// create a new empty session
|
||||
assert (DC->working_sess + 1 < 3);
|
||||
assert (!DC->sessions[++ DC->working_sess]);
|
||||
struct session *s = DC->sessions[DC->working_sess] = alloc_session();
|
||||
|
||||
// DC->session_id = fetch_long ();
|
||||
// long las_id = fetch_long (c->mtconnection);
|
||||
long ses_id = fetch_long (c->mtconnection);
|
||||
//s->session_id = ses_id;
|
||||
logprintf ("new sess_id = %ld\n", ses_id);
|
||||
|
||||
// fetch_long (c->mtconnection); // unique_id
|
||||
DC->server_salt = fetch_long (c->mtconnection);
|
||||
*/
|
||||
}
|
||||
|
||||
void work_msgs_ack (struct connection *c UU, long long msg_id UU) {
|
||||
if (verbosity) {
|
||||
logprintf ( "work_msgs_ack: msg_id = %lld\n", msg_id);
|
||||
}
|
||||
logprintf ( "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);
|
||||
if (verbosity) {
|
||||
logprintf ("ack for %lld\n", id);
|
||||
}
|
||||
logprintf ("ack for %lld\n", id);
|
||||
query_ack (id);
|
||||
}
|
||||
}
|
||||
|
||||
void work_rpc_result (struct connection *c UU, long long msg_id UU) {
|
||||
if (verbosity) {
|
||||
logprintf ( "work_rpc_result: msg_id = %lld\n", msg_id);
|
||||
}
|
||||
logprintf ( "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);
|
||||
|
@ -1639,9 +1644,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);
|
||||
if (verbosity) {
|
||||
logprintf ( "process_rpc_message(), len=%d\n", len);
|
||||
}
|
||||
logprintf ( "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);
|
||||
|
@ -1676,10 +1679,8 @@ 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);
|
||||
if (verbosity >= 1) {
|
||||
logprintf ( "received mesage id %016llx\n", enc->msg_id);
|
||||
hexdump_in (c->mtconnection);
|
||||
}
|
||||
logprintf ( "received mesage id %016llx\n", enc->msg_id);
|
||||
hexdump_in (c->mtconnection);
|
||||
c->mtconnection->server_last_msg_id = enc->msg_id;
|
||||
|
||||
//*(long long *)(longpoll_query + 3) = *(long long *)((char *)(&enc->msg_id) + 0x3c);
|
||||
|
@ -1763,9 +1764,7 @@ int rpc_execute (struct connection *c, int op, int len) {
|
|||
|
||||
|
||||
int tc_close (struct connection *c, int who) {
|
||||
if (verbosity) {
|
||||
logprintf ( "outbound http connection #%d : closing by %d\n", c->fd, who);
|
||||
}
|
||||
logprintf ( "outbound http connection #%d : closing by %d\n", c->fd, who);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -277,6 +277,7 @@ static inline void out_ints (struct mtproto_connection *self, const int *what, i
|
|||
|
||||
|
||||
static inline void out_int (struct mtproto_connection *self, int x) {
|
||||
logprintf("out_int(): packet_ptr:%p, packet_buffer:%p\n", self->packet_ptr, self->packet_buffer);
|
||||
assert (self->packet_ptr + 1 <= self->packet_buffer + PACKET_BUFFER_SIZE);
|
||||
*self->packet_ptr++ = x;
|
||||
}
|
||||
|
|
|
@ -103,9 +103,7 @@ void prng_seed (struct mtproto_connection *self, const char *password_filename,
|
|||
if (l < 0) {
|
||||
logprintf ( "Warning: fail to read password file - \"%s\", %m.\n", password_filename);
|
||||
} else {
|
||||
if (verbosity > 0) {
|
||||
logprintf ( "read %d bytes from password file.\n", l);
|
||||
}
|
||||
logprintf ( "read %d bytes from password file.\n", l);
|
||||
RAND_add (a, l, l);
|
||||
}
|
||||
close (fd);
|
||||
|
|
36
net.c
36
net.c
|
@ -105,9 +105,7 @@ 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) {
|
||||
if (verbosity) {
|
||||
logprintf ( "fail connection: reason: ping timeout\n");
|
||||
}
|
||||
logprintf ( "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) {
|
||||
|
@ -330,9 +328,7 @@ struct connection *create_connection (const char *host, int port, struct session
|
|||
c->port = port;
|
||||
assert (!Connections[fd]);
|
||||
Connections[fd] = c;
|
||||
if (verbosity) {
|
||||
logprintf ( "connect to %s:%d successful\n", host, port);
|
||||
}
|
||||
logprintf ( "connect to %s:%d successful\n", host, port);
|
||||
if (c->methods->ready) {
|
||||
c->methods->ready (c);
|
||||
}
|
||||
|
@ -418,9 +414,7 @@ void fail_connection (struct connection *c) {
|
|||
|
||||
extern FILE *log_net_f;
|
||||
int try_write (struct connection *c) {
|
||||
if (verbosity) {
|
||||
logprintf ( "try write: fd = %d\n", c->fd);
|
||||
}
|
||||
logprintf ( "try write: fd = %d\n", c->fd);
|
||||
int x = 0;
|
||||
while (c->out_head) {
|
||||
int r = netwrite (c->fd, c->out_head->rptr, c->out_head->wptr - c->out_head->rptr);
|
||||
|
@ -454,9 +448,7 @@ int try_write (struct connection *c) {
|
|||
delete_connection_buffer (b);
|
||||
} else {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
if (verbosity) {
|
||||
logprintf ("fail_connection: write_error %m\n");
|
||||
}
|
||||
logprintf ("fail_connection: write_error %m\n");
|
||||
fail_connection (c);
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -464,9 +456,7 @@ int try_write (struct connection *c) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (verbosity) {
|
||||
logprintf ( "Sent %d bytes to %d\n", x, c->fd);
|
||||
}
|
||||
logprintf ( "Sent %d bytes to %d\n", x, c->fd);
|
||||
c->out_bytes -= x;
|
||||
return x;
|
||||
}
|
||||
|
@ -534,9 +524,7 @@ void try_rpc_read (struct connection *c) {
|
|||
}
|
||||
|
||||
void try_read (struct connection *c) {
|
||||
if (verbosity) {
|
||||
logprintf ( "try read: fd = %d\n", c->fd);
|
||||
}
|
||||
logprintf ( "try read: fd = %d\n", c->fd);
|
||||
if (!c->in_tail) {
|
||||
c->in_head = c->in_tail = new_connection_buffer (1 << 20);
|
||||
}
|
||||
|
@ -569,9 +557,7 @@ void try_read (struct connection *c) {
|
|||
c->in_tail = b;
|
||||
} else {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
if (verbosity) {
|
||||
logprintf ("fail_connection: read_error %m\n");
|
||||
}
|
||||
logprintf ("fail_connection: read_error %m\n");
|
||||
fail_connection (c);
|
||||
return;
|
||||
} else {
|
||||
|
@ -579,9 +565,7 @@ void try_read (struct connection *c) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (verbosity) {
|
||||
logprintf ( "Received %d bytes from %d\n", x, c->fd);
|
||||
}
|
||||
logprintf ( "Received %d bytes from %d\n", x, c->fd);
|
||||
c->in_bytes += x;
|
||||
if (x) {
|
||||
try_rpc_read (c);
|
||||
|
@ -624,9 +608,7 @@ void connections_poll_result (struct pollfd *fds, int max) {
|
|||
try_read (c);
|
||||
}
|
||||
if (fds[i].revents & (POLLHUP | POLLERR | POLLRDHUP)) {
|
||||
if (verbosity) {
|
||||
logprintf ("fail_connection: events_mask=0x%08x\n", fds[i].revents);
|
||||
}
|
||||
logprintf ("fail_connection: events_mask=0x%08x\n", fds[i].revents);
|
||||
fail_connection (c);
|
||||
} else if (fds[i].revents & POLLOUT) {
|
||||
if (c->state == conn_connecting) {
|
||||
|
|
29
queries.c
29
queries.c
|
@ -137,9 +137,7 @@ void query_restart (long long id) {
|
|||
|
||||
struct query *send_query (struct dc *DC, int ints, void *data, struct query_methods *methods, void *extra) {
|
||||
logprintf("send_query(...)\n");
|
||||
if (verbosity) {
|
||||
logprintf ( "Sending query of size %d to DC (%s:%d)\n", 4 * ints, DC->ip, DC->port);
|
||||
}
|
||||
logprintf ( "Sending query of size %d to DC (%s:%d)\n", 4 * ints, DC->ip, DC->port);
|
||||
struct query *q = talloc0 (sizeof (*q));
|
||||
q->data_len = ints;
|
||||
q->data = talloc (4 * ints);
|
||||
|
@ -147,9 +145,7 @@ struct query *send_query (struct dc *DC, int ints, void *data, struct query_meth
|
|||
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;
|
||||
if (verbosity) {
|
||||
logprintf ( "Msg_id is %lld %p\n", q->msg_id, q);
|
||||
}
|
||||
logprintf ( "Msg_id is %lld %p\n", q->msg_id, q);
|
||||
q->methods = methods;
|
||||
q->DC = DC;
|
||||
if (queries_tree) {
|
||||
|
@ -219,9 +215,7 @@ void query_result (long long id UU) {
|
|||
struct query *q = query_get (id);
|
||||
struct mtproto_connection *mtp = query_get_mtproto(q);
|
||||
|
||||
if (verbosity) {
|
||||
logprintf ( "result for query #%lld\n", id);
|
||||
}
|
||||
logprintf ( "result for query #%lld\n", id);
|
||||
if (verbosity >= 4) {
|
||||
logprintf ( "result: ");
|
||||
hexdump_in (mtp);
|
||||
|
@ -246,9 +240,7 @@ void query_result (long long id UU) {
|
|||
}
|
||||
}
|
||||
if (!q) {
|
||||
if (verbosity) {
|
||||
logprintf ( "No such query\n");
|
||||
}
|
||||
logprintf ( "No such query\n");
|
||||
mtp->in_ptr = mtp->in_end;
|
||||
} else {
|
||||
if (!(q->flags & QUERY_ACK_RECEIVED)) {
|
||||
|
@ -297,9 +289,7 @@ void work_timers (void) {
|
|||
if (ev->timeout > t) { break; }
|
||||
remove_event_timer (ev);
|
||||
assert (ev->alarm);
|
||||
if (verbosity) {
|
||||
logprintf ("Alarm\n");
|
||||
}
|
||||
logprintf ("Alarm\n");
|
||||
ev->alarm (ev->self);
|
||||
}
|
||||
}
|
||||
|
@ -394,6 +384,7 @@ struct query_methods help_get_config_methods = {
|
|||
void do_help_get_config (struct telegram *instance) {
|
||||
struct mtproto_connection *mtp = instance->connection;
|
||||
|
||||
logprintf ("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);
|
||||
|
@ -636,9 +627,7 @@ int nearest_dc_on_answer (struct query *q UU) {
|
|||
|
||||
assert (fetch_int (mtp) == (int)CODE_nearest_dc);
|
||||
char *country = fetch_str_dup (mtp);
|
||||
if (verbosity > 0) {
|
||||
logprintf ("Server thinks that you are in %s\n", country);
|
||||
}
|
||||
logprintf ("Server thinks that you are in %s\n", country);
|
||||
fetch_int (mtp); // this_dc
|
||||
nearest_dc_num = fetch_int (mtp);
|
||||
assert (nearest_dc_num >= 0);
|
||||
|
@ -688,9 +677,7 @@ int sign_in_on_answer (struct query *q UU) {
|
|||
bl_do_set_our_id (mtp->bl, mtp, our_id);
|
||||
}
|
||||
sign_in_ok = 1;
|
||||
if (verbosity) {
|
||||
logprintf ( "telegram: authorized successfully: name = '%s %s', phone = '%s', expires = %d\n", User.first_name, User.last_name, User.phone, (int)(expires - get_double_time ()));
|
||||
}
|
||||
logprintf ( "telegram: authorized successfully: name = '%s %s', phone = '%s', expires = %d\n", User.first_name, User.last_name, User.phone, (int)(expires - get_double_time ()));
|
||||
DC_working->has_auth = 1;
|
||||
|
||||
bl_do_dc_signed (mtp->bl, mtp, DC_working->id);
|
||||
|
|
10
telegram.c
10
telegram.c
|
@ -69,18 +69,21 @@ void on_state_change(struct telegram *instance, int state, void *data)
|
|||
switch (state) {
|
||||
case STATE_ERROR: {
|
||||
const char* err = data;
|
||||
logprintf("Telegram errored: %s \n", err);
|
||||
if (err == NULL) {
|
||||
err = "<no description>";
|
||||
}
|
||||
logprintf("telegram errored: %s\n", err);
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_AUTHORIZED:
|
||||
logprintf("requesting configuration");
|
||||
logprintf("requesting configuration\n");
|
||||
telegram_change_state(instance, STATE_CONFIG_REQUESTED, NULL);
|
||||
do_help_get_config (instance);
|
||||
break;
|
||||
|
||||
case STATE_CONFIG_RECEIVED:
|
||||
logprintf("received network configuration, checking whether phone is registered.");
|
||||
logprintf("received network configuration, checking whether phone is registered.\n");
|
||||
telegram_store_session(instance);
|
||||
do_auth_check_phone(instance, instance->login);
|
||||
break;
|
||||
|
@ -133,6 +136,7 @@ struct telegram *telegram_new(struct dc *DC, const char* login, const char *conf
|
|||
logprintf("%s\n", this->download_path);
|
||||
logprintf("%s\n", this->auth_path);
|
||||
logprintf("%s\n", this->state_path);
|
||||
logprintf("%s\n", this->secret_path);
|
||||
|
||||
telegram_add_state_change_listener(this, on_state_change);
|
||||
telegram_change_state(this, STATE_INITIALISED, NULL);
|
||||
|
|
2
tools.c
2
tools.c
|
@ -239,7 +239,7 @@ int tinflate (void *input, int ilen, void *output, int olen) {
|
|||
logprintf ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
}
|
||||
}
|
||||
if (verbosity && err != Z_STREAM_END) {
|
||||
if (err != Z_STREAM_END) {
|
||||
logprintf ( "inflate error = %d\n", err);
|
||||
logprintf ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue