Merge github.com:vysheng/tg

Conflicts:
	interface.c
This commit is contained in:
vysheng 2013-11-19 21:01:18 +04:00
commit a8cc367a16
6 changed files with 125 additions and 65 deletions

View File

@ -50,6 +50,8 @@ int msg_num_mode;
int in_readline; int in_readline;
int readline_active; int readline_active;
int log_level;
long long cur_uploading_bytes; long long cur_uploading_bytes;
long long cur_uploaded_bytes; long long cur_uploaded_bytes;
long long cur_downloading_bytes; long long cur_downloading_bytes;
@ -286,6 +288,7 @@ char *commands[] = {
"view_document_thumb", "view_document_thumb",
"load_document", "load_document",
"view_document", "view_document",
"set",
0 }; 0 };
int commands_flags[] = { int commands_flags[] = {
@ -327,6 +330,11 @@ int commands_flags[] = {
07, 07,
07, 07,
0732, 0732,
07,
07,
07,
07,
07,
}; };
int get_complete_mode (void) { int get_complete_mode (void) {
@ -781,6 +789,13 @@ void interpreter (char *line UU) {
"rename_contact <user> <first-name> <last-name> - tries to rename contact. If you have another device it will be a fight\n" "rename_contact <user> <first-name> <last-name> - tries to rename contact. If you have another device it will be a fight\n"
"suggested_contacts - print info about contacts, you have max common friends\n" "suggested_contacts - print info about contacts, you have max common friends\n"
"visualize_key <secret_chat> - prints visualization of encryption key. You should compare it to your partner's one\n" "visualize_key <secret_chat> - prints visualization of encryption key. You should compare it to your partner's one\n"
"set <param> <param-value>. Possible <param> values are:\n"
"\tdebug_verbosity - just as it sounds. Debug verbosity\n"
"\tlog_level - level of logging of new events. Lower is less verbose:\n"
"\t\tLevel 1: prints info about read messages\n"
"\t\tLevel 2: prints line, when somebody is typing in chat\n"
"\t\tLevel 3: prints line, when somebody changes online status\n"
"\tmsg_num - enables/disables numeration of messages\n"
); );
pop_color (); pop_color ();
} else if (IS_WORD ("show_license")) { } else if (IS_WORD ("show_license")) {
@ -938,11 +953,26 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
} else if (IS_WORD ("set")) {
command = next_token (&l);
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
if (IS_WORD ("debug_verbosity")) {
verbosity = num;
} else if (IS_WORD ("log_level")) {
log_level = num;
} else if (IS_WORD ("msg_num")) {
msg_num_mode = num;
}
} else if (IS_WORD ("quit")) { } else if (IS_WORD ("quit")) {
exit (0); exit (0);
} }
#undef IS_WORD #undef IS_WORD
#undef RET #undef RET
update_prompt ();
in_readline = 0; in_readline = 0;
} }

13
main.c
View File

@ -76,6 +76,7 @@ char *downloads_directory;
char *config_directory; char *config_directory;
char *binlog_file_name; char *binlog_file_name;
int binlog_enabled; int binlog_enabled;
extern int log_level;
void set_default_username (const char *s) { void set_default_username (const char *s) {
if (default_username) { if (default_username) {
@ -260,6 +261,9 @@ void parse_config (void) {
strcpy (buf + l, "test"); strcpy (buf + l, "test");
config_lookup_bool (&conf, buf, &test_dc); config_lookup_bool (&conf, buf, &test_dc);
strcpy (buf + l, "log_level");
config_lookup_int (&conf, buf, &log_level);
if (!msg_num_mode) { if (!msg_num_mode) {
strcpy (buf + l, "msg_num"); strcpy (buf + l, "msg_num");
config_lookup_bool (&conf, buf, &msg_num_mode); config_lookup_bool (&conf, buf, &msg_num_mode);
@ -300,7 +304,7 @@ void inner_main (void) {
} }
void usage (void) { void usage (void) {
printf ("%s [-u username] [-h] [-k public key name] [-N] [-v]\n", PROGNAME); printf ("%s [-u username] [-h] [-k public key name] [-N] [-v] [-l log_level]\n", PROGNAME);
exit (1); exit (1);
} }
@ -310,7 +314,7 @@ extern int default_dc_num;
void args_parse (int argc, char **argv) { void args_parse (int argc, char **argv) {
int opt = 0; int opt = 0;
while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:")) != -1) { while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:l:")) != -1) {
switch (opt) { switch (opt) {
case 'u': case 'u':
set_default_username (optarg); set_default_username (optarg);
@ -331,6 +335,9 @@ void args_parse (int argc, char **argv) {
prefix = strdup (optarg); prefix = strdup (optarg);
assert (strlen (prefix) <= 100); assert (strlen (prefix) <= 100);
break; break;
case 'l':
log_level = atoi (optarg);
break;
case 'h': case 'h':
default: default:
usage (); usage ();
@ -357,6 +364,8 @@ int main (int argc, char **argv) {
signal (SIGSEGV, sig_handler); signal (SIGSEGV, sig_handler);
signal (SIGABRT, sig_handler); signal (SIGABRT, sig_handler);
log_level = 10;
args_parse (argc, argv); args_parse (argc, argv);
printf ( printf (
"Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n" "Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n"

View File

@ -51,6 +51,7 @@
#include "mtproto-common.h" #include "mtproto-common.h"
#define MAX_NET_RES (1L << 16) #define MAX_NET_RES (1L << 16)
extern int log_level;
int verbosity; int verbosity;
int auth_success; int auth_success;
@ -739,6 +740,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
} }
} }
fetch_pts (); fetch_pts ();
if (log_level >= 1) {
print_start (); print_start ();
push_color (COLOR_YELLOW); push_color (COLOR_YELLOW);
print_date (time (0)); print_date (time (0));
@ -746,11 +748,13 @@ void work_update (struct connection *c UU, long long msg_id UU) {
pop_color (); pop_color ();
print_end (); print_end ();
} }
}
break; break;
case CODE_update_user_typing: case CODE_update_user_typing:
{ {
peer_id_t id = MK_USER (fetch_int ()); peer_id_t id = MK_USER (fetch_int ());
peer_t *U = user_chat_get (id); peer_t *U = user_chat_get (id);
if (log_level >= 2) {
print_start (); print_start ();
push_color (COLOR_YELLOW); push_color (COLOR_YELLOW);
print_date (time (0)); print_date (time (0));
@ -760,6 +764,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
pop_color (); pop_color ();
print_end (); print_end ();
} }
}
break; break;
case CODE_update_chat_user_typing: case CODE_update_chat_user_typing:
{ {
@ -767,6 +772,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
peer_id_t id = MK_USER (fetch_int ()); peer_id_t id = MK_USER (fetch_int ());
peer_t *C = user_chat_get (chat_id); peer_t *C = user_chat_get (chat_id);
peer_t *U = user_chat_get (id); peer_t *U = user_chat_get (id);
if (log_level >= 2) {
print_start (); print_start ();
push_color (COLOR_YELLOW); push_color (COLOR_YELLOW);
print_date (time (0)); print_date (time (0));
@ -778,6 +784,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
pop_color (); pop_color ();
print_end (); print_end ();
} }
}
break; break;
case CODE_update_user_status: case CODE_update_user_status:
{ {
@ -785,6 +792,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
peer_t *U = user_chat_get (user_id); peer_t *U = user_chat_get (user_id);
if (U) { if (U) {
fetch_user_status (&U->user.status); fetch_user_status (&U->user.status);
if (log_level >= 3) {
print_start (); print_start ();
push_color (COLOR_YELLOW); push_color (COLOR_YELLOW);
print_date (time (0)); print_date (time (0));
@ -794,6 +802,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
printf ("%s\n", (U->user.status.online > 0) ? "online" : "offline"); printf ("%s\n", (U->user.status.online > 0) ? "online" : "offline");
pop_color (); pop_color ();
print_end (); print_end ();
}
} else { } else {
struct user_status t; struct user_status t;
fetch_user_status (&t); fetch_user_status (&t);
@ -876,6 +885,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
if (y == CODE_user_profile_photo_empty) { if (y == CODE_user_profile_photo_empty) {
} else { } else {
assert (y == CODE_user_profile_photo); assert (y == CODE_user_profile_photo);
fetch_long (); // photo_id
fetch_file_location (&t); fetch_file_location (&t);
fetch_file_location (&t); fetch_file_location (&t);
} }
@ -1096,6 +1106,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
M = M->next; M = M->next;
} }
} }
if (log_level >= 1) {
print_start (); print_start ();
push_color (COLOR_YELLOW); push_color (COLOR_YELLOW);
print_date (time (0)); print_date (time (0));
@ -1105,6 +1116,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
pop_color (); pop_color ();
print_end (); print_end ();
} }
}
break; break;
case CODE_update_chat_participant_add: case CODE_update_chat_participant_add:
{ {

View File

@ -76,6 +76,7 @@
#define CODE_input_peer_notify_settings_old 0x3cf4b1be #define CODE_input_peer_notify_settings_old 0x3cf4b1be
#define CODE_peer_notify_settings_old 0xddbcd4a5 #define CODE_peer_notify_settings_old 0xddbcd4a5
#define CODE_user_profile_photo_old 0x990d1493
#define CODE_msg_detained_info 0x276d3ec6 #define CODE_msg_detained_info 0x276d3ec6
/* not really a limit, for struct encrypted_message only */ /* not really a limit, for struct encrypted_message only */

View File

@ -303,6 +303,28 @@ void out_random (int n) {
out_cstring (buf, n); out_cstring (buf, n);
} }
int allow_send_linux_version;
void do_insert_header (void) {
out_int (CODE_invoke_with_layer9);
out_int (CODE_init_connection);
out_int (TG_APP_ID);
if (allow_send_linux_version) {
struct utsname st;
uname (&st);
out_string (st.machine);
static char buf[1000000];
sprintf (buf, "%s %s %s", st.sysname, st.release, st.version);
out_string (buf);
out_string (TG_VERSION " (build " TG_BUILD ")");
out_string ("En");
} else {
out_string ("x86");
out_string ("Linux");
out_string (TG_VERSION);
out_string ("en");
}
}
/* {{{ Get config */ /* {{{ Get config */
void fetch_dc_option (void) { void fetch_dc_option (void) {
@ -413,7 +435,7 @@ void do_send_code (const char *user) {
suser = strdup (user); suser = strdup (user);
want_dc_num = 0; want_dc_num = 0;
clear_packet (); clear_packet ();
out_int (CODE_invoke_with_layer6); do_insert_header ();
out_int (CODE_auth_send_code); out_int (CODE_auth_send_code);
out_string (user); out_string (user);
out_int (0); out_int (0);
@ -441,7 +463,7 @@ void do_send_code (const char *user) {
logprintf ("send_code: dc_num = %d\n", dc_working_num); logprintf ("send_code: dc_num = %d\n", dc_working_num);
want_dc_num = 0; want_dc_num = 0;
clear_packet (); clear_packet ();
out_int (CODE_invoke_with_layer6); do_insert_header ();
out_int (CODE_auth_send_code); out_int (CODE_auth_send_code);
out_string (user); out_string (user);
out_int (0); out_int (0);
@ -2531,24 +2553,7 @@ struct query_methods get_difference_methods = {
void do_get_difference (void) { void do_get_difference (void) {
difference_got = 0; difference_got = 0;
clear_packet (); clear_packet ();
out_int (CODE_invoke_with_layer9); do_insert_header ();
out_int (CODE_init_connection);
out_int (TG_APP_ID);
if (allow_send_linux_version) {
struct utsname st;
uname (&st);
out_string (st.machine);
static char buf[1000000];
sprintf (buf, "%s %s %s", st.sysname, st.release, st.version);
out_string (buf);
out_string (TG_VERSION " (build " TG_BUILD ")");
out_string ("En");
} else {
out_string ("x86");
out_string ("Linux");
out_string (TG_VERSION);
out_string ("en");
}
if (seq > 0) { if (seq > 0) {
out_int (CODE_updates_get_difference); out_int (CODE_updates_get_difference);
out_int (pts); out_int (pts);

View File

@ -202,8 +202,10 @@ int fetch_user (struct user *U) {
need_update |= set_update_int (&U->photo_small.dc, -2); need_update |= set_update_int (&U->photo_small.dc, -2);
need_update |= set_update_int (&U->photo_big.dc, -2); need_update |= set_update_int (&U->photo_big.dc, -2);
} else { } else {
assert (y == CODE_user_profile_photo); assert (y == CODE_user_profile_photo || y == CODE_user_profile_photo_old);
if (y == CODE_user_profile_photo) {
fetch_long (); fetch_long ();
}
need_update |= fetch_file_location (&U->photo_small); need_update |= fetch_file_location (&U->photo_small);
need_update |= fetch_file_location (&U->photo_big); need_update |= fetch_file_location (&U->photo_big);
} }
@ -396,6 +398,7 @@ void fetch_user_full (struct user *U) {
free_photo (&U->photo); free_photo (&U->photo);
} }
fetch_photo (&U->photo); fetch_photo (&U->photo);
U->flags |= FLAG_HAS_PHOTO;
fetch_notify_settings (); fetch_notify_settings ();
U->blocked = fetch_int (); U->blocked = fetch_int ();
if (U->real_first_name) { free (U->real_first_name); } if (U->real_first_name) { free (U->real_first_name); }