Merge github.com:vysheng/tg
Conflicts: main.c
This commit is contained in:
commit
c85f085244
10
interface.c
10
interface.c
@ -94,6 +94,8 @@ int in_chat_mode;
|
|||||||
tgl_peer_id_t chat_mode_id;
|
tgl_peer_id_t chat_mode_id;
|
||||||
extern int readline_disabled;
|
extern int readline_disabled;
|
||||||
|
|
||||||
|
extern int disable_output;
|
||||||
|
|
||||||
int is_same_word (const char *s, size_t l, const char *word) {
|
int is_same_word (const char *s, size_t l, const char *word) {
|
||||||
return s && word && strlen (word) == l && !memcmp (s, word, l);
|
return s && word && strlen (word) == l && !memcmp (s, word, l);
|
||||||
}
|
}
|
||||||
@ -848,7 +850,7 @@ void mark_read_upd (int num, struct tgl_message *list[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void type_notification_upd (struct tgl_user *U) {
|
void type_notification_upd (struct tgl_user *U) {
|
||||||
if (log_level < 2) { return; }
|
if (log_level < 2 || disable_output) { return; }
|
||||||
print_start ();
|
print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
printf ("User ");
|
printf ("User ");
|
||||||
@ -859,7 +861,7 @@ void type_notification_upd (struct tgl_user *U) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void type_in_chat_notification_upd (struct tgl_user *U, struct tgl_chat *C) {
|
void type_in_chat_notification_upd (struct tgl_user *U, struct tgl_chat *C) {
|
||||||
if (log_level < 2) { return; }
|
if (log_level < 2 || disable_output) { return; }
|
||||||
print_start ();
|
print_start ();
|
||||||
push_color (COLOR_YELLOW);
|
push_color (COLOR_YELLOW);
|
||||||
printf ("User ");
|
printf ("User ");
|
||||||
@ -876,6 +878,7 @@ void print_message_gw (struct tgl_message *M) {
|
|||||||
#ifdef USE_LUA
|
#ifdef USE_LUA
|
||||||
lua_new_msg (M);
|
lua_new_msg (M);
|
||||||
#endif
|
#endif
|
||||||
|
if (disable_output) { return; }
|
||||||
if (!binlog_read) { return; }
|
if (!binlog_read) { return; }
|
||||||
print_start ();
|
print_start ();
|
||||||
print_message (M);
|
print_message (M);
|
||||||
@ -935,6 +938,7 @@ void user_update_gw (struct tgl_user *U, unsigned flags) {
|
|||||||
lua_user_update (U, flags);
|
lua_user_update (U, flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (disable_output) { return; }
|
||||||
if (!binlog_read) { return; }
|
if (!binlog_read) { return; }
|
||||||
|
|
||||||
if (!(flags & TGL_UPDATE_CREATED)) {
|
if (!(flags & TGL_UPDATE_CREATED)) {
|
||||||
@ -959,6 +963,7 @@ void chat_update_gw (struct tgl_chat *U, unsigned flags) {
|
|||||||
lua_chat_update (U, flags);
|
lua_chat_update (U, flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (disable_output) { return; }
|
||||||
if (!binlog_read) { return; }
|
if (!binlog_read) { return; }
|
||||||
|
|
||||||
if (!(flags & TGL_UPDATE_CREATED)) {
|
if (!(flags & TGL_UPDATE_CREATED)) {
|
||||||
@ -983,6 +988,7 @@ void secret_chat_update_gw (struct tgl_secret_chat *U, unsigned flags) {
|
|||||||
lua_secret_chat_update (U, flags);
|
lua_secret_chat_update (U, flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (disable_output) { return; }
|
||||||
if (!binlog_read) { return; }
|
if (!binlog_read) { return; }
|
||||||
|
|
||||||
if ((flags & TGL_UPDATE_WORKING) || (flags & TGL_UPDATE_DELETED)) {
|
if ((flags & TGL_UPDATE_WORKING) || (flags & TGL_UPDATE_DELETED)) {
|
||||||
|
6
loop.c
6
loop.c
@ -72,6 +72,8 @@ int register_mode;
|
|||||||
extern int safe_quit;
|
extern int safe_quit;
|
||||||
extern int sync_from_start;
|
extern int sync_from_start;
|
||||||
|
|
||||||
|
extern int disable_output;
|
||||||
|
|
||||||
void got_it (char *line, int len);
|
void got_it (char *line, int len);
|
||||||
void write_state_file (void);
|
void write_state_file (void);
|
||||||
|
|
||||||
@ -613,6 +615,10 @@ int loop (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!tgl_signed_dc (tgl_state.DC_working)) {
|
if (!tgl_signed_dc (tgl_state.DC_working)) {
|
||||||
|
if (disable_output) {
|
||||||
|
fprintf (stderr, "Can not login without output\n");
|
||||||
|
exit (2);
|
||||||
|
}
|
||||||
if (!default_username) {
|
if (!default_username) {
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
char *user = 0;
|
char *user = 0;
|
||||||
|
17
main.c
17
main.c
@ -96,6 +96,7 @@ int allow_weak_random;
|
|||||||
char *lua_file;
|
char *lua_file;
|
||||||
int disable_colors;
|
int disable_colors;
|
||||||
int readline_disabled;
|
int readline_disabled;
|
||||||
|
int disable_output;
|
||||||
|
|
||||||
void set_default_username (const char *s) {
|
void set_default_username (const char *s) {
|
||||||
if (default_username) {
|
if (default_username) {
|
||||||
@ -220,8 +221,10 @@ void running_for_first_time (void) {
|
|||||||
//char *downloads_directory = get_downloads_directory ();
|
//char *downloads_directory = get_downloads_directory ();
|
||||||
|
|
||||||
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
|
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
|
||||||
|
if (!disable_output) {
|
||||||
printf ("[%s] created\n", config_directory);
|
printf ("[%s] created\n", config_directory);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tfree_str (config_directory);
|
tfree_str (config_directory);
|
||||||
config_directory = NULL;
|
config_directory = NULL;
|
||||||
@ -353,15 +356,21 @@ void parse_config (void) {
|
|||||||
tgl_set_download_directory (downloads_directory);
|
tgl_set_download_directory (downloads_directory);
|
||||||
|
|
||||||
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
|
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
|
||||||
|
if (!disable_output) {
|
||||||
printf ("[%s] created\n", config_directory);
|
printf ("[%s] created\n", config_directory);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) {
|
if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) {
|
||||||
|
if (!disable_output) {
|
||||||
printf ("[%s] created\n", downloads_directory);
|
printf ("[%s] created\n", downloads_directory);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void parse_config (void) {
|
void parse_config (void) {
|
||||||
|
if (!disable_output) {
|
||||||
printf ("libconfig not enabled\n");
|
printf ("libconfig not enabled\n");
|
||||||
|
}
|
||||||
tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
|
tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
|
||||||
|
|
||||||
if (binlog_enabled) {
|
if (binlog_enabled) {
|
||||||
@ -409,6 +418,7 @@ void usage (void) {
|
|||||||
printf (" -L <log-name> log file name\n");
|
printf (" -L <log-name> log file name\n");
|
||||||
printf (" -U <user-name> change uid after start\n");
|
printf (" -U <user-name> change uid after start\n");
|
||||||
printf (" -G <group-name> change gid after start\n");
|
printf (" -G <group-name> change gid after start\n");
|
||||||
|
printf (" -D disable output\n");
|
||||||
|
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -509,7 +519,7 @@ int change_user_group () {
|
|||||||
|
|
||||||
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:vNl:fEwWCRdL:U:G:"
|
while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:DU:G:"
|
||||||
#ifdef HAVE_LIBCONFIG
|
#ifdef HAVE_LIBCONFIG
|
||||||
"c:p:"
|
"c:p:"
|
||||||
#else
|
#else
|
||||||
@ -586,6 +596,9 @@ void args_parse (int argc, char **argv) {
|
|||||||
case 'G':
|
case 'G':
|
||||||
set_group_name = optarg;
|
set_group_name = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
disable_output ++;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
usage ();
|
usage ();
|
||||||
@ -640,12 +653,14 @@ int main (int argc, char **argv) {
|
|||||||
signal (SIGUSR1, sigusr1_handler);
|
signal (SIGUSR1, sigusr1_handler);
|
||||||
reopen_logs ();
|
reopen_logs ();
|
||||||
}
|
}
|
||||||
|
if (!disable_output) {
|
||||||
printf (
|
printf (
|
||||||
"Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n"
|
"Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n"
|
||||||
"Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
|
"Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
|
||||||
"This is free software, and you are welcome to redistribute it\n"
|
"This is free software, and you are welcome to redistribute it\n"
|
||||||
"under certain conditions; type `show_license' for details.\n"
|
"under certain conditions; type `show_license' for details.\n"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
running_for_first_time ();
|
running_for_first_time ();
|
||||||
parse_config ();
|
parse_config ();
|
||||||
|
|
||||||
|
@ -617,7 +617,12 @@ static int process_dh_answer (struct connection *c, char *packet, int len, int t
|
|||||||
l = BN_num_bytes (&auth_key_num);
|
l = BN_num_bytes (&auth_key_num);
|
||||||
assert (l >= 250 && l <= 256);
|
assert (l >= 250 && l <= 256);
|
||||||
assert (BN_bn2bin (&auth_key_num, (unsigned char *)(temp_key ? D->temp_auth_key : D->auth_key)));
|
assert (BN_bn2bin (&auth_key_num, (unsigned char *)(temp_key ? D->temp_auth_key : D->auth_key)));
|
||||||
memset (temp_key ? D->temp_auth_key + l : D->auth_key + l, 0, 256 - l);
|
if (l < 256) {
|
||||||
|
char *key = temp_key ? D->temp_auth_key : D->auth_key;
|
||||||
|
memmove (key + 256 - l, key, l);
|
||||||
|
memset (key, 0, 256 - l);
|
||||||
|
}
|
||||||
|
|
||||||
BN_free (dh_power);
|
BN_free (dh_power);
|
||||||
BN_free (&auth_key_num);
|
BN_free (&auth_key_num);
|
||||||
BN_free (&dh_g);
|
BN_free (&dh_g);
|
||||||
|
Loading…
Reference in New Issue
Block a user