Commit bf86f756 authored by Vysheng's avatar Vysheng

fixes

parent 418cad58
This diff is collapsed.
......@@ -21,33 +21,29 @@
#include "structures.h"
void *alloc_log_event (int l);
void replay_log (void);
void add_log_event (const int *data, int l);
void write_binlog (void);
void bl_do_set_auth_key_id (int num, unsigned char *buf);
void bl_do_dc_option (int id, int l1, const char *name, int l2, const char *ip, int port);
void bl_do_set_our_id (int id);
void bl_do_user_add (int id, const char *f, int fl, const char *l, int ll, long long access_token, const char *p, int pl, int contact);
void bl_do_user_delete (struct user *U);
void bl_do_set_user_profile_photo (struct user *U, long long photo_id, struct file_location *big, struct file_location *small);
void bl_do_user_set_name (struct user *U, const char *f, int fl, const char *l, int ll);
void bl_do_user_set_access_hash (struct user *U, long long access_token);
void bl_do_user_set_phone (struct user *U, const char *p, int pl);
void bl_do_user_set_friend (struct user *U, int friend);
void bl_do_user_set_full_photo (struct user *U, const int *start, int len);
void bl_do_user_set_blocked (struct user *U, int blocked);
void bl_do_user_set_real_name (struct user *U, const char *f, int fl, const char *l, int ll);
void bl_do_user_delete (struct tgl_user *U);
void bl_do_set_user_profile_photo (struct tgl_user *U, long long photo_id, struct tgl_file_location *big, struct tgl_file_location *small);
void bl_do_user_set_name (struct tgl_user *U, const char *f, int fl, const char *l, int ll);
void bl_do_user_set_access_hash (struct tgl_user *U, long long access_token);
void bl_do_user_set_phone (struct tgl_user *U, const char *p, int pl);
void bl_do_user_set_friend (struct tgl_user *U, int friend);
void bl_do_user_set_full_photo (struct tgl_user *U, const int *start, int len);
void bl_do_user_set_blocked (struct tgl_user *U, int blocked);
void bl_do_user_set_real_name (struct tgl_user *U, const char *f, int fl, const char *l, int ll);
void bl_do_encr_chat_delete (struct secret_chat *U);
void bl_do_encr_chat_requested (struct secret_chat *U, long long access_hash, int date, int admin_id, int user_id, unsigned char g_key[], unsigned char nonce[]);
void bl_do_encr_chat_set_access_hash (struct secret_chat *U, long long access_hash);
void bl_do_encr_chat_set_date (struct secret_chat *U, int date);
void bl_do_encr_chat_set_state (struct secret_chat *U, enum secret_chat_state state);
void bl_do_encr_chat_accepted (struct secret_chat *U, const unsigned char g_key[], const unsigned char nonce[], long long key_fingerprint);
void bl_do_encr_chat_set_key (struct secret_chat *E, unsigned char key[], long long key_fingerprint);
void bl_do_encr_chat_delete (struct tgl_secret_chat *U);
void bl_do_encr_chat_requested (struct tgl_secret_chat *U, long long access_hash, int date, int admin_id, int user_id, unsigned char g_key[], unsigned char nonce[]);
void bl_do_encr_chat_set_access_hash (struct tgl_secret_chat *U, long long access_hash);
void bl_do_encr_chat_set_date (struct tgl_secret_chat *U, int date);
void bl_do_encr_chat_set_state (struct tgl_secret_chat *U, enum tgl_secret_chat_state state);
void bl_do_encr_chat_accepted (struct tgl_secret_chat *U, const unsigned char g_key[], const unsigned char nonce[], long long key_fingerprint);
void bl_do_encr_chat_set_key (struct tgl_secret_chat *E, unsigned char key[], long long key_fingerprint);
void bl_do_encr_chat_init (int id, int user_id, unsigned char random[], unsigned char g_a[]);
void bl_do_dc_signed (int id);
......@@ -59,18 +55,18 @@ void bl_do_set_qts (int qts);
void bl_do_set_seq (int seq);
void bl_do_set_date (int date);
void bl_do_create_chat (struct chat *C, int y, const char *s, int l, int users_num, int date, int version, struct file_location *big, struct file_location *small);
void bl_do_chat_forbid (struct chat *C, int on);
void bl_do_chat_set_title (struct chat *C, const char *s, int l);
void bl_do_chat_set_photo (struct chat *C, struct file_location *big, struct file_location *small);
void bl_do_chat_set_date (struct chat *C, int date);
void bl_do_chat_set_set_in_chat (struct chat *C, int on);
void bl_do_chat_set_version (struct chat *C, int version, int user_num);
void bl_do_chat_set_admin (struct chat *C, int admin);
void bl_do_chat_set_participants (struct chat *C, int version, int user_num, struct chat_user *users);
void bl_do_chat_set_full_photo (struct chat *U, const int *start, int len);
void bl_do_chat_add_user (struct chat *C, int version, int user, int inviter, int date);
void bl_do_chat_del_user (struct chat *C, int version, int user);
void bl_do_create_chat (struct tgl_chat *C, int y, const char *s, int l, int users_num, int date, int version, struct tgl_file_location *big, struct tgl_file_location *small);
void bl_do_chat_forbid (struct tgl_chat *C, int on);
void bl_do_chat_set_title (struct tgl_chat *C, const char *s, int l);
void bl_do_chat_set_photo (struct tgl_chat *C, struct tgl_file_location *big, struct tgl_file_location *small);
void bl_do_chat_set_date (struct tgl_chat *C, int date);
void bl_do_chat_set_set_in_chat (struct tgl_chat *C, int on);
void bl_do_chat_set_version (struct tgl_chat *C, int version, int user_num);
void bl_do_chat_set_admin (struct tgl_chat *C, int admin);
void bl_do_chat_set_participants (struct tgl_chat *C, int version, int user_num, struct tgl_chat_user *users);
void bl_do_chat_set_full_photo (struct tgl_chat *U, const int *start, int len);
void bl_do_chat_add_user (struct tgl_chat *C, int version, int user, int inviter, int date);
void bl_do_chat_del_user (struct tgl_chat *C, int version, int user);
void bl_do_create_message_text (int msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s);
void bl_do_create_message_text_fwd (int msg_id, int from_id, int to_type, int to_id, int date, int fwd, int fwd_date, int l, const char *s);
......@@ -82,8 +78,8 @@ void bl_do_create_message_media_encr (long long msg_id, int from_id, int to_type
void bl_do_create_message_service_encr (long long msg_id, int from_id, int to_type, int to_id, int date, const int *data, int len);
void bl_do_send_message_text (long long msg_id, int from_id, int to_type, int to_id, int date, int l, const char *s);
void bl_do_send_message_action_encr (long long msg_id, int from_id, int to_type, int to_id, int date, int l, const int *s);
void bl_do_set_unread (struct message *M, int unread);
void bl_do_set_message_sent (struct message *M);
void bl_do_set_msg_id (struct message *M, int id);
void bl_do_delete_msg (struct message *M);
void bl_do_set_unread (struct tgl_message *M, int unread);
void bl_do_set_message_sent (struct tgl_message *M);
void bl_do_set_msg_id (struct tgl_message *M, int id);
void bl_do_delete_msg (struct tgl_message *M);
#endif
This diff is collapsed.
......@@ -19,6 +19,7 @@
#ifndef __INTERFACE_H__
#define __INTERFACE_H__
#include "structures.h"
#include "tgl-layout.h"
#define COLOR_RED "\033[0;31m"
#define COLOR_REDB "\033[1;31m"
......@@ -48,7 +49,7 @@ void logprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)))
#define vlogprintf(v,...) \
do { \
if (tgl_params.verbosity >= (v)) {\
if (tgl_state.verbosity >= (v)) {\
logprintf (__VA_ARGS__);\
}\
} while (0);\
......@@ -56,14 +57,13 @@ void logprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)))
void hexdump (int *in_ptr, int *in_end);
struct message;
union peer;
void print_message (struct message *M);
void print_chat_name (peer_id_t id, union peer *C);
void print_user_name (peer_id_t id, union peer *U);
void print_encr_chat_name_full (peer_id_t id, peer_t *C);
void print_encr_chat_name (peer_id_t id, peer_t *C);
//void print_media (struct message_media *M);
struct tgl_message;
void print_message (struct tgl_message *M);
void print_chat_name (tgl_peer_id_t id, tgl_peer_t *C);
void print_user_name (tgl_peer_id_t id, tgl_peer_t *U);
void print_encr_chat_name_full (tgl_peer_id_t id, tgl_peer_t *C);
void print_encr_chat_name (tgl_peer_id_t id, tgl_peer_t *C);
//void print_media (struct tgl_message_media *M);
void pop_color (void);
void push_color (const char *color);
void print_start (void);
......
......@@ -60,9 +60,7 @@
extern char *default_username;
extern char *auth_token;
extern int test_dc;
void set_default_username (const char *s);
int default_dc_num;
extern int binlog_enabled;
extern int unknown_user_list_pos;
......@@ -71,7 +69,6 @@ int register_mode;
extern int safe_quit;
extern int queries_num;
int unread_messages;
void got_it (char *line, int len);
void net_loop (int flags, int (*is_end)(void)) {
while (!is_end ()) {
......@@ -93,7 +90,7 @@ void net_loop (int flags, int (*is_end)(void)) {
}
work_timers ();
if ((flags & 3) && (fds[0].revents & POLLIN)) {
unread_messages = 0;
tgl_state.unread_messages = 0;
if (flags & 1) {
rl_callback_read_char ();
} else {
......@@ -113,7 +110,7 @@ void net_loop (int flags, int (*is_end)(void)) {
exit (0);
}
if (unknown_user_list_pos) {
do_get_user_list_info_silent (unknown_user_list_pos, unknown_user_list);
tgl_do_get_user_list_info_silent (unknown_user_list_pos, unknown_user_list);
unknown_user_list_pos = 0;
}
}
......@@ -153,11 +150,6 @@ int main_loop (void) {
return 0;
}
struct dc *DC_list[MAX_DC_ID + 1];
struct dc *DC_working;
int dc_working_num;
int auth_state;
char *get_auth_key_filename (void);
char *get_state_filename (void);
char *get_secret_chat_filename (void);
......@@ -229,7 +221,7 @@ void read_dc (int auth_file_fd, int id, unsigned ver) {
}
void empty_auth_file (void) {
alloc_dc (1, tstrdup (tgl_params.test_mode ? TG_SERVER_TEST : TG_SERVER), 443);
alloc_dc (1, tstrdup (tgl_state.test_mode ? TG_SERVER_TEST : TG_SERVER), 443);
dc_working_num = 1;
auth_state = 0;
write_auth_file ();
......@@ -324,7 +316,7 @@ void write_state_file (void) {
wseq = seq; wpts = pts; wqts = qts; wdate = last_date;
}
extern peer_t *Peers[];
extern tgl_peer_t *Peers[];
extern int peer_num;
extern int encr_root;
......@@ -349,18 +341,18 @@ void read_secret_chat_file (void) {
assert (read (fd, &cc, 4) == 4);
int i;
for (i = 0; i < cc; i++) {
peer_t *P = talloc0 (sizeof (*P));
struct secret_chat *E = &P->encr_chat;
tgl_peer_t *P = talloc0 (sizeof (*P));
struct tgl_secret_chat *E = &P->encr_chat;
int t;
assert (read (fd, &t, 4) == 4);
P->id = MK_ENCR_CHAT (t);
P->id = TGL_MK_ENCR_CHAT (t);
assert (read (fd, &P->flags, 4) == 4);
assert (read (fd, &t, 4) == 4);
assert (t > 0);
P->print_name = talloc (t + 1);
assert (read (fd, P->print_name, t) == t);
P->print_name[t] = 0;
peer_insert_name (P);
tglp_peer_insert_name (P);
assert (read (fd, &E->state, 4) == 4);
assert (read (fd, &E->user_id, 4) == 4);
......@@ -376,7 +368,7 @@ void read_secret_chat_file (void) {
}
assert (read (fd, E->key, 256) == 256);
assert (read (fd, &E->key_fingerprint, 8) == 8);
insert_encrypted_chat (P);
tglp_insert_encrypted_chat (P);
}
if (version >= 1) {
assert (read (fd, &encr_root, 4) == 4);
......@@ -389,16 +381,16 @@ void read_secret_chat_file (void) {
close (fd);
}
void count_encr_peer (peer_t *P, void *cc) {
if (get_peer_type (P->id) == PEER_ENCR_CHAT && P->encr_chat.state != sc_none && P->encr_chat.state != sc_deleted) {
void count_encr_peer (tgl_peer_t *P, void *cc) {
if (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT && P->encr_chat.state != sc_none && P->encr_chat.state != sc_deleted) {
(*(int *)cc) ++;
}
}
void write_encr_peer (peer_t *P, void *pfd) {
void write_encr_peer (tgl_peer_t *P, void *pfd) {
int fd = *(int *)pfd;
if (get_peer_type (P->id) == PEER_ENCR_CHAT && P->encr_chat.state != sc_none && P->encr_chat.state != sc_deleted) {
int t = get_peer_id (P->id);
if (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT && P->encr_chat.state != sc_none && P->encr_chat.state != sc_deleted) {
int t = tgl_get_peer_id (P->id);
assert (write (fd, &t, 4) == 4);
t = P->flags;
assert (write (fd, &t, 4) == 4);
......@@ -435,8 +427,8 @@ void write_secret_chat_file (void) {
assert (write (fd, x, 8) == 8);
int cc = 0;
peer_iterator_ex (count_encr_peer, &cc);
peer_iterator_ex (write_encr_peer, &fd);
tgl_peer_iterator_ex (count_encr_peer, &cc);
tgl_peer_iterator_ex (write_encr_peer, &fd);
assert (write (fd, &encr_root, 4) == 4);
if (encr_root) {
......@@ -468,9 +460,9 @@ int loop (void) {
if (binlog_enabled) {
double t = get_double_time ();
logprintf ("replay log start\n");
replay_log ();
tgl_replay_log ();
logprintf ("replay log end in %lf seconds\n", get_double_time () - t);
write_binlog ();
tgl_reopen_binlog_for_writing ();
#ifdef USE_LUA
lua_binlog_end ();
#endif
......@@ -493,7 +485,7 @@ int loop (void) {
if (verbosity) {
logprintf ("Requesting info about DC...\n");
}
do_help_get_config ();
tgl_do_help_get_config ();
net_loop (0, mcs);
if (verbosity) {
logprintf ("DC_info: %d new DC got\n", new_dc_num);
......@@ -519,11 +511,11 @@ int loop (void) {
set_default_username (user);
}
}
int res = do_auth_check_phone (default_username);
int res = tgl_do_auth_check_phone (default_username);
assert (res >= 0);
logprintf ("%s\n", res > 0 ? "phone registered" : "phone not registered");
if (res > 0 && !register_mode) {
do_send_code (default_username);
tgl_do_send_code (default_username);
char *code = 0;
size_t size = 0;
printf ("Code from sms (if you did not receive an SMS and want to be called, type \"call\"): ");
......@@ -534,11 +526,11 @@ int loop (void) {
}
if (!strcmp (code, "call")) {
printf ("You typed \"call\", switching to phone system.\n");
do_phone_call (default_username);
tgl_do_phone_call (default_username);
printf ("Calling you! Code: ");
continue;
}
if (do_send_code_result (code) >= 0) {
if (tgl_do_send_code_result (code) >= 0) {
break;
}
printf ("Invalid code. Try again: ");
......@@ -572,12 +564,12 @@ int loop (void) {
exit (EXIT_FAILURE);
}
int dc_num = do_get_nearest_dc ();
int dc_num = tgl_do_get_nearest_dc ();
assert (dc_num >= 0 && dc_num <= MAX_DC_NUM && DC_list[dc_num]);
dc_working_num = dc_num;
DC_working = DC_list[dc_working_num];
do_send_code (default_username);
tgl_do_send_code (default_username);
printf ("Code from sms (if you did not receive an SMS and want to be called, type \"call\"): ");
while (1) {
if (net_getline (&code, &size) == -1) {
......@@ -586,11 +578,11 @@ int loop (void) {
}
if (!strcmp (code, "call")) {
printf ("You typed \"call\", switching to phone system.\n");
do_phone_call (default_username);
tgl_do_phone_call (default_username);
printf ("Calling you! Code: ");
continue;
}
if (do_send_code_result_auth (code, first_name, last_name) >= 0) {
if (tgl_do_send_code_result_auth (code, first_name, last_name) >= 0) {
break;
}
printf ("Invalid code. Try again: ");
......@@ -601,8 +593,8 @@ int loop (void) {
}
for (i = 0; i <= MAX_DC_NUM; i++) if (DC_list[i] && !DC_list[i]->has_auth) {
do_export_auth (i);
do_import_auth (i);
tgl_do_export_auth (i);
tgl_do_import_auth (i);
bl_do_dc_signed (i);
write_auth_file ();
}
......@@ -616,15 +608,15 @@ int loop (void) {
set_interface_callbacks ();
do_get_difference ();
tgl_do_get_difference ();
net_loop (0, dgot);
#ifdef USE_LUA
lua_diff_end ();
#endif
send_all_unsent ();
tglm_send_all_unsent ();
do_get_dialog_list ();
tgl_do_get_dialog_list ();
if (wait_dialog_list) {
dialog_list_got = 0;
net_loop (0, dlgot);
......
......@@ -21,14 +21,15 @@ lua_State *luaState;
#include "tools.h"
#include "queries.h"
#include "net.h"
#include "tgl.h"
extern int verbosity;
static int have_file;
#define my_lua_checkstack(L,x) assert (lua_checkstack (L, x))
void push_user (peer_t *P UU);
void push_peer (peer_id_t id, peer_t *P);
void push_user (tgl_peer_t *P UU);
void push_peer (tgl_peer_id_t id, tgl_peer_t *P);
void lua_add_string_field (const char *name, const char *value) {
assert (name && strlen (name));
......@@ -47,15 +48,15 @@ void lua_add_num_field (const char *name, double value) {
lua_settable (luaState, -3);
}
void push_peer_type (int x) {
void push_tgl_peer_type (int x) {
switch (x) {
case PEER_USER:
case TGL_PEER_USER:
lua_pushstring (luaState, "user");
break;
case PEER_CHAT:
case TGL_PEER_CHAT:
lua_pushstring (luaState, "chat");
break;
case PEER_ENCR_CHAT:
case TGL_PEER_ENCR_CHAT:
lua_pushstring (luaState, "encr_chat");
break;
default:
......@@ -63,7 +64,7 @@ void push_peer_type (int x) {
}
}
void push_user (peer_t *P UU) {
void push_user (tgl_peer_t *P UU) {
my_lua_checkstack (luaState, 4);
lua_add_string_field ("first_name", P->user.first_name);
lua_add_string_field ("last_name", P->user.last_name);
......@@ -72,41 +73,41 @@ void push_user (peer_t *P UU) {
lua_add_string_field ("phone", P->user.phone);
}
void push_chat (peer_t *P) {
void push_chat (tgl_peer_t *P) {
my_lua_checkstack (luaState, 4);
assert (P->chat.title);
lua_add_string_field ("title", P->chat.title);
lua_add_num_field ("members_num", P->chat.users_num);
}
void push_encr_chat (peer_t *P) {
void push_encr_chat (tgl_peer_t *P) {
my_lua_checkstack (luaState, 4);
lua_pushstring (luaState, "user");
push_peer (MK_USER (P->encr_chat.user_id), peer_get (MK_USER (P->encr_chat.user_id)));
push_peer (TGL_MK_USER (P->encr_chat.user_id), tgl_peer_get (TGL_MK_USER (P->encr_chat.user_id)));
lua_settable (luaState, -3);
}
void push_peer (peer_id_t id, peer_t *P) {
void push_peer (tgl_peer_id_t id, tgl_peer_t *P) {
lua_newtable (luaState);
lua_add_num_field ("id", get_peer_id (id));
lua_add_num_field ("id", tgl_get_peer_id (id));
lua_pushstring (luaState, "type");
push_peer_type (get_peer_type (id));
push_tgl_peer_type (tgl_get_peer_type (id));
lua_settable (luaState, -3);
if (!P || !(P->flags & FLAG_CREATED)) {
lua_pushstring (luaState, "print_name");
static char s[100];
switch (get_peer_type (id)) {
case PEER_USER:
sprintf (s, "user#%d", get_peer_id (id));
switch (tgl_get_peer_type (id)) {
case TGL_PEER_USER:
sprintf (s, "user#%d", tgl_get_peer_id (id));
break;
case PEER_CHAT:
sprintf (s, "chat#%d", get_peer_id (id));
case TGL_PEER_CHAT:
sprintf (s, "chat#%d", tgl_get_peer_id (id));
break;
case PEER_ENCR_CHAT:
sprintf (s, "encr_chat#%d", get_peer_id (id));
case TGL_PEER_ENCR_CHAT:
sprintf (s, "encr_chat#%d", tgl_get_peer_id (id));
break;
default:
assert (0);
......@@ -120,14 +121,14 @@ void push_peer (peer_id_t id, peer_t *P) {
lua_add_string_field ("print_name", P->print_name);
lua_add_num_field ("flags", P->flags);
switch (get_peer_type (id)) {
case PEER_USER:
switch (tgl_get_peer_type (id)) {
case TGL_PEER_USER:
push_user (P);
break;
case PEER_CHAT:
case TGL_PEER_CHAT:
push_chat (P);
break;
case PEER_ENCR_CHAT:
case TGL_PEER_ENCR_CHAT:
push_encr_chat (P);
break;
default:
......@@ -135,7 +136,7 @@ void push_peer (peer_id_t id, peer_t *P) {
}
}
void push_media (struct message_media *M) {
void push_media (struct tgl_message_media *M) {
my_lua_checkstack (luaState, 4);
switch (M->type) {
......@@ -176,7 +177,7 @@ void push_media (struct message_media *M) {
}
}
void push_message (struct message *M) {
void push_message (struct tgl_message *M) {
assert (M);
my_lua_checkstack (luaState, 10);
lua_newtable (luaState);
......@@ -186,20 +187,20 @@ void push_message (struct message *M) {
lua_add_string_field ("id", s);
lua_add_num_field ("flags", M->flags);
if (get_peer_type (M->fwd_from_id)) {
if (tgl_get_peer_type (M->fwd_from_id)) {
lua_pushstring (luaState, "fwd_from");
push_peer (M->fwd_from_id, peer_get (M->fwd_from_id));
push_peer (M->fwd_from_id, tgl_peer_get (M->fwd_from_id));
lua_settable (luaState, -3); // fwd_from
lua_add_num_field ("fwd_date", M->fwd_date);
}
lua_pushstring (luaState, "from");
push_peer (M->from_id, peer_get (M->from_id));
push_peer (M->from_id, tgl_peer_get (M->from_id));
lua_settable (luaState, -3);
lua_pushstring (luaState, "to");
push_peer (M->to_id, peer_get (M->to_id));
push_peer (M->to_id, tgl_peer_get (M->to_id));
lua_settable (luaState, -3);
lua_pushstring (luaState, "out");
......@@ -275,7 +276,7 @@ void lua_our_id (int id) {
}
}
void lua_new_msg (struct message *M UU) {
void lua_new_msg (struct tgl_message *M UU) {
if (!have_file) { return; }
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
......@@ -290,7 +291,7 @@ void lua_new_msg (struct message *M UU) {
}
}
void lua_secret_chat_created (struct secret_chat *C) {
void lua_secret_chat_created (struct tgl_secret_chat *C) {
if (!have_file) { return; }
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
......@@ -305,7 +306,7 @@ void lua_secret_chat_created (struct secret_chat *C) {
}
}
void lua_user_update (struct user *U) {
void lua_user_update (struct tgl_user *U) {
if (!have_file) { return; }
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
......@@ -320,7 +321,7 @@ void lua_user_update (struct user *U) {
}
}
void lua_chat_update (struct chat *C) {
void lua_chat_update (struct tgl_chat *C) {
if (!have_file) { return; }
lua_settop (luaState, 0);
//lua_checkstack (luaState, 20);
......@@ -335,15 +336,15 @@ void lua_chat_update (struct chat *C) {
}
}
extern peer_t *Peers[];
extern tgl_peer_t *Peers[];
extern int peer_num;
#define MAX_LUA_COMMANDS 1000
void *lua_ptr[MAX_LUA_COMMANDS];
static int pos;
static peer_t *get_peer (const char *s) {
return peer_lookup_name (s);
static tgl_peer_t *get_peer (const char *s) {
return tgl_peer_get_by_name (s);
}
void lua_do_all (void) {
......@@ -354,19 +355,19 @@ void lua_do_all (void) {
int f = (long)lua_ptr[p ++];
switch (f) {
case 0:
do_send_message (((peer_t *)lua_ptr[p])->id, lua_ptr[p + 1], strlen (lua_ptr[p + 1]));
tgl_do_send_message (((tgl_peer_t *)lua_ptr[p])->id, lua_ptr[p + 1], strlen (lua_ptr[p + 1]));
tfree_str (lua_ptr[p + 1]);
p += 2;
break;
case 1:
do_forward_message (((peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1]);
tgl_do_forward_message (((tgl_peer_t *)lua_ptr[p])->id, (long)lua_ptr[p + 1]);
p += 2;
break;
case 2:
#ifdef DEBUG
texists (lua_ptr[p], sizeof (peer_t));
texists (lua_ptr[p], sizeof (tgl_peer_t));
#endif
do_mark_read (((peer_t *)lua_ptr[p])->id);
tgl_do_mark_read (((tgl_peer_t *)lua_ptr[p])->id);
p += 1;
break;
default:
......@@ -394,7 +395,7 @@ static int send_msg_from_lua (lua_State *L) {
}
const char *msg = lua_tostring (L, -1);
peer_t *P = get_peer (s);
tgl_peer_t *P = get_peer (s);
if (!P) {
lua_pushboolean (L, 0);
return 1;
......@@ -426,7 +427,7 @@ static int fwd_msg_from_lua (lua_State *L) {
lua_pushboolean (L, 0);
return 1;
}
peer_t *P = get_peer (s);
tgl_peer_t *P = get_peer (s);
if (!P) {
lua_pushboolean (L, 0);
return 1;
......@@ -455,7 +456,7 @@ static int mark_read_from_lua (lua_State *L) {
lua_pushboolean (L, 0);
return 1;
}
peer_t *P = get_peer (s);
tgl_peer_t *P = get_peer (s);
if (!P) {
lua_pushboolean (L, 0);
return 1;
......
......@@ -5,11 +5,11 @@
#include "structures.h"
void lua_init (const char *file);
void lua_new_msg (struct message *M);
void lua_new_msg (struct tgl_message *M);
void lua_our_id (int id);
void lua_secret_chat_created (struct secret_chat *U);
void lua_user_update (struct user *U);
void lua_chat_update (struct chat *C);
void lua_secret_chat_created (struct tgl_secret_chat *U);
void lua_user_update (struct tgl_user *U);
void lua_chat_update (struct tgl_chat *C);
void lua_binlog_end (void);
void lua_diff_end (void);
void lua_do_all (void);
......
......@@ -298,9 +298,12 @@ void parse_config (void) {
buf[l ++] = '.';
}
tgl_params.test_mode = 0;
int test_mode = 0;
strcpy (buf + l, "test");
config_lookup_bool (&conf, buf, &tgl_params.test_mode);
config_lookup_bool (&conf, buf, &test_mode);
if (test_mode) {
tgl_set_test_mode ();
}
strcpy (buf + l, "log_level");
long long t = log_level;
......@@ -393,7 +396,7 @@ void args_parse (int argc, char **argv) {
rsa_public_key_name = tstrdup (optarg);
break;
case 'v':
tgl_params.verbosity ++;
tgl_incr_verbosity ();
break;
case 'N':
msg_num_mode ++;
......
This diff is collapsed.
This diff is collapsed.
......@@ -21,6 +21,7 @@
#define __QUERIES_H__
#include "structures.h"
#include "auto.h"
#include "tgl-layout.h"
#define QUERY_ACK_RECEIVED 1
......@@ -65,59 +66,8 @@ void work_timers (void);
extern struct query_methods help_get_config_methods;
void do_send_code (const char *user);
void do_phone_call (const char *user);
int do_send_code_result (const char *code);
double get_double_time (void);
void do_update_contact_list (void);
union user_chat;
void do_send_message (peer_id_t id, const char *msg, int len);
void do_send_text (peer_id_t id, char *file);
void do_get_history (peer_id_t id, int limit);
void do_get_dialog_list (void);
void do_get_dialog_list_ex (void);
void do_send_photo (int type, peer_id_t to_id, char *file_name);
void do_get_chat_info (peer_id_t id);
void do_get_user_list_info_silent (int num, int *list);
void do_get_user_info (peer_id_t id);
void do_forward_message (peer_id_t id, int n);
void do_rename_chat (peer_id_t id, char *name);
void do_load_encr_video (struct encr_video *V, int next);
void do_create_encr_chat_request (int user_id);
void do_create_secret_chat (peer_id_t id);
void do_create_group_chat (peer_id_t id, char *chat_topic);
void do_get_suggested (void);
struct photo;
struct video;
void do_load_photo (struct photo *photo, int next);
void do_load_video_thumb (struct video *video, int next);
void do_load_audio (struct video *V, int next);
void do_load_video (struct video *V, int next);
void do_load_document (struct document *V, int next);
void do_load_document_thumb (struct document *video, int next);
void do_help_get_config (void);
int do_auth_check_phone (const char *user);
int do_get_nearest_dc (void);
int do_send_code_result_auth (const char *code, const char *first_name, const char *last_name);
void do_import_auth (int num);
void do_export_auth (int num);
void do_add_contact (const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, int force);
void do_msg_search (peer_id_t id, int from, int to, int limit, const char *s);
void do_accept_encr_chat_request (struct secret_chat *E);
void do_get_difference (void);
void do_mark_read (peer_id_t id);
void do_visualize_key (peer_id_t id);
void do_create_keys_end (struct secret_chat *U);
void do_add_user_to_chat (peer_id_t chat_id, peer_id_t id, int limit);
void do_del_user_from_chat (peer_id_t chat_id, peer_id_t id);
void do_update_status (int online);
void do_contacts_search (int limit, const char *s);
void do_send_msg (struct message *M);
void do_delete_msg (long long id);
void do_restore_msg (long long id);
void do_send_encr_chat_layer (struct secret_chat *E);
// For binlog
......
This diff is collapsed.
......@@ -23,72 +23,31 @@
#include "tgl-layout.h"
#include "tgl-fetch.h"
char *create_print_name (peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
struct message *message_alloc (long long id);
void free_user (struct user *U);
void free_chat (struct chat *U);
int tgl_print_stat (char *s, int len);
peer_t *peer_get (peer_id_t id);
peer_t *peer_lookup_name (const char *s);
struct message *message_get (long long id);
void message_insert_tree (struct message *M);
void update_message_id (struct message *M, long long id);
void message_insert (struct message *M);
void free_photo (struct photo *P);
void insert_encrypted_chat (peer_t *P);
void insert_user (peer_t *P);
void insert_chat (peer_t *P);
void message_insert_unsent (struct message *M);
void message_remove_unsent (struct message *M);
void send_all_unsent (void);
void message_remove_tree (struct message *M);
void message_add_peer (struct message *M);
void message_del_peer (struct message *M);
void free_message (struct message *M);
void message_del_use (struct message *M);
void peer_insert_name (peer_t *P);
void peer_delete_name (peer_t *P);
void peer_iterator_ex (void (*it)(peer_t *P, void *extra), void *extra);
int complete_user_list (int index, const char *text, int len, char **R);
int complete_chat_list (int index, const char *text, int len, char **R);
int complete_encr_chat_list (int index, const char *text, int len, char **R);
int complete_peer_list (int index, const char *text, int len, char **R);
#define PEER_USER 1
#define PEER_CHAT 2
#define PEER_GEO_CHAT 3
#define PEER_ENCR_CHAT 4
#define PEER_UNKNOWN 0
#define MK_USER(id) set_peer_id (PEER_USER,id)
#define MK_CHAT(id) set_peer_id (PEER_CHAT,id)
#define MK_GEO_CHAT(id) set_peer_id (PEER_GEO_CHAT,id)
#define MK_ENCR_CHAT(id) set_peer_id (PEER_ENCR_CHAT,id)
static inline int get_peer_type (peer_id_t id) {
return id.type;
}
static inline int get_peer_id (peer_id_t id) {
return id.id;
}
static inline peer_id_t set_peer_id (int type, int id) {
peer_id_t ID;
ID.id = id;
ID.type = type;
return ID;
}
static inline int cmp_peer_id (peer_id_t a, peer_id_t b) {
return memcmp (&a, &b, sizeof (a));
}
char *create_print_name (tgl_peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
void tgls_free_user (struct tgl_user *U);
void tgls_free_chat (struct tgl_chat *U);
void tgls_free_photo (struct tgl_photo *P);
void tgls_free_message (struct tgl_message *M);
struct tgl_message *tglm_message_alloc (long long id);
void tglm_message_insert_tree (struct tgl_message *M);
void tglm_update_message_id (struct tgl_message *M, long long id);
void tglm_message_insert (struct tgl_message *M);
void tglm_message_insert_unsent (struct tgl_message *M);
void tglm_message_remove_unsent (struct tgl_message *M);
void tglm_send_all_unsent (void);
void tglm_message_remove_tree (struct tgl_message *M);
void tglm_message_add_peer (struct tgl_message *M);
void tglm_message_del_peer (struct tgl_message *M);
void tglm_message_del_use (struct tgl_message *M);
void tglm_message_add_use (struct tgl_message *M);
void tglp_peer_insert_name (tgl_peer_t *P);
void tglp_peer_delete_name (tgl_peer_t *P);
void tglp_insert_encrypted_chat (tgl_peer_t *P);
void tglp_insert_user (tgl_peer_t *P);
void tglp_insert_chat (tgl_peer_t *P);
#endif
......@@ -16,8 +16,7 @@
Copyright Vitaly Valtman 2013
*/
#define MAX_DC_NUM 9
#define MAX_PEER_NUM 100000
#define TGL_MAX_PEER_NUM 100000
#ifndef PROG_NAME
#define PROG_NAME "telegram-cli"
......
#ifndef __TGL_FETCH_H__
#define __TGL_FETCH_H__
int tglf_fetch_file_location (struct file_location *loc);
int tglf_fetch_user_status (struct user_status *S);
int tglf_fetch_user (struct user *U);
struct user *tglf_fetch_alloc_user (void);
struct user *tglf_fetch_alloc_user_full (void);
struct chat *tglf_fetch_alloc_chat (void);
struct chat *tglf_fetch_alloc_chat_full (void);
struct secret_chat *tglf_fetch_alloc_encrypted_chat (void);
struct message *tglf_fetch_alloc_message (void);
struct message *tglf_fetch_alloc_geo_message (void);
struct message *tglf_fetch_alloc_message_short (void);
struct message *tglf_fetch_alloc_message_short_chat (void);
struct message *tglf_fetch_alloc_encrypted_message (void);
void tglf_fetch_encrypted_message_file (struct message_media *M);
peer_id_t tglf_fetch_peer_id (void);
int tglf_fetch_file_location (struct tgl_file_location *loc);
int tglf_fetch_user_status (struct tgl_user_status *S);
int tglf_fetch_user (struct tgl_user *U);
struct tgl_user *tglf_fetch_alloc_user (void);
struct tgl_user *tglf_fetch_alloc_user_full (void);
struct tgl_chat *tglf_fetch_alloc_chat (void);
struct tgl_chat *tglf_fetch_alloc_chat_full (void);
struct tgl_secret_chat *tglf_fetch_alloc_encrypted_chat (void);
struct tgl_message *tglf_fetch_alloc_message (void);
struct tgl_message *tglf_fetch_alloc_geo_message (void);
struct tgl_message *tglf_fetch_alloc_message_short (void);
struct tgl_message *tglf_fetch_alloc_message_short_chat (void);
struct tgl_message *tglf_fetch_alloc_encrypted_message (void);
void tglf_fetch_encrypted_message_file (struct tgl_message_media *M);
tgl_peer_id_t tglf_fetch_peer_id (void);
void tglf_fetch_message_media (struct message_media *M);
void tglf_fetch_message_media_encrypted (struct message_media *M);
void tglf_fetch_message_action (struct message_action *M);
void tglf_fetch_message_action_encrypted (struct message_action *M);
void tglf_fetch_photo (struct photo *P);
void tglf_fetch_message_media (struct tgl_message_media *M);
void tglf_fetch_message_media_encrypted (struct tgl_message_media *M);
void tglf_fetch_message_action (struct tgl_message_action *M);
void tglf_fetch_message_action_encrypted (struct tgl_message_action *M);
void tglf_fetch_photo (struct tgl_photo *P);
void tglf_fetch_chat (struct tgl_chat *C);
void tglf_fetch_chat_full (struct tgl_chat *C);
void tglf_fetch_audio (struct tgl_audio *V);
void tglf_fetch_video (struct tgl_video *V);
void tglf_fetch_document (struct tgl_document *V);
void tglf_fetch_message (struct tgl_message *M);
void tglf_fetch_geo_message (struct tgl_message *M);
#endif
This diff is collapsed.
......@@ -3,6 +3,5 @@
#endif
#include "tgl.h"
struct tgl_params tgl_params;
struct tgl_state tgl_state;
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