This commit is contained in:
Vysheng 2014-08-13 19:55:16 +04:00
parent 418cad58d1
commit bf86f75604
18 changed files with 1533 additions and 1536 deletions

677
binlog.c

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -38,20 +38,21 @@
#endif
#include "include.h"
#include "queries.h"
//#include "queries.h"
#include "interface.h"
#include "telegram.h"
#include "structures.h"
#include "auto/constants.h"
#include "tools.h"
//#include "structures.h"
#include "mtproto-common.h"
//#include "mtproto-common.h"
#include "tgl.h"
#define ALLOW_MULT 1
char *default_prompt = "> ";
int unread_messages;
int msg_num_mode;
int alert_sound;
@ -62,17 +63,11 @@ int readline_active;
int log_level;
long long cur_uploading_bytes;
long long cur_uploaded_bytes;
long long cur_downloading_bytes;
long long cur_downloaded_bytes;
char *line_ptr;
extern peer_t *Peers[];
extern int peer_num;
int in_chat_mode;
peer_id_t chat_mode_id;
tgl_peer_id_t chat_mode_id;
int is_same_word (const char *s, size_t l, const char *word) {
@ -93,6 +88,7 @@ char *end_string_token (int *l) {
*l = line_ptr - s;
return s;
}
char *next_token (int *l) {
while (*line_ptr == ' ') { line_ptr ++; }
if (!*line_ptr) {
@ -103,14 +99,6 @@ char *next_token (int *l) {
char *s = line_ptr;
int in_str = 0;
while (*line_ptr && (*line_ptr != ' ' || neg || in_str)) {
/* if (*line_ptr == '\\') {
neg = 1 - neg;
} else {
if (*line_ptr == '"' && !neg) {
in_str = !in_str;
}
neg = 0;
}*/
line_ptr++;
}
*l = line_ptr - s;
@ -118,7 +106,7 @@ char *next_token (int *l) {
}
#define NOT_FOUND (int)0x80000000
peer_id_t PEER_NOT_FOUND = {.id = NOT_FOUND};
tgl_peer_id_t TGL_PEER_NOT_FOUND = {.id = NOT_FOUND};
long long next_token_int (void) {
int l;
@ -133,98 +121,98 @@ long long next_token_int (void) {
}
}
peer_id_t next_token_user (void) {
tgl_peer_id_t next_token_user (void) {
int l;
char *s = next_token (&l);
if (!s) { return PEER_NOT_FOUND; }
if (!s) { return TGL_PEER_NOT_FOUND; }
if (l >= 6 && !memcmp (s, "user#", 5)) {
s += 5;
l -= 5;
int r = atoi (s);
if (r >= 0) { return set_peer_id (PEER_USER, r); }
else { return PEER_NOT_FOUND; }
if (r >= 0) { return tgl_set_peer_id (TGL_PEER_USER, r); }
else { return TGL_PEER_NOT_FOUND; }
}
char c = s[l];
peer_t *P = peer_lookup_name (s);
tgl_peer_t *P = tgl_peer_get_by_name (s);
s[l] = c;
if (P && get_peer_type (P->id) == PEER_USER) {
if (P && tgl_get_peer_type (P->id) == TGL_PEER_USER) {
return P->id;
} else {
return PEER_NOT_FOUND;
return TGL_PEER_NOT_FOUND;
}
}
peer_id_t next_token_chat (void) {
tgl_peer_id_t next_token_chat (void) {
int l;
char *s = next_token (&l);
if (!s) { return PEER_NOT_FOUND; }
if (!s) { return TGL_PEER_NOT_FOUND; }
if (l >= 6 && !memcmp (s, "chat#", 5)) {
s += 5;
l -= 5;
int r = atoi (s);
if (r >= 0) { return set_peer_id (PEER_CHAT, r); }
else { return PEER_NOT_FOUND; }
if (r >= 0) { return tgl_set_peer_id (TGL_PEER_CHAT, r); }
else { return TGL_PEER_NOT_FOUND; }
}
char c = s[l];
peer_t *P = peer_lookup_name (s);
tgl_peer_t *P = tgl_peer_get_by_name (s);
s[l] = c;
if (P && get_peer_type (P->id) == PEER_CHAT) {
if (P && tgl_get_peer_type (P->id) == TGL_PEER_CHAT) {
return P->id;
} else {
return PEER_NOT_FOUND;
return TGL_PEER_NOT_FOUND;
}
}
peer_id_t next_token_encr_chat (void) {
tgl_peer_id_t next_token_encr_chat (void) {
int l;
char *s = next_token (&l);
if (!s) { return PEER_NOT_FOUND; }
if (!s) { return TGL_PEER_NOT_FOUND; }
char c = s[l];
peer_t *P = peer_lookup_name (s);
tgl_peer_t *P = tgl_peer_get_by_name (s);
s[l] = c;
if (P && get_peer_type (P->id) == PEER_ENCR_CHAT) {
if (P && tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT) {
return P->id;
} else {
return PEER_NOT_FOUND;
return TGL_PEER_NOT_FOUND;
}
}
peer_id_t next_token_peer (void) {
tgl_peer_id_t next_token_peer (void) {
int l;
char *s = next_token (&l);
if (!s) { return PEER_NOT_FOUND; }
if (!s) { return TGL_PEER_NOT_FOUND; }
if (l >= 6 && !memcmp (s, "user#", 5)) {
s += 5;
l -= 5;
int r = atoi (s);
if (r >= 0) { return set_peer_id (PEER_USER, r); }
else { return PEER_NOT_FOUND; }
if (r >= 0) { return tgl_set_peer_id (TGL_PEER_USER, r); }
else { return TGL_PEER_NOT_FOUND; }
}
if (l >= 6 && !memcmp (s, "chat#", 5)) {
s += 5;
l -= 5;
int r = atoi (s);
if (r >= 0) { return set_peer_id (PEER_CHAT, r); }
else { return PEER_NOT_FOUND; }
if (r >= 0) { return tgl_set_peer_id (TGL_PEER_CHAT, r); }
else { return TGL_PEER_NOT_FOUND; }
}
char c = s[l];
peer_t *P = peer_lookup_name (s);
tgl_peer_t *P = tgl_peer_get_by_name (s);
s[l] = c;
if (P) {
return P->id;
} else {
return PEER_NOT_FOUND;
return TGL_PEER_NOT_FOUND;
}
}
@ -232,26 +220,26 @@ char *get_default_prompt (void) {
static char buf[1000];
int l = 0;
if (in_chat_mode) {
peer_t *U = peer_get (chat_mode_id);
tgl_peer_t *U = tgl_peer_get (chat_mode_id);
assert (U && U->print_name);
l += tsnprintf (buf + l, 999 - l, COLOR_RED "%.*s " COLOR_NORMAL, 100, U->print_name);
}
if (unread_messages || cur_uploading_bytes || cur_downloading_bytes) {
if (tgl_state.unread_messages || tgl_state.cur_uploading_bytes || tgl_state.cur_downloading_bytes) {
l += tsnprintf (buf + l, 999 - l, COLOR_RED "[");
int ok = 0;
if (unread_messages) {
l += tsnprintf (buf + l, 999 - l, "%d unread", unread_messages);
if (tgl_state.unread_messages) {
l += tsnprintf (buf + l, 999 - l, "%d unread", tgl_state.unread_messages);
ok = 1;
}
if (cur_uploading_bytes) {
if (tgl_state.cur_uploading_bytes) {
if (ok) { *(buf + l) = ' '; l ++; }
ok = 1;
l += tsnprintf (buf + l, 999 - l, "%lld%%Up", 100 * cur_uploaded_bytes / cur_uploading_bytes);
l += tsnprintf (buf + l, 999 - l, "%lld%%Up", 100 * tgl_state.cur_uploaded_bytes / tgl_state.cur_uploading_bytes);
}
if (cur_downloading_bytes) {
if (tgl_state.cur_downloading_bytes) {
if (ok) { *(buf + l) = ' '; l ++; }
ok = 1;
l += tsnprintf (buf + l, 999 - l, "%lld%%Down", 100 * cur_downloaded_bytes / cur_downloading_bytes);
l += tsnprintf (buf + l, 999 - l, "%lld%%Down", 100 * tgl_state.cur_downloaded_bytes / tgl_state.cur_downloading_bytes);
}
l += tsnprintf (buf + l, 999 - l, "]" COLOR_NORMAL);
return buf;
@ -479,11 +467,11 @@ char *command_generator (const char *text, int state) {
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 1:
index = complete_user_list (index, text, len, &R);
index = tgl_complete_user_list (index, text, len, &R);
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 2:
index = complete_peer_list (index, text, len, &R);
index = tgl_complete_peer_list (index, text, len, &R);
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 3:
@ -491,11 +479,11 @@ char *command_generator (const char *text, int state) {
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 4:
index = complete_chat_list (index, text, len, &R);
index = tgl_complete_chat_list (index, text, len, &R);
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 5:
index = complete_encr_chat_list (index, text, len, &R);
index = tgl_complete_encr_chat_list (index, text, len, &R);
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 6:
@ -537,15 +525,15 @@ void interpreter_chat_mode (char *line) {
int limit = 40;
sscanf (line, "/history %99d", &limit);
if (limit < 0 || limit > 1000) { limit = 40; }
do_get_history (chat_mode_id, limit);
tgl_do_get_history (chat_mode_id, limit);
return;
}
if (!strncmp (line, "/read", 5)) {
do_mark_read (chat_mode_id);
tgl_do_mark_read (chat_mode_id);
return;
}
if (strlen (line)>0) {
do_send_message (chat_mode_id, line, strlen (line));
tgl_do_send_message (chat_mode_id, line, strlen (line));
}
}
@ -592,36 +580,36 @@ void interpreter (char *line UU) {
#define IS_WORD(s) is_same_word (command, l, (s))
#define RET in_readline = 0; return;
peer_id_t id;
tgl_peer_id_t id;
#define GET_PEER \
id = next_token_peer (); \
if (!cmp_peer_id (id, PEER_NOT_FOUND)) { \
if (!tgl_cmp_peer_id (id, TGL_PEER_NOT_FOUND)) { \
printf ("Bad user/chat id\n"); \
RET; \
}
#define GET_PEER_USER \
id = next_token_user (); \
if (!cmp_peer_id (id, PEER_NOT_FOUND)) { \
if (!tgl_cmp_peer_id (id, TGL_PEER_NOT_FOUND)) { \
printf ("Bad user id\n"); \
RET; \
}
#define GET_PEER_CHAT \
id = next_token_chat (); \
if (!cmp_peer_id (id, PEER_NOT_FOUND)) { \
if (!tgl_cmp_peer_id (id, TGL_PEER_NOT_FOUND)) { \
printf ("Bad chat id\n"); \
RET; \
}
#define GET_PEER_ENCR_CHAT \
id = next_token_encr_chat (); \
if (!cmp_peer_id (id, PEER_NOT_FOUND)) { \
if (!tgl_cmp_peer_id (id, TGL_PEER_NOT_FOUND)) { \
printf ("Bad encr_chat id\n"); \
RET; \
}
if (IS_WORD ("contact_list")) {
do_update_contact_list ();
tgl_do_update_contact_list ();
} else if (IS_WORD ("dialog_list")) {
do_get_dialog_list ();
tgl_do_get_dialog_list ();
} else if (IS_WORD ("stats")) {
static char stat_buf[1 << 15];
tgl_print_stat (stat_buf, (1 << 15) - 1);
@ -634,7 +622,7 @@ void interpreter (char *line UU) {
printf ("Empty message\n");
RET;
}
do_send_message (id, s, strlen (s));
tgl_do_send_message (id, s, strlen (s));
} else if (IS_WORD ("rename_chat")) {
GET_PEER_CHAT;
int t;
@ -643,7 +631,7 @@ void interpreter (char *line UU) {
printf ("Empty new name\n");
RET;
}
do_rename_chat (id, s);
tgl_do_rename_chat (id, s);
} else if (IS_WORD ("send_photo")) {
GET_PEER;
int t;
@ -652,7 +640,7 @@ void interpreter (char *line UU) {
printf ("Empty file name\n");
RET;
}
do_send_photo (CODE_input_media_uploaded_photo, id, tstrndup (s, t));
tgl_do_send_photo (CODE_input_media_uploaded_photo, id, tstrndup (s, t));
} else if (IS_WORD("send_video")) {
GET_PEER;
int t;
@ -661,7 +649,7 @@ void interpreter (char *line UU) {
printf ("Empty file name\n");
RET;
}
do_send_photo (CODE_input_media_uploaded_video, id, tstrndup (s, t));
tgl_do_send_photo (CODE_input_media_uploaded_video, id, tstrndup (s, t));
} else if (IS_WORD ("send_text")) {
GET_PEER;
int t;
@ -670,7 +658,7 @@ void interpreter (char *line UU) {
printf ("Empty file name\n");
RET;
}
do_send_text (id, tstrndup (s, t));
tgl_do_send_text (id, tstrndup (s, t));
} else if (IS_WORD ("fwd")) {
GET_PEER;
int num = next_token_int ();
@ -678,18 +666,18 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
do_forward_message (id, num);
tgl_do_forward_message (id, num);
} else if (IS_WORD ("load_photo")) {
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_photo) {
do_load_photo (&M->media.photo, 1);
tgl_do_load_photo (&M->media.photo, 1);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_photo) {
do_load_encr_video (&M->media.encr_video, 1); // this is not a bug.
tgl_do_load_encr_video (&M->media.encr_video, 1); // this is not a bug.
} else {
printf ("Bad msg id\n");
RET;
@ -700,11 +688,11 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_photo) {
do_load_photo (&M->media.photo, 2);
tgl_do_load_photo (&M->media.photo, 2);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_photo) {
do_load_encr_video (&M->media.encr_video, 2); // this is not a bug.
tgl_do_load_encr_video (&M->media.encr_video, 2); // this is not a bug.
} else {
printf ("Bad msg id\n");
RET;
@ -715,9 +703,9 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_video) {
do_load_video_thumb (&M->media.video, 1);
tgl_do_load_video_thumb (&M->media.video, 1);
} else {
printf ("Bad msg id\n");
RET;
@ -728,9 +716,9 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_video) {
do_load_video_thumb (&M->media.video, 2);
tgl_do_load_video_thumb (&M->media.video, 2);
} else {
printf ("Bad msg id\n");
RET;
@ -741,11 +729,11 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_video) {
do_load_video (&M->media.video, 1);
tgl_do_load_video (&M->media.video, 1);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_video) {
do_load_encr_video (&M->media.encr_video, 1);
tgl_do_load_encr_video (&M->media.encr_video, 1);
} else {
printf ("Bad msg id\n");
RET;
@ -756,35 +744,35 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_video) {
do_load_video (&M->media.video, 2);
tgl_do_load_video (&M->media.video, 2);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_video) {
do_load_encr_video (&M->media.encr_video, 2);
tgl_do_load_encr_video (&M->media.encr_video, 2);
} else {
printf ("Bad msg id\n");
RET;
}
} else if (IS_WORD ("chat_info")) {
GET_PEER_CHAT;
do_get_chat_info (id);
tgl_do_get_chat_info (id);
} else if (IS_WORD ("user_info")) {
GET_PEER_USER;
do_get_user_info (id);
tgl_do_get_user_info (id);
} else if (IS_WORD ("history")) {
GET_PEER;
int limit = next_token_int ();
do_get_history (id, limit > 0 ? limit : 40);
tgl_do_get_history (id, limit > 0 ? limit : 40);
} else if (IS_WORD ("chat_add_user")) {
GET_PEER_CHAT;
peer_id_t chat_id = id;
tgl_peer_id_t chat_id = id;
GET_PEER_USER;
do_add_user_to_chat (chat_id, id, 100);
tgl_do_add_user_to_chat (chat_id, id, 100);
} else if (IS_WORD ("chat_del_user")) {
GET_PEER_CHAT;
peer_id_t chat_id = id;
tgl_peer_id_t chat_id = id;
GET_PEER_USER;
do_del_user_from_chat (chat_id, id);
tgl_do_del_user_from_chat (chat_id, id);
} else if (IS_WORD ("add_contact")) {
int phone_len, first_name_len, last_name_len;
char *phone, *first_name, *last_name;
@ -803,10 +791,10 @@ void interpreter (char *line UU) {
printf ("No last name found\n");
RET;
}
do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 0);
tgl_do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 0);
} else if (IS_WORD ("rename_contact")) {
GET_PEER_USER;
peer_t *U = peer_get (id);
tgl_peer_t *U = tgl_peer_get (id);
if (!U) {
printf ("No such user\n");
RET;
@ -829,7 +817,7 @@ void interpreter (char *line UU) {
printf ("No last name found\n");
RET;
}
do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 1);
tgl_do_add_contact (phone, phone_len, first_name, first_name_len, last_name, last_name_len, 1);
} else if (IS_WORD ("help")) {
//print_start ();
push_color (COLOR_YELLOW);
@ -886,7 +874,7 @@ void interpreter (char *line UU) {
printf ("Empty message\n");
RET;
}
do_msg_search (id, from, to, limit, s);
tgl_do_msg_search (id, from, to, limit, s);
} else if (IS_WORD ("global_search")) {
int from = 0;
int to = 0;
@ -897,16 +885,16 @@ void interpreter (char *line UU) {
printf ("Empty message\n");
RET;
}
do_msg_search (PEER_NOT_FOUND, from, to, limit, s);
tgl_do_msg_search (TGL_PEER_NOT_FOUND, from, to, limit, s);
} else if (IS_WORD ("mark_read")) {
GET_PEER;
do_mark_read (id);
tgl_do_mark_read (id);
} else if (IS_WORD ("visualize_key")) {
GET_PEER_ENCR_CHAT;
do_visualize_key (id);
tgl_do_visualize_key (id);
} else if (IS_WORD ("create_secret_chat")) {
GET_PEER;
do_create_secret_chat (id);
tgl_do_create_secret_chat (id);
} else if (IS_WORD ("create_group_chat")) {
GET_PEER;
int t;
@ -915,13 +903,13 @@ void interpreter (char *line UU) {
printf ("Empty chat topic\n");
RET;
}
do_create_group_chat (id, s);
tgl_do_create_group_chat (id, s);
} else if (IS_WORD ("suggested_contacts")) {
do_get_suggested ();
tgl_do_get_suggested ();
} else if (IS_WORD ("status_online")) {
do_update_status (1);
tgl_do_update_status (1);
} else if (IS_WORD ("status_offline")) {
do_update_status (0);
tgl_do_update_status (0);
} else if (IS_WORD ("contacts_search")) {
int t;
char *s = next_token (&t);
@ -929,7 +917,7 @@ void interpreter (char *line UU) {
printf ("Empty search query\n");
RET;
}
do_contacts_search (100, s);
tgl_do_contacts_search (100, s);
} else if (IS_WORD("send_audio")) {
GET_PEER;
int t;
@ -938,7 +926,7 @@ void interpreter (char *line UU) {
printf ("Empty file name\n");
RET;
}
do_send_photo (CODE_input_media_uploaded_audio, id, tstrndup (s, t));
tgl_do_send_photo (CODE_input_media_uploaded_audio, id, tstrndup (s, t));
} else if (IS_WORD("send_document")) {
GET_PEER;
int t;
@ -947,18 +935,18 @@ void interpreter (char *line UU) {
printf ("Empty file name\n");
RET;
}
do_send_photo (CODE_input_media_uploaded_document, id, tstrndup (s, t));
tgl_do_send_photo (CODE_input_media_uploaded_document, id, tstrndup (s, t));
} else if (IS_WORD ("load_audio")) {
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_audio) {
do_load_audio (&M->media.video, 1);
tgl_do_load_audio (&M->media.video, 1);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_audio) {
do_load_encr_video (&M->media.encr_video, 1);
tgl_do_load_encr_video (&M->media.encr_video, 1);
} else {
printf ("Bad msg id\n");
RET;
@ -969,11 +957,11 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_audio) {
do_load_audio (&M->media.video, 2);
tgl_do_load_audio (&M->media.video, 2);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_audio) {
do_load_encr_video (&M->media.encr_video, 2);
tgl_do_load_encr_video (&M->media.encr_video, 2);
} else {
printf ("Bad msg id\n");
RET;
@ -984,9 +972,9 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_document) {
do_load_document_thumb (&M->media.document, 1);
tgl_do_load_document_thumb (&M->media.document, 1);
} else {
printf ("Bad msg id\n");
RET;
@ -997,9 +985,9 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_document) {
do_load_document_thumb (&M->media.document, 2);
tgl_do_load_document_thumb (&M->media.document, 2);
} else {
printf ("Bad msg id\n");
RET;
@ -1010,11 +998,11 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_document) {
do_load_document (&M->media.document, 1);
tgl_do_load_document (&M->media.document, 1);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_document) {
do_load_encr_video (&M->media.encr_video, 1);
tgl_do_load_encr_video (&M->media.encr_video, 1);
} else {
printf ("Bad msg id\n");
RET;
@ -1025,11 +1013,11 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
struct message *M = message_get (num);
struct tgl_message *M = tgl_message_get (num);
if (M && !M->service && M->media.type == CODE_message_media_document) {
do_load_document (&M->media.document, 2);
tgl_do_load_document (&M->media.document, 2);
} else if (M && !M->service && M->media.type == CODE_decrypted_message_media_document) {
do_load_encr_video (&M->media.encr_video, 2);
tgl_do_load_encr_video (&M->media.encr_video, 2);
} else {
printf ("Bad msg id\n");
RET;
@ -1042,7 +1030,7 @@ void interpreter (char *line UU) {
RET;
}
if (IS_WORD ("debug_verbosity")) {
verbosity = num;
tgl_set_verbosity (num);
} else if (IS_WORD ("log_level")) {
log_level = num;
} else if (IS_WORD ("msg_num")) {
@ -1060,22 +1048,22 @@ void interpreter (char *line UU) {
printf ("Bad msg id\n");
RET;
}
do_delete_msg (num);
tgl_do_delete_msg (num);
} else if (IS_WORD ("restore_msg")) {
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
do_restore_msg (num);
tgl_do_restore_msg (num);
} else if (IS_WORD ("delete_restore_msg")) {
long long num = next_token_int ();
if (num == NOT_FOUND) {
printf ("Bad msg id\n");
RET;
}
do_delete_msg (num);
do_restore_msg (num);
tgl_do_delete_msg (num);
tgl_do_restore_msg (num);
} else if (IS_WORD ("quit")) {
exit (0);
} else if (IS_WORD ("safe_quit")) {
@ -1186,7 +1174,7 @@ void pop_color (void) {
}
}
void print_media (struct message_media *M) {
void print_media (struct tgl_message_media *M) {
assert (M);
switch (M->type) {
case CODE_message_media_empty:
@ -1255,31 +1243,31 @@ void print_media (struct message_media *M) {
int unknown_user_list_pos;
int unknown_user_list[1000];
void print_user_name (peer_id_t id, peer_t *U) {
assert (get_peer_type (id) == PEER_USER);
void print_user_name (tgl_peer_id_t id, tgl_peer_t *U) {
assert (tgl_get_peer_type (id) == TGL_PEER_USER);
push_color (COLOR_RED);
if (!U) {
printf ("user#%d", get_peer_id (id));
printf ("user#%d", tgl_get_peer_id (id));
int i;
int ok = 1;
for (i = 0; i < unknown_user_list_pos; i++) {
if (unknown_user_list[i] == get_peer_id (id)) {
if (unknown_user_list[i] == tgl_get_peer_id (id)) {
ok = 0;
break;
}
}
if (ok) {
assert (unknown_user_list_pos < 1000);
unknown_user_list[unknown_user_list_pos ++] = get_peer_id (id);
unknown_user_list[unknown_user_list_pos ++] = tgl_get_peer_id (id);
}
} else {
if (U->flags & (FLAG_USER_SELF | FLAG_USER_CONTACT)) {
push_color (COLOR_REDB);
}
if ((U->flags & FLAG_DELETED)) {
printf ("deleted user#%d", get_peer_id (id));
printf ("deleted user#%d", tgl_get_peer_id (id));
} else if (!(U->flags & FLAG_CREATED)) {
printf ("empty user#%d", get_peer_id (id));
printf ("empty user#%d", tgl_get_peer_id (id));
} else if (!U->user.first_name || !strlen (U->user.first_name)) {
printf ("%s", U->user.last_name);
} else if (!U->user.last_name || !strlen (U->user.last_name)) {
@ -1294,33 +1282,33 @@ void print_user_name (peer_id_t id, peer_t *U) {
pop_color ();
}
void print_chat_name (peer_id_t id, peer_t *C) {
assert (get_peer_type (id) == PEER_CHAT);
void print_chat_name (tgl_peer_id_t id, tgl_peer_t *C) {
assert (tgl_get_peer_type (id) == TGL_PEER_CHAT);
push_color (COLOR_MAGENTA);
if (!C) {
printf ("chat#%d", get_peer_id (id));
printf ("chat#%d", tgl_get_peer_id (id));
} else {
printf ("%s", C->chat.title);
}
pop_color ();
}
void print_encr_chat_name (peer_id_t id, peer_t *C) {
assert (get_peer_type (id) == PEER_ENCR_CHAT);
void print_encr_chat_name (tgl_peer_id_t id, tgl_peer_t *C) {
assert (tgl_get_peer_type (id) == TGL_PEER_ENCR_CHAT);
push_color (COLOR_MAGENTA);
if (!C) {
printf ("encr_chat#%d", get_peer_id (id));
printf ("encr_chat#%d", tgl_get_peer_id (id));
} else {
printf ("%s", C->print_name);
}
pop_color ();
}
void print_encr_chat_name_full (peer_id_t id, peer_t *C) {
assert (get_peer_type (id) == PEER_ENCR_CHAT);
void print_encr_chat_name_full (tgl_peer_id_t id, tgl_peer_t *C) {
assert (tgl_get_peer_type (id) == TGL_PEER_ENCR_CHAT);
push_color (COLOR_MAGENTA);
if (!C) {
printf ("encr_chat#%d", get_peer_id (id));
printf ("encr_chat#%d", tgl_get_peer_id (id));
} else {
printf ("%s", C->print_name);
}
@ -1342,7 +1330,7 @@ void print_date_full (long t) {
printf ("[%04d/%02d/%02d %02d:%02d:%02d]", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
}
void print_service_message (struct message *M) {
void print_service_message (struct tgl_message *M) {
assert (M);
print_start ();
push_color (COLOR_GREY);
@ -1354,14 +1342,14 @@ void print_service_message (struct message *M) {
print_date (M->date);
pop_color ();
printf (" ");
if (get_peer_type (M->to_id) == PEER_CHAT) {
print_chat_name (M->to_id, peer_get (M->to_id));
if (tgl_get_peer_type (M->to_id) == TGL_PEER_CHAT) {
print_chat_name (M->to_id, tgl_peer_get (M->to_id));
} else {
assert (get_peer_type (M->to_id) == PEER_ENCR_CHAT);
print_encr_chat_name (M->to_id, peer_get (M->to_id));
assert (tgl_get_peer_type (M->to_id) == TGL_PEER_ENCR_CHAT);
print_encr_chat_name (M->to_id, tgl_peer_get (M->to_id));
}
printf (" ");
print_user_name (M->from_id, peer_get (M->from_id));
print_user_name (M->from_id, tgl_peer_get (M->from_id));
switch (M->action.type) {
case CODE_message_action_empty:
@ -1388,12 +1376,12 @@ void print_service_message (struct message *M) {
break;
case CODE_message_action_chat_add_user:
printf (" added user ");
print_user_name (set_peer_id (PEER_USER, M->action.user), peer_get (set_peer_id (PEER_USER, M->action.user)));
print_user_name (tgl_set_peer_id (TGL_PEER_USER, M->action.user), tgl_peer_get (tgl_set_peer_id (TGL_PEER_USER, M->action.user)));
printf ("\n");
break;
case CODE_message_action_chat_delete_user:
printf (" deleted user ");
print_user_name (set_peer_id (PEER_USER, M->action.user), peer_get (set_peer_id (PEER_USER, M->action.user)));
print_user_name (tgl_set_peer_id (TGL_PEER_USER, M->action.user), tgl_peer_get (tgl_set_peer_id (TGL_PEER_USER, M->action.user)));
printf ("\n");
break;
case CODE_decrypted_message_action_set_message_t_t_l:
@ -1421,10 +1409,10 @@ void print_service_message (struct message *M) {
print_end ();
}
peer_id_t last_from_id;
peer_id_t last_to_id;
tgl_peer_id_t last_from_id;
tgl_peer_id_t last_to_id;
void print_message (struct message *M) {
void print_message (struct tgl_message *M) {
assert (M);
if (M->flags & (FLAG_MESSAGE_EMPTY | FLAG_DELETED)) {
return;
@ -1434,7 +1422,7 @@ void print_message (struct message *M) {
print_service_message (M);
return;
}
if (!get_peer_type (M->to_id)) {
if (!tgl_get_peer_type (M->to_id)) {
logprintf ("Bad msg\n");
return;
}
@ -1443,7 +1431,7 @@ void print_message (struct message *M) {
last_to_id = M->to_id;
print_start ();
if (get_peer_type (M->to_id) == PEER_USER) {
if (tgl_get_peer_type (M->to_id) == TGL_PEER_USER) {
if (M->out) {
push_color (COLOR_GREEN);
if (msg_num_mode) {
@ -1452,7 +1440,7 @@ void print_message (struct message *M) {
print_date (M->date);
pop_color ();
printf (" ");
print_user_name (M->to_id, peer_get (M->to_id));
print_user_name (M->to_id, tgl_peer_get (M->to_id));
push_color (COLOR_GREEN);
if (M->unread) {
printf (" <<< ");
@ -1467,7 +1455,7 @@ void print_message (struct message *M) {
print_date (M->date);
pop_color ();
printf (" ");
print_user_name (M->from_id, peer_get (M->from_id));
print_user_name (M->from_id, tgl_peer_get (M->from_id));
push_color (COLOR_BLUE);
if (M->unread) {
printf (" >>> ");
@ -1478,8 +1466,8 @@ void print_message (struct message *M) {
play_sound();
}
}
} else if (get_peer_type (M->to_id) == PEER_ENCR_CHAT) {
peer_t *P = peer_get (M->to_id);
} else if (tgl_get_peer_type (M->to_id) == TGL_PEER_ENCR_CHAT) {
tgl_peer_t *P = tgl_peer_get (M->to_id);
assert (P);
if (M->out) {
push_color (COLOR_GREEN);
@ -1515,7 +1503,7 @@ void print_message (struct message *M) {
}
}
} else {
assert (get_peer_type (M->to_id) == PEER_CHAT);
assert (tgl_get_peer_type (M->to_id) == TGL_PEER_CHAT);
push_color (COLOR_MAGENTA);
if (msg_num_mode) {
printf ("%lld ", M->id);
@ -1523,10 +1511,10 @@ void print_message (struct message *M) {
print_date (M->date);
pop_color ();
printf (" ");
print_chat_name (M->to_id, peer_get (M->to_id));
print_chat_name (M->to_id, tgl_peer_get (M->to_id));
printf (" ");
print_user_name (M->from_id, peer_get (M->from_id));
if ((get_peer_type (M->from_id) == PEER_USER) && (get_peer_id (M->from_id) == tgl_state.our_id)) {
print_user_name (M->from_id, tgl_peer_get (M->from_id));
if ((tgl_get_peer_type (M->from_id) == TGL_PEER_USER) && (tgl_get_peer_id (M->from_id) == tgl_state.our_id)) {
push_color (COLOR_GREEN);
} else {
push_color (COLOR_BLUE);
@ -1537,9 +1525,9 @@ void print_message (struct message *M) {
printf (" »»» ");
}
}
if (get_peer_type (M->fwd_from_id) == PEER_USER) {
if (tgl_get_peer_type (M->fwd_from_id) == TGL_PEER_USER) {
printf ("[fwd from ");
print_user_name (M->fwd_from_id, peer_get (M->fwd_from_id));
print_user_name (M->fwd_from_id, tgl_peer_get (M->fwd_from_id));
printf ("] ");
}
if (M->message && strlen (M->message)) {

View File

@ -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);

72
loop.c
View File

@ -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);

View File

@ -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;

View File

@ -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);

9
main.c
View File

@ -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 ++;

View File

@ -54,6 +54,7 @@
#include "structures.h"
#include "binlog.h"
#include "auto.h"
#include "tgl.h"
#if defined(__FreeBSD__)
#define __builtin_bswap32(x) bswap32(x)
@ -831,7 +832,7 @@ void fetch_seq (void) {
int x = fetch_int ();
if (x > seq + 1) {
logprintf ("Hole in seq: seq = %d, x = %d\n", seq, x);
//do_get_difference ();
//tgl_do_get_difference ();
//seq = x;
} else if (x == seq + 1) {
seq = x;
@ -844,20 +845,20 @@ void work_update_binlog (void) {
switch (op) {
case CODE_update_user_name:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *UC = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *UC = tgl_peer_get (user_id);
if (UC) {
struct user *U = &UC->user;
struct tgl_user *U = &UC->user;
if (U->first_name) { tfree_str (U->first_name); }
if (U->last_name) { tfree_str (U->last_name); }
if (U->print_name) {
peer_delete_name (UC);
tglp_peer_delete_name (UC);
tfree_str (U->print_name);
}
U->first_name = fetch_str_dup ();
U->last_name = fetch_str_dup ();
U->print_name = create_print_name (U->id, U->first_name, U->last_name, 0, 0);
peer_insert_name ((void *)U);
tglp_peer_insert_name ((void *)U);
} else {
fetch_skip_str ();
fetch_skip_str ();
@ -866,11 +867,11 @@ void work_update_binlog (void) {
break;
case CODE_update_user_photo:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *UC = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *UC = tgl_peer_get (user_id);
fetch_date ();
if (UC) {
struct user *U = &UC->user;
struct tgl_user *U = &UC->user;
unsigned y = fetch_int ();
if (y == CODE_user_profile_photo_empty) {
@ -884,7 +885,7 @@ void work_update_binlog (void) {
tglf_fetch_file_location (&U->photo_big);
}
} else {
struct file_location t;
struct tgl_file_location t;
unsigned y = fetch_int ();
if (y == CODE_user_profile_photo_empty) {
} else {
@ -907,7 +908,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
switch (op) {
case CODE_update_new_message:
{
struct message *M = tglf_fetch_alloc_message ();
struct tgl_message *M = tglf_fetch_alloc_message ();
assert (M);
fetch_pts ();
unread_messages ++;
@ -919,7 +920,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
{
int id = fetch_int (); // id
int new = fetch_long (); // random_id
struct message *M = message_get (new);
struct tgl_message *M = tgl_message_get (new);
if (M) {
bl_do_set_msg_id (M, id);
}
@ -932,7 +933,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
int i;
for (i = 0; i < n; i++) {
int id = fetch_int ();
struct message *M = message_get (id);
struct tgl_message *M = tgl_message_get (id);
if (M) {
bl_do_set_unread (M, 0);
}
@ -950,8 +951,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_user_typing:
{
peer_id_t id = MK_USER (fetch_int ());
peer_t *U = peer_get (id);
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (id);
if (log_level >= 2) {
print_start ();
push_color (COLOR_YELLOW);
@ -966,10 +967,10 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_chat_user_typing:
{
peer_id_t chat_id = MK_CHAT (fetch_int ());
peer_id_t id = MK_USER (fetch_int ());
peer_t *C = peer_get (chat_id);
peer_t *U = peer_get (id);
tgl_peer_id_t chat_id = TGL_MK_CHAT (fetch_int ());
tgl_peer_id_t id = TGL_MK_USER (fetch_int ());
tgl_peer_t *C = tgl_peer_get (chat_id);
tgl_peer_t *U = tgl_peer_get (id);
if (log_level >= 2) {
print_start ();
push_color (COLOR_YELLOW);
@ -986,8 +987,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_user_status:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *U = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (user_id);
if (U) {
tglf_fetch_user_status (&U->user.status);
if (log_level >= 3) {
@ -1002,21 +1003,21 @@ void work_update (struct connection *c UU, long long msg_id UU) {
print_end ();
}
} else {
struct user_status t;
struct tgl_user_status t;
tglf_fetch_user_status (&t);
}
}
break;
case CODE_update_user_name:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *UC = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *UC = tgl_peer_get (user_id);
if (UC && (UC->flags & FLAG_CREATED)) {
int l1 = prefetch_strlen ();
char *f = fetch_str (l1);
int l2 = prefetch_strlen ();
char *l = fetch_str (l2);
struct user *U = &UC->user;
struct tgl_user *U = &UC->user;
bl_do_user_set_real_name (U, f, l1, l, l2);
print_start ();
push_color (COLOR_YELLOW);
@ -1036,15 +1037,15 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_user_photo:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *UC = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *UC = tgl_peer_get (user_id);
fetch_date ();
if (UC && (UC->flags & FLAG_CREATED)) {
struct user *U = &UC->user;
struct tgl_user *U = &UC->user;
unsigned y = fetch_int ();
long long photo_id;
struct file_location big;
struct file_location small;
struct tgl_file_location big;
struct tgl_file_location small;
memset (&big, 0, sizeof (big));
memset (&small, 0, sizeof (small));
if (y == CODE_user_profile_photo_empty) {
@ -1068,7 +1069,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
pop_color ();
print_end ();
} else {
struct file_location t;
struct tgl_file_location t;
unsigned y = fetch_int ();
if (y == CODE_user_profile_photo_empty) {
} else {
@ -1113,15 +1114,15 @@ void work_update (struct connection *c UU, long long msg_id UU) {
{
unsigned x = fetch_int ();
assert (x == CODE_chat_participants || x == CODE_chat_participants_forbidden);
peer_id_t chat_id = MK_CHAT (fetch_int ());
tgl_peer_id_t chat_id = TGL_MK_CHAT (fetch_int ());
int n = 0;
peer_t *C = peer_get (chat_id);
tgl_peer_t *C = tgl_peer_get (chat_id);
if (C && (C->flags & FLAG_CREATED)) {
if (x == CODE_chat_participants) {
bl_do_chat_set_admin (&C->chat, fetch_int ());
assert (fetch_int () == CODE_vector);
n = fetch_int ();
struct chat_user *users = talloc (12 * n);
struct tgl_chat_user *users = talloc (12 * n);
int i;
for (i = 0; i < n; i++) {
assert (fetch_int () == (int)CODE_chat_participant);
@ -1157,8 +1158,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_contact_registered:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *U = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (user_id);
fetch_int (); // date
print_start ();
push_color (COLOR_YELLOW);
@ -1172,8 +1173,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_contact_link:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *U = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (user_id);
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
@ -1196,8 +1197,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_activation:
{
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *U = peer_get (user_id);
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_t *U = tgl_peer_get (user_id);
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
@ -1227,7 +1228,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_new_geo_chat_message:
{
struct message *M = tglf_fetch_alloc_geo_message ();
struct tgl_message *M = tglf_fetch_alloc_geo_message ();
unread_messages ++;
print_message (M);
update_prompt ();
@ -1235,7 +1236,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_new_encrypted_message:
{
struct message *M = tglf_fetch_alloc_encrypted_message ();
struct tgl_message *M = tglf_fetch_alloc_encrypted_message ();
unread_messages ++;
print_message (M);
update_prompt ();
@ -1244,7 +1245,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_encryption:
{
struct secret_chat *E = tglf_fetch_alloc_encrypted_chat ();
struct tgl_secret_chat *E = tglf_fetch_alloc_encrypted_chat ();
if (verbosity >= 2) {
logprintf ("Secret chat state = %d\n", E->state);
}
@ -1278,25 +1279,25 @@ void work_update (struct connection *c UU, long long msg_id UU) {
pop_color ();
print_end ();
if (E->state == sc_request && !disable_auto_accept) {
do_accept_encr_chat_request (E);
tgl_do_accept_encr_chat_request (E);
}
if (E->state == sc_ok) {
do_send_encr_chat_layer (E);
tgl_do_send_encr_chat_layer (E);
}
fetch_int (); // date
}
break;
case CODE_update_encrypted_chat_typing:
{
peer_id_t id = MK_ENCR_CHAT (fetch_int ());
peer_t *P = peer_get (id);
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ());
tgl_peer_t *P = tgl_peer_get (id);
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
if (P) {
printf (" User ");
peer_id_t user_id = MK_USER (P->encr_chat.user_id);
print_user_name (user_id, peer_get (user_id));
tgl_peer_id_t user_id = TGL_MK_USER (P->encr_chat.user_id);
print_user_name (user_id, tgl_peer_get (user_id));
printf (" typing in secret chat ");
print_encr_chat_name (id, P);
printf ("\n");
@ -1309,14 +1310,14 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_encrypted_messages_read:
{
peer_id_t id = MK_ENCR_CHAT (fetch_int ()); // chat_id
tgl_peer_id_t id = TGL_MK_ENCR_CHAT (fetch_int ()); // chat_id
fetch_int (); // max_date
fetch_int (); // date
peer_t *P = peer_get (id);
tgl_peer_t *P = tgl_peer_get (id);
int x = -1;
if (P && P->last) {
x = 0;
struct message *M = P->last;
struct tgl_message *M = P->last;
while (M && (!M->out || M->unread)) {
if (M->out) {
M->unread = 0;
@ -1330,7 +1331,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" Encrypted chat ");
print_encr_chat_name_full (id, peer_get (id));
print_encr_chat_name_full (id, tgl_peer_get (id));
printf (": %d messages marked read \n", x);
pop_color ();
print_end ();
@ -1339,25 +1340,25 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_chat_participant_add:
{
peer_id_t chat_id = MK_CHAT (fetch_int ());
peer_id_t user_id = MK_USER (fetch_int ());
peer_id_t inviter_id = MK_USER (fetch_int ());
tgl_peer_id_t chat_id = TGL_MK_CHAT (fetch_int ());
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
tgl_peer_id_t inviter_id = TGL_MK_USER (fetch_int ());
int version = fetch_int ();
peer_t *C = peer_get (chat_id);
tgl_peer_t *C = tgl_peer_get (chat_id);
if (C && (C->flags & FLAG_CREATED)) {
bl_do_chat_add_user (&C->chat, version, get_peer_id (user_id), get_peer_id (inviter_id), time (0));
bl_do_chat_add_user (&C->chat, version, tgl_get_peer_id (user_id), tgl_get_peer_id (inviter_id), time (0));
}
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" Chat ");
print_chat_name (chat_id, peer_get (chat_id));
print_chat_name (chat_id, tgl_peer_get (chat_id));
printf (": user ");
print_user_name (user_id, peer_get (user_id));
print_user_name (user_id, tgl_peer_get (user_id));
printf (" added by user ");
print_user_name (inviter_id, peer_get (inviter_id));
print_user_name (inviter_id, tgl_peer_get (inviter_id));
printf ("\n");
pop_color ();
print_end ();
@ -1365,22 +1366,22 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_chat_participant_delete:
{
peer_id_t chat_id = MK_CHAT (fetch_int ());
peer_id_t user_id = MK_USER (fetch_int ());
tgl_peer_id_t chat_id = TGL_MK_CHAT (fetch_int ());
tgl_peer_id_t user_id = TGL_MK_USER (fetch_int ());
int version = fetch_int ();
peer_t *C = peer_get (chat_id);
tgl_peer_t *C = tgl_peer_get (chat_id);
if (C && (C->flags & FLAG_CREATED)) {
bl_do_chat_del_user (&C->chat, version, get_peer_id (user_id));
bl_do_chat_del_user (&C->chat, version, tgl_get_peer_id (user_id));
}
print_start ();
push_color (COLOR_YELLOW);
print_date (time (0));
printf (" Chat ");
print_chat_name (chat_id, peer_get (chat_id));
print_chat_name (chat_id, tgl_peer_get (chat_id));
printf (": user ");
print_user_name (user_id, peer_get (user_id));
print_user_name (user_id, tgl_peer_get (user_id));
printf (" deleted\n");
pop_color ();
print_end ();
@ -1401,7 +1402,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
{
int id = fetch_int ();
int blocked = fetch_bool ();
peer_t *P = peer_get (MK_USER (id));
tgl_peer_t *P = tgl_peer_get (TGL_MK_USER (id));
if (P && (P->flags & FLAG_CREATED)) {
bl_do_user_set_blocked (&P->user, blocked);
}
@ -1454,7 +1455,7 @@ void work_updates (struct connection *c, long long msg_id) {
void work_update_short_message (struct connection *c UU, long long msg_id UU) {
assert (fetch_int () == (int)CODE_update_short_message);
struct message *M = tglf_fetch_alloc_message_short ();
struct tgl_message *M = tglf_fetch_alloc_message_short ();
unread_messages ++;
print_message (M);
update_prompt ();
@ -1465,7 +1466,7 @@ void work_update_short_message (struct connection *c UU, long long msg_id UU) {
void work_update_short_chat_message (struct connection *c UU, long long msg_id UU) {
assert (fetch_int () == CODE_update_short_chat_message);
struct message *M = tglf_fetch_alloc_message_short_chat ();
struct tgl_message *M = tglf_fetch_alloc_message_short_chat ();
unread_messages ++;
print_message (M);
update_prompt ();
@ -1601,7 +1602,7 @@ void work_new_detailed_info (struct connection *c UU, long long msg_id UU) {
void work_updates_to_long (struct connection *c UU, long long msg_id UU) {
assert (fetch_int () == (int)CODE_updates_too_long);
logprintf ("updates to long... Getting difference\n");
do_get_difference ();
tgl_do_get_difference ();
}
void work_bad_msg_notification (struct connection *c UU, long long msg_id UU) {

388
queries.c

File diff suppressed because it is too large Load Diff

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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);
char *create_print_name (tgl_peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
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 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 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));
}
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

View File

@ -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"

View File

@ -1,25 +1,34 @@
#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

View File

@ -20,41 +20,41 @@
#pragma pack(push,4)
typedef struct { int type; int id; } peer_id_t;
typedef struct { int type; int id; } tgl_peer_id_t;
struct file_location {
struct tgl_file_location {
int dc;
long long volume;
int local_id;
long long secret;
};
struct photo_size {
struct tgl_photo_size {
char *type;
struct file_location loc;
struct tgl_file_location loc;
int w;
int h;
int size;
char *data;
};
struct geo {
struct tgl_geo {
double longitude;
double latitude;
};
struct photo {
struct tgl_photo {
long long id;
long long access_hash;
int user_id;
int date;
char *caption;
struct geo geo;
struct tgl_geo geo;
int sizes_num;
struct photo_size *sizes;
struct tgl_photo_size *sizes;
};
struct encr_photo {
struct tgl_encr_photo {
long long id;
long long access_hash;
int dc_id;
@ -67,7 +67,7 @@ struct encr_photo {
int h;
};
struct encr_video {
struct tgl_encr_video {
long long id;
long long access_hash;
int dc_id;
@ -82,7 +82,7 @@ struct encr_video {
char *mime_type;
};
struct encr_audio {
struct tgl_encr_audio {
long long id;
long long access_hash;
int dc_id;
@ -95,7 +95,7 @@ struct encr_audio {
char *mime_type;
};
struct encr_document {
struct tgl_encr_document {
long long id;
long long access_hash;
int dc_id;
@ -108,64 +108,64 @@ struct encr_document {
char *mime_type;
};
struct encr_file {
struct tgl_encr_file {
char *filename;
unsigned char *key;
unsigned char *iv;
};
struct user_status {
struct tgl_user_status {
int online;
int when;
};
struct user {
peer_id_t id;
struct tgl_user {
tgl_peer_id_t id;
int flags;
struct message *last;
struct tgl_message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct tgl_file_location photo_big;
struct tgl_file_location photo_small;
long long photo_id;
struct photo photo;
struct tgl_photo photo;
char *first_name;
char *last_name;
char *phone;
long long access_hash;
struct user_status status;
struct tgl_user_status status;
int blocked;
char *real_first_name;
char *real_last_name;
};
struct chat_user {
struct tgl_chat_user {
int user_id;
int inviter_id;
int date;
};
struct chat {
peer_id_t id;
struct tgl_chat {
tgl_peer_id_t id;
int flags;
struct message *last;
struct tgl_message *last;
char *print_title;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
struct tgl_file_location photo_big;
struct tgl_file_location photo_small;
struct tgl_photo photo;
char *title;
int users_num;
int user_list_size;
int user_list_version;
struct chat_user *user_list;
struct tgl_chat_user *user_list;
int date;
int version;
int admin_id;
};
enum secret_chat_state {
enum tgl_secret_chat_state {
sc_none,
sc_waiting,
sc_request,
@ -173,15 +173,15 @@ enum secret_chat_state {
sc_deleted
};
struct secret_chat {
peer_id_t id;
struct tgl_secret_chat {
tgl_peer_id_t id;
int flags;
struct message *last;
struct tgl_message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
struct tgl_file_location photo_big;
struct tgl_file_location photo_small;
struct tgl_photo photo;
int user_id;
int admin_id;
int date;
@ -191,35 +191,35 @@ struct secret_chat {
unsigned char *g_key;
unsigned char *nonce;
enum secret_chat_state state;
enum tgl_secret_chat_state state;
int key[64];
long long key_fingerprint;
};
typedef union peer {
typedef union tgl_peer {
struct {
peer_id_t id;
tgl_peer_id_t id;
int flags;
struct message *last;
struct tgl_message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
struct tgl_file_location photo_big;
struct tgl_file_location photo_small;
struct tgl_photo photo;
};
struct user user;
struct chat chat;
struct secret_chat encr_chat;
} peer_t;
struct tgl_user user;
struct tgl_chat chat;
struct tgl_secret_chat encr_chat;
} tgl_peer_t;
struct video {
struct tgl_video {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
struct photo_size thumb;
struct tgl_photo_size thumb;
char *caption;
int duration;
int w;
@ -227,7 +227,7 @@ struct video {
char *mime_type;
};
struct audio {
struct tgl_audio {
long long id;
long long access_hash;
int user_id;
@ -238,19 +238,19 @@ struct audio {
char *mime_type;
};
struct document {
struct tgl_document {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
struct photo_size thumb;
struct tgl_photo_size thumb;
char *caption;
char *mime_type;
};
struct message_action {
struct tgl_message_action {
unsigned type;
union {
struct {
@ -259,7 +259,7 @@ struct message_action {
int *users;
};
char *new_title;
struct photo photo;
struct tgl_photo photo;
int user;
int ttl;
int layer;
@ -269,25 +269,25 @@ struct message_action {
};
};
struct message_media {
struct tgl_message_media {
unsigned type;
union {
struct photo photo;
struct video video;
struct audio audio;
struct document document;
struct geo geo;
struct tgl_photo photo;
struct tgl_video video;
struct tgl_audio audio;
struct tgl_document document;
struct tgl_geo geo;
struct {
char *phone;
char *first_name;
char *last_name;
int user_id;
};
struct encr_photo encr_photo;
struct encr_video encr_video;
struct encr_audio encr_audio;
struct encr_document encr_document;
struct encr_file encr_file;
struct tgl_encr_photo encr_photo;
struct tgl_encr_video encr_video;
struct tgl_encr_audio encr_audio;
struct tgl_encr_document encr_document;
struct tgl_encr_file encr_file;
struct {
void *data;
int data_size;
@ -295,25 +295,25 @@ struct message_media {
};
};
struct message {
struct message *next_use, *prev_use;
struct message *next, *prev;
struct tgl_message {
struct tgl_message *next_use, *prev_use;
struct tgl_message *next, *prev;
long long id;
int flags;
peer_id_t fwd_from_id;
tgl_peer_id_t fwd_from_id;
int fwd_date;
peer_id_t from_id;
peer_id_t to_id;
tgl_peer_id_t from_id;
tgl_peer_id_t to_id;
int out;
int unread;
int date;
int service;
union {
struct message_action action;
struct tgl_message_action action;
struct {
char *message;
int message_len;
struct message_media media;
struct tgl_message_media media;
};
};
};

1
tgl.c
View File

@ -3,6 +3,5 @@
#endif
#include "tgl.h"
struct tgl_params tgl_params;
struct tgl_state tgl_state;

135
tgl.h
View File

@ -1,17 +1,140 @@
#ifndef __TGL_H__
#define __TGL_H__
#include <tgl-layout.h>
#include <string.h>
#define TGL_MAX_DC_NUM 100
// Do not modify this structure, unless you know what you do
struct tgl_state {
int our_id; // ID of logged in user
int encr_root;
unsigned char *encr_prime;
int encr_param_version;
int pts;
int qts;
int date;
int seq;
int binlog_enabled;
int test_mode;
int verbosity;
int unread_messages;
struct dc *DC_list[TGL_MAX_DC_NUM];
struct dc *DC_working;
int dc_working_num;
long long cur_uploading_bytes;
long long cur_uploaded_bytes;
long long cur_downloading_bytes;
long long cur_downloaded_bytes;
};
extern struct tgl_state tgl_state;
// Should be set before first use of lib
struct tgl_params {
int test_mode; // Connect to test DC
int verbosity; // May be modified any moment
};
extern struct tgl_params tgl_params;
void tgl_reopen_binlog_for_writing (void);
void tgl_replay_log (void);
int tgl_print_stat (char *s, int len);
tgl_peer_t *tgl_peer_get (tgl_peer_id_t id);
tgl_peer_t *tgl_peer_get_by_name (const char *s);
struct tgl_message *tgl_message_get (long long id);
void tgl_peer_iterator_ex (void (*it)(tgl_peer_t *P, void *extra), void *extra);
int tgl_complete_user_list (int index, const char *text, int len, char **R);
int tgl_complete_chat_list (int index, const char *text, int len, char **R);
int tgl_complete_encr_chat_list (int index, const char *text, int len, char **R);
int tgl_complete_peer_list (int index, const char *text, int len, char **R);
#define TGL_PEER_USER 1
#define TGL_PEER_CHAT 2
#define TGL_PEER_GEO_CHAT 3
#define TGL_PEER_ENCR_CHAT 4
#define TGL_PEER_UNKNOWN 0
#define TGL_MK_USER(id) tgl_set_peer_id (TGL_PEER_USER,id)
#define TGL_MK_CHAT(id) tgl_set_peer_id (TGL_PEER_CHAT,id)
#define TGL_MK_GEO_CHAT(id) tgl_set_peer_id (TGL_PEER_GEO_CHAT,id)
#define TGL_MK_ENCR_CHAT(id) tgl_set_peer_id (TGL_PEER_ENCR_CHAT,id)
static inline int tgl_get_peer_type (tgl_peer_id_t id) {
return id.type;
}
static inline int tgl_get_peer_id (tgl_peer_id_t id) {
return id.id;
}
static inline tgl_peer_id_t tgl_set_peer_id (int type, int id) {
tgl_peer_id_t ID;
ID.id = id;
ID.type = type;
return ID;
}
static inline int tgl_cmp_peer_id (tgl_peer_id_t a, tgl_peer_id_t b) {
return memcmp (&a, &b, sizeof (a));
}
static inline void tgl_incr_verbosity (void) {
tgl_state.verbosity ++;
}
static inline void tgl_set_verbosity (int val) {
tgl_state.verbosity = val;
}
static inline void tgl_set_test_mode (void) {
tgl_state.test_mode ++;
}
void tgl_do_send_code (const char *user);
void tgl_do_phone_call (const char *user);
int tgl_do_send_code_result (const char *code);
void tgl_do_update_contact_list (void);
void tgl_do_send_message (tgl_peer_id_t id, const char *msg, int len);
void tgl_do_send_text (tgl_peer_id_t id, char *file);
void tgl_do_get_history (tgl_peer_id_t id, int limit);
void tgl_do_get_dialog_list (void);
void tgl_do_get_dialog_list_ex (void);
void tgl_do_send_photo (int type, tgl_peer_id_t to_id, char *file_name);
void tgl_do_get_chat_info (tgl_peer_id_t id);
void tgl_do_get_user_list_info_silent (int num, int *list);
void tgl_do_get_user_info (tgl_peer_id_t id);
void tgl_do_forward_message (tgl_peer_id_t id, int n);
void tgl_do_rename_chat (tgl_peer_id_t id, char *name);
void tgl_do_load_encr_video (struct tgl_encr_video *V, int next);
void tgl_do_create_encr_chat_request (int user_id);
void tgl_do_create_secret_chat (tgl_peer_id_t id);
void tgl_do_create_group_chat (tgl_peer_id_t id, char *chat_topic);
void tgl_do_get_suggested (void);
void tgl_do_load_photo (struct tgl_photo *photo, int next);
void tgl_do_load_video_thumb (struct tgl_video *video, int next);
void tgl_do_load_audio (struct tgl_video *V, int next);
void tgl_do_load_video (struct tgl_video *V, int next);
void tgl_do_load_document (struct tgl_document *V, int next);
void tgl_do_load_document_thumb (struct tgl_document *video, int next);
void tgl_do_help_get_config (void);
int tgl_do_auth_check_phone (const char *user);
int tgl_do_get_nearest_dc (void);
int tgl_do_send_code_result_auth (const char *code, const char *first_name, const char *last_name);
void tgl_do_import_auth (int num);
void tgl_do_export_auth (int num);
void tgl_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 tgl_do_msg_search (tgl_peer_id_t id, int from, int to, int limit, const char *s);
void tgl_do_accept_encr_chat_request (struct tgl_secret_chat *E);
void tgl_do_get_difference (void);
void tgl_do_mark_read (tgl_peer_id_t id);
void tgl_do_visualize_key (tgl_peer_id_t id);
void tgl_do_create_keys_end (struct tgl_secret_chat *U);
void tgl_do_add_user_to_chat (tgl_peer_id_t chat_id, tgl_peer_id_t id, int limit);
void tgl_do_del_user_from_chat (tgl_peer_id_t chat_id, tgl_peer_id_t id);
void tgl_do_update_status (int online);
void tgl_do_contacts_search (int limit, const char *s);
void tgl_do_send_msg (struct tgl_message *M);
void tgl_do_delete_msg (long long id);
void tgl_do_restore_msg (long long id);
void tgl_do_send_encr_chat_layer (struct tgl_secret_chat *E);
#endif