Commit fe08f0c5 authored by vysheng's avatar vysheng

more code

parent bf86f756
...@@ -1126,9 +1126,7 @@ static void replay_log_event (void) { ...@@ -1126,9 +1126,7 @@ static void replay_log_event (void) {
assert (rptr < wptr); assert (rptr < wptr);
int op = *rptr; int op = *rptr;
if (verbosity >= 2) { vlogprintf (E_DEBUG, "replay_log_event: log_pos=%lld, op=0x%08x\n", binlog_pos, op);
logprintf ("log_pos %lld, op 0x%08x\n", binlog_pos, op);
}
in_ptr = rptr; in_ptr = rptr;
in_end = wptr; in_end = wptr;
...@@ -1201,7 +1199,7 @@ static void replay_log_event (void) { ...@@ -1201,7 +1199,7 @@ static void replay_log_event (void) {
FETCH_COMBINATOR_FUNCTION (binlog_set_msg_id) FETCH_COMBINATOR_FUNCTION (binlog_set_msg_id)
FETCH_COMBINATOR_FUNCTION (binlog_delete_msg) FETCH_COMBINATOR_FUNCTION (binlog_delete_msg)
default: default:
logprintf ("Unknown op 0x%08x\n", op); vlogprintf (E_ERROR, "Unknown op 0x%08x\n", op);
assert (0); assert (0);
} }
assert (ok >= 0); assert (ok >= 0);
...@@ -1287,9 +1285,7 @@ void tgl_reopen_binlog_for_writing (void) { ...@@ -1287,9 +1285,7 @@ void tgl_reopen_binlog_for_writing (void) {
} }
static void add_log_event (const int *data, int len) { static void add_log_event (const int *data, int len) {
if (verbosity) { vlogprintf (E_DEBUG, "Add log event: magic = 0x%08x, len = %d\n", data[0], len);
logprintf ("Add log event: magic = 0x%08x, len = %d\n", data[0], len);
}
assert (!(len & 3)); assert (!(len & 3));
rptr = (void *)data; rptr = (void *)data;
wptr = rptr + (len / 4); wptr = rptr + (len / 4);
...@@ -1297,7 +1293,7 @@ static void add_log_event (const int *data, int len) { ...@@ -1297,7 +1293,7 @@ static void add_log_event (const int *data, int len) {
int *end = in_end; int *end = in_end;
replay_log_event (); replay_log_event ();
if (rptr != wptr) { if (rptr != wptr) {
logprintf ("Unread %lld ints. Len = %d\n", (long long)(wptr - rptr), len); vlogprintf (E_ERROR, "Unread %lld ints. Len = %d\n", (long long)(wptr - rptr), len);
assert (rptr == wptr); assert (rptr == wptr);
} }
if (tgl_state.binlog_enabled) { if (tgl_state.binlog_enabled) {
......
...@@ -34,11 +34,6 @@ ...@@ -34,11 +34,6 @@
#define COLOR_INVERSE "\033[7m" #define COLOR_INVERSE "\033[7m"
#define E_ERROR 0
#define E_WARNING 1
#define E_NOTICE 2
#define E_DEBUG 3
char *get_default_prompt (void); char *get_default_prompt (void);
char *complete_none (const char *text, int state); char *complete_none (const char *text, int state);
char **complete_text (char *text, int start, int end); char **complete_text (char *text, int start, int end);
......
...@@ -155,7 +155,7 @@ char *get_state_filename (void); ...@@ -155,7 +155,7 @@ char *get_state_filename (void);
char *get_secret_chat_filename (void); char *get_secret_chat_filename (void);
int zero[512]; int zero[512];
/*
void write_dc (int auth_file_fd, struct dc *DC) { void write_dc (int auth_file_fd, struct dc *DC) {
assert (write (auth_file_fd, &DC->port, 4) == 4); assert (write (auth_file_fd, &DC->port, 4) == 4);
int l = strlen (DC->ip); int l = strlen (DC->ip);
...@@ -436,7 +436,7 @@ void write_secret_chat_file (void) { ...@@ -436,7 +436,7 @@ void write_secret_chat_file (void) {
assert (write (fd, encr_prime, 256) == 256); assert (write (fd, encr_prime, 256) == 256);
} }
close (fd); close (fd);
} }*/
extern int max_chat_size; extern int max_chat_size;
int mcs (void) { int mcs (void) {
......
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include "telegram.h" #include "telegram.h"
#include "loop.h" #include "loop.h"
#include "mtproto-client.h"
#include "interface.h" #include "interface.h"
#include "tools.h" #include "tools.h"
...@@ -59,8 +58,8 @@ ...@@ -59,8 +58,8 @@
#include "tgl.h" #include "tgl.h"
#define PROGNAME "telegram-client" #define PROGNAME "telegram-cli"
#define VERSION "0.01" #define VERSION "0.07"
#define CONFIG_DIRECTORY "." PROG_NAME #define CONFIG_DIRECTORY "." PROG_NAME
#define CONFIG_FILE "config" #define CONFIG_FILE "config"
...@@ -319,13 +318,20 @@ void parse_config (void) { ...@@ -319,13 +318,20 @@ void parse_config (void) {
config_directory = make_full_path (config_directory); config_directory = make_full_path (config_directory);
parse_config_val (&conf, &auth_file_name, "auth_file", AUTH_KEY_FILE, config_directory); parse_config_val (&conf, &auth_file_name, "auth_file", AUTH_KEY_FILE, config_directory);
parse_config_val (&conf, &state_file_name, "state_file", STATE_FILE, config_directory);
parse_config_val (&conf, &secret_chat_file_name, "secret", SECRET_CHAT_FILE, config_directory);
parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory); parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory);
parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory); parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory);
strcpy (buf + l, "binlog_enabled"); strcpy (buf + l, "binlog_enabled");
config_lookup_bool (&conf, buf, &binlog_enabled); config_lookup_bool (&conf, buf, &binlog_enabled);
if (binlog_enabled) {
tgl_set_binlog_mode (1);
tgl_set_binlog_path (binlog_file_name);
} else {
tgl_set_binlog_mode (0);
tgl_set_auth_file_path (auth_file_name);
}
tgl_set_download_directory (downloads_directory);
if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) { if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) {
printf ("[%s] created\n", config_directory); printf ("[%s] created\n", config_directory);
...@@ -338,10 +344,17 @@ void parse_config (void) { ...@@ -338,10 +344,17 @@ void parse_config (void) {
void parse_config (void) { void parse_config (void) {
printf ("libconfig not enabled\n"); printf ("libconfig not enabled\n");
tasprintf (&auth_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, AUTH_KEY_FILE); tasprintf (&auth_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, AUTH_KEY_FILE);
tasprintf (&state_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, STATE_FILE);
tasprintf (&secret_chat_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, SECRET_CHAT_FILE);
tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY); tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY);
tasprintf (&binlog_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, BINLOG_FILE); tasprintf (&binlog_file_name, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, BINLOG_FILE);
if (binlog_enabled) {
tgl_set_binlog_mode (1);
tgl_set_binlog_path (binlog_file_name);
} else {
tgl_set_binlog_mode (0);
tgl_set_auth_file_path (auth_file_name;
}
tgl_set_download_directory (downloads_directory);
} }
#endif #endif
...@@ -488,7 +501,7 @@ int main (int argc, char **argv) { ...@@ -488,7 +501,7 @@ int main (int argc, char **argv) {
args_parse (argc, argv); args_parse (argc, argv);
printf ( printf (
"Telegram-client version " TG_VERSION ", Copyright (C) 2013 Vitaly Valtman\n" "Telegram-client version " TGL_VERSION ", Copyright (C) 2013 Vitaly Valtman\n"
"Telegram-client comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n" "Telegram-client comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n"
"This is free software, and you are welcome to redistribute it\n" "This is free software, and you are welcome to redistribute it\n"
"under certain conditions; type `show_license' for details.\n" "under certain conditions; type `show_license' for details.\n"
......
This diff is collapsed.
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include <openssl/sha.h> #include <openssl/sha.h>
#include "mtproto-common.h" #include "mtproto-common.h"
#include "interface.h"
#include "include.h" #include "include.h"
#ifdef __MACH__ #ifdef __MACH__
...@@ -61,9 +60,7 @@ int get_random_bytes (unsigned char *buf, int n) { ...@@ -61,9 +60,7 @@ int get_random_bytes (unsigned char *buf, int n) {
if (h >= 0) { if (h >= 0) {
r = read (h, buf, n); r = read (h, buf, n);
if (r > 0) { if (r > 0) {
if (verbosity >= 3) { vlogprintf (E_DEBUG, "added %d bytes of real entropy to secure random numbers seed\n", r);
logprintf ( "added %d bytes of real entropy to secure random numbers seed\n", r);
}
} else { } else {
r = 0; r = 0;
} }
...@@ -143,16 +140,14 @@ void prng_seed (const char *password_filename, int password_length) { ...@@ -143,16 +140,14 @@ void prng_seed (const char *password_filename, int password_length) {
if (password_filename && password_length > 0) { if (password_filename && password_length > 0) {
int fd = open (password_filename, O_RDONLY); int fd = open (password_filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
logprintf ( "Warning: fail to open password file - \"%s\", %m.\n", password_filename); vlogprintf (E_WARNING, "Warning: fail to open password file - \"%s\", %m.\n", password_filename);
} else { } else {
unsigned char *a = talloc0 (password_length); unsigned char *a = talloc0 (password_length);
int l = read (fd, a, password_length); int l = read (fd, a, password_length);
if (l < 0) { if (l < 0) {
logprintf ( "Warning: fail to read password file - \"%s\", %m.\n", password_filename); vlogprintf (E_WARNING, "Warning: fail to read password file - \"%s\", %m.\n", password_filename);
} else { } else {
if (verbosity > 0) { vlogprintf (E_DEBUG, "read %d bytes from password file.\n", l);
logprintf ( "read %d bytes from password file.\n", l);
}
RAND_add (a, l, l); RAND_add (a, l, l);
} }
close (fd); close (fd);
......
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
#include <openssl/aes.h> #include <openssl/aes.h>
#include <stdio.h> #include <stdio.h>
#include "interface.h" //#include "interface.h"
#include "tools.h" #include "tools.h"
#include "auto/constants.h" #include "auto/constants.h"
#include "tgl.h"
/* DH key exchange protocol data structures */ /* DH key exchange protocol data structures */
#define CODE_req_pq 0x60469778 #define CODE_req_pq 0x60469778
#define CODE_resPQ 0x05162463 #define CODE_resPQ 0x05162463
...@@ -178,9 +180,7 @@ static inline int prefetch_strlen (void) { ...@@ -178,9 +180,7 @@ static inline int prefetch_strlen (void) {
extern int verbosity; extern int verbosity;
static inline char *fetch_str (int len) { static inline char *fetch_str (int len) {
assert (len >= 0); assert (len >= 0);
if (verbosity > 6) { vlogprintf (E_DEBUG + 3, "fetch_string: len = %d\n", len);
logprintf ("fetch_string: len = %d\n", len);
}
if (len < 254) { if (len < 254) {
char *str = (char *) in_ptr + 1; char *str = (char *) in_ptr + 1;
in_ptr += 1 + (len >> 2); in_ptr += 1 + (len >> 2);
...@@ -272,16 +272,12 @@ int fetch_bignum (BIGNUM *x); ...@@ -272,16 +272,12 @@ int fetch_bignum (BIGNUM *x);
static inline int fetch_int (void) { static inline int fetch_int (void) {
assert (in_ptr + 1 <= in_end); assert (in_ptr + 1 <= in_end);
if (verbosity > 6) { vlogprintf (E_DEBUG + 3, "fetch_int: 0x%08x (%d)\n", *in_ptr, *in_ptr);
logprintf ("fetch_int: 0x%08x (%d)\n", *in_ptr, *in_ptr);
}
return *(in_ptr ++); return *(in_ptr ++);
} }
static inline int fetch_bool (void) { static inline int fetch_bool (void) {
if (verbosity > 6) { vlogprintf (E_DEBUG + 3, "fetch_bool: 0x%08x (%d)\n", *in_ptr, *in_ptr);
logprintf ("fetch_bool: 0x%08x (%d)\n", *in_ptr, *in_ptr);
}
assert (in_ptr + 1 <= in_end); assert (in_ptr + 1 <= in_end);
assert (*(in_ptr) == (int)CODE_bool_true || *(in_ptr) == (int)CODE_bool_false); assert (*(in_ptr) == (int)CODE_bool_true || *(in_ptr) == (int)CODE_bool_false);
return *(in_ptr ++) == (int)CODE_bool_true; return *(in_ptr ++) == (int)CODE_bool_true;
...@@ -349,14 +345,14 @@ void init_aes_unauth (const char server_nonce[16], const char hidden_client_nonc ...@@ -349,14 +345,14 @@ void init_aes_unauth (const char server_nonce[16], const char hidden_client_nonc
void init_aes_auth (char auth_key[192], char msg_key[16], int encrypt); void init_aes_auth (char auth_key[192], char msg_key[16], int encrypt);
int pad_aes_encrypt (char *from, int from_len, char *to, int size); int pad_aes_encrypt (char *from, int from_len, char *to, int size);
int pad_aes_decrypt (char *from, int from_len, char *to, int size); int pad_aes_decrypt (char *from, int from_len, char *to, int size);
/*
static inline void hexdump_in (void) { static inline void hexdump_in (void) {
hexdump (in_ptr, in_end); hexdump (in_ptr, in_end);
} }
static inline void hexdump_out (void) { static inline void hexdump_out (void) {
hexdump (packet_buffer, packet_ptr); hexdump (packet_buffer, packet_ptr);
} }*/
#ifdef __MACH__ #ifdef __MACH__
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
......
...@@ -26,9 +26,6 @@ struct dc; ...@@ -26,9 +26,6 @@ struct dc;
#define TG_SERVER_TEST "173.240.5.253" #define TG_SERVER_TEST "173.240.5.253"
#define TG_APP_HASH "36722c72256a24c1225de00eb6a1ca74" #define TG_APP_HASH "36722c72256a24c1225de00eb6a1ca74"
#define TG_APP_ID 2899 #define TG_APP_ID 2899
#define TG_BUILD "209"
#define TG_VERSION "0.01-beta"
#define ACK_TIMEOUT 1 #define ACK_TIMEOUT 1
#define MAX_DC_ID 10 #define MAX_DC_ID 10
......
This diff is collapsed.
...@@ -50,10 +50,12 @@ struct query { ...@@ -50,10 +50,12 @@ struct query {
struct dc *DC; struct dc *DC;
struct session *session; struct session *session;
void *extra; void *extra;
void *callback;
void *callback_extra;
}; };
struct query *send_query (struct dc *DC, int len, void *data, struct query_methods *methods, void *extra); struct query *send_query (struct dc *DC, int len, void *data, struct query_methods *methods, void *extra, void *callback, void *callback_extra);
void query_ack (long long id); void query_ack (long long id);
void query_error (long long id); void query_error (long long id);
void query_result (long long id); void query_result (long long id);
...@@ -64,13 +66,13 @@ void remove_event_timer (struct event_timer *ev); ...@@ -64,13 +66,13 @@ void remove_event_timer (struct event_timer *ev);
double next_timer_in (void); double next_timer_in (void);
void work_timers (void); void work_timers (void);
extern struct query_methods help_get_config_methods; //extern struct query_methods help_get_config_methods;
double get_double_time (void); double get_double_time (void);
// For binlog // For binlog
int get_dh_config_on_answer (struct query *q); //int get_dh_config_on_answer (struct query *q);
void fetch_dc_option (void); //void fetch_dc_option (void);
#endif #endif
...@@ -1628,9 +1628,9 @@ void tglm_message_remove_unsent (struct tgl_message *M) { ...@@ -1628,9 +1628,9 @@ void tglm_message_remove_unsent (struct tgl_message *M) {
static void __send_msg (struct tgl_message *M) { static void __send_msg (struct tgl_message *M) {
vlogprintf (E_NOTICE, "Resending message...\n"); vlogprintf (E_NOTICE, "Resending message...\n");
print_message (M); //print_message (M);
tgl_do_send_msg (M); tgl_do_send_msg (M, 0, 0);
} }
void tglm_send_all_unsent (void ) { void tglm_send_all_unsent (void ) {
......
...@@ -5,3 +5,19 @@ ...@@ -5,3 +5,19 @@
#include "tgl.h" #include "tgl.h"
struct tgl_state tgl_state; struct tgl_state tgl_state;
void tgl_set_binlog_mode (int mode) {
tgl_state.binlog_enabled = mode;
}
void tgl_set_binlog_path (const char *path) {
tgl_state.binlog_name = tstrdup (path);
}
void tgl_set_auth_file_path (const char *path) {
tgl_state.auth_file = tstrdup (path);
}
void tgl_set_download_directory (const char *path) {
tgl_state.downloads_directory = tstrdup (path);
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment