Commit 418cad58 authored by Vysheng's avatar Vysheng

Some refactoring

parent 9959c058
......@@ -18,7 +18,7 @@ DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${DEP}/auto ${OBJ}/auto
EXE_LIST=${EXE}/generate ${EXE}/tlc ${EXE}/telegram-cli
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/net.o ${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/lua-tg.o ${OBJ}/auto/auto.o
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/net.o ${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/lua-tg.o ${OBJ}/auto/auto.o ${OBJ}/tgl.o
TLC_OBJECTS=${OBJ}/tlc.o ${OBJ}/tl-parser.o ${OBJ}/crc32.o
GENERATE_OBJECTS=${OBJ}/generate.o
COMMON_OBJECTS=${OBJ}/tools.o
......
This diff is collapsed.
......@@ -46,6 +46,8 @@
#include "mtproto-common.h"
#include "tgl.h"
#define ALLOW_MULT 1
char *default_prompt = "> ";
......@@ -144,12 +146,12 @@ peer_id_t next_token_user (void) {
else { return PEER_NOT_FOUND; }
}
int index = 0;
while (index < peer_num && (!is_same_word (s, l, Peers[index]->print_name) || get_peer_type (Peers[index]->id) != PEER_USER)) {
index ++;
}
if (index < peer_num) {
return Peers[index]->id;
char c = s[l];
peer_t *P = peer_lookup_name (s);
s[l] = c;
if (P && get_peer_type (P->id) == PEER_USER) {
return P->id;
} else {
return PEER_NOT_FOUND;
}
......@@ -168,12 +170,12 @@ peer_id_t next_token_chat (void) {
else { return PEER_NOT_FOUND; }
}
int index = 0;
while (index < peer_num && (!is_same_word (s, l, Peers[index]->print_name) || get_peer_type (Peers[index]->id) != PEER_CHAT)) {
index ++;
}
if (index < peer_num) {
return Peers[index]->id;
char c = s[l];
peer_t *P = peer_lookup_name (s);
s[l] = c;
if (P && get_peer_type (P->id) == PEER_CHAT) {
return P->id;
} else {
return PEER_NOT_FOUND;
}
......@@ -184,12 +186,12 @@ peer_id_t next_token_encr_chat (void) {
char *s = next_token (&l);
if (!s) { return PEER_NOT_FOUND; }
int index = 0;
while (index < peer_num && (!is_same_word (s, l, Peers[index]->print_name) || get_peer_type (Peers[index]->id) != PEER_ENCR_CHAT)) {
index ++;
}
if (index < peer_num) {
return Peers[index]->id;
char c = s[l];
peer_t *P = peer_lookup_name (s);
s[l] = c;
if (P && get_peer_type (P->id) == PEER_ENCR_CHAT) {
return P->id;
} else {
return PEER_NOT_FOUND;
}
......@@ -214,13 +216,13 @@ peer_id_t next_token_peer (void) {
if (r >= 0) { return set_peer_id (PEER_CHAT, r); }
else { return PEER_NOT_FOUND; }
}
int index = 0;
while (index < peer_num && (!is_same_word (s, l, Peers[index]->print_name))) {
index ++;
}
if (index < peer_num) {
return Peers[index]->id;
char c = s[l];
peer_t *P = peer_lookup_name (s);
s[l] = c;
if (P) {
return P->id;
} else {
return PEER_NOT_FOUND;
}
......@@ -431,58 +433,6 @@ int get_complete_mode (void) {
}
}
int complete_user_list (int index, const char *text, int len, char **R) {
index ++;
while (index < peer_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len) || get_peer_type (Peers[index]->id) != PEER_USER)) {
index ++;
}
if (index < peer_num) {
*R = strdup (Peers[index]->print_name);
return index;
} else {
return -1;
}
}
int complete_chat_list (int index, const char *text, int len, char **R) {
index ++;
while (index < peer_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len) || get_peer_type (Peers[index]->id) != PEER_CHAT)) {
index ++;
}
if (index < peer_num) {
*R = strdup (Peers[index]->print_name);
return index;
} else {
return -1;
}
}
int complete_encr_chat_list (int index, const char *text, int len, char **R) {
index ++;
while (index < peer_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len) || get_peer_type (Peers[index]->id) != PEER_ENCR_CHAT)) {
index ++;
}
if (index < peer_num) {
*R = strdup (Peers[index]->print_name);
return index;
} else {
return -1;
}
}
int complete_user_chat_list (int index, const char *text, int len, char **R) {
index ++;
while (index < peer_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) {
index ++;
}
if (index < peer_num) {
*R = strdup (Peers[index]->print_name);
return index;
} else {
return -1;
}
}
int complete_string_list (char **list, int index, const char *text, int len, char **R) {
index ++;
while (list[index] && strncmp (list[index], text, len)) {
......@@ -533,7 +483,7 @@ char *command_generator (const char *text, int state) {
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 2:
index = complete_user_chat_list (index, text, len, &R);
index = complete_peer_list (index, text, len, &R);
if (c) { rl_line_buffer[rl_point] = c; }
return R;
case 3:
......@@ -674,7 +624,7 @@ void interpreter (char *line UU) {
do_get_dialog_list ();
} else if (IS_WORD ("stats")) {
static char stat_buf[1 << 15];
print_stat (stat_buf, (1 << 15) - 1);
tgl_print_stat (stat_buf, (1 << 15) - 1);
printf ("%s\n", stat_buf);
} else if (IS_WORD ("msg")) {
GET_PEER;
......@@ -1392,8 +1342,6 @@ 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);
}
int our_id;
void print_service_message (struct message *M) {
assert (M);
print_start ();
......@@ -1578,7 +1526,7 @@ void print_message (struct message *M) {
print_chat_name (M->to_id, 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) == our_id)) {
if ((get_peer_type (M->from_id) == PEER_USER) && (get_peer_id (M->from_id) == tgl_state.our_id)) {
push_color (COLOR_GREEN);
} else {
push_color (COLOR_BLUE);
......
......@@ -33,6 +33,11 @@
#define COLOR_INVERSE "\033[7m"
#define E_ERROR 0
#define E_WARNING 1
#define E_NOTICE 2
#define E_DEBUG 3
char *get_default_prompt (void);
char *complete_none (const char *text, int state);
char **complete_text (char *text, int start, int end);
......@@ -40,6 +45,15 @@ void interpreter (char *line);
void rprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void logprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
#define vlogprintf(v,...) \
do { \
if (tgl_params.verbosity >= (v)) {\
logprintf (__VA_ARGS__);\
}\
} while (0);\
void hexdump (int *in_ptr, int *in_end);
struct message;
......
......@@ -52,6 +52,9 @@
#include "loop.h"
#include "binlog.h"
#include "lua-tg.h"
#include "structures.h"
#include "tgl.h"
#include "auto.h"
......@@ -177,7 +180,6 @@ void write_dc (int auth_file_fd, struct dc *DC) {
assert (write (auth_file_fd, &DC->has_auth, 4) == 4);
}
int our_id;
void write_auth_file (void) {
if (binlog_enabled) { return; }
int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600);
......@@ -199,7 +201,7 @@ void write_auth_file (void) {
assert (write (auth_file_fd, &x, 4) == 4);
}
}
assert (write (auth_file_fd, &our_id, 4) == 4);
assert (write (auth_file_fd, &tgl_state.our_id, 4) == 4);
close (auth_file_fd);
}
......@@ -227,7 +229,7 @@ void read_dc (int auth_file_fd, int id, unsigned ver) {
}
void empty_auth_file (void) {
alloc_dc (1, tstrdup (test_dc ? TG_SERVER_TEST : TG_SERVER), 443);
alloc_dc (1, tstrdup (tgl_params.test_mode ? TG_SERVER_TEST : TG_SERVER), 443);
dc_working_num = 1;
auth_state = 0;
write_auth_file ();
......@@ -263,7 +265,7 @@ void read_auth_file (void) {
read_dc (auth_file_fd, i, m);
}
}
int l = read (auth_file_fd, &our_id, 4);
int l = read (auth_file_fd, &tgl_state.our_id, 4);
if (l < 4) {
assert (!l);
}
......@@ -387,6 +389,40 @@ 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) {
(*(int *)cc) ++;
}
}
void write_encr_peer (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);
assert (write (fd, &t, 4) == 4);
t = P->flags;
assert (write (fd, &t, 4) == 4);
t = strlen (P->print_name);
assert (write (fd, &t, 4) == 4);
assert (write (fd, P->print_name, t) == t);
assert (write (fd, &P->encr_chat.state, 4) == 4);
assert (write (fd, &P->encr_chat.user_id, 4) == 4);
assert (write (fd, &P->encr_chat.admin_id, 4) == 4);
assert (write (fd, &P->encr_chat.ttl, 4) == 4);
assert (write (fd, &P->encr_chat.access_hash, 8) == 8);
if (P->encr_chat.state != sc_waiting) {
assert (write (fd, P->encr_chat.g_key, 256) == 256);
}
if (P->encr_chat.state != sc_waiting) {
assert (write (fd, P->encr_chat.nonce, 256) == 256);
}
assert (write (fd, P->encr_chat.key, 256) == 256);
assert (write (fd, &P->encr_chat.key_fingerprint, 8) == 8);
}
}
void write_secret_chat_file (void) {
if (binlog_enabled) { return; }
int fd = open (get_secret_chat_filename (), O_CREAT | O_RDWR, 0600);
......@@ -397,40 +433,11 @@ void write_secret_chat_file (void) {
x[0] = SECRET_CHAT_FILE_MAGIC;
x[1] = 1;
assert (write (fd, x, 8) == 8);
int i;
int cc = 0;
for (i = 0; i < peer_num; i++) if (get_peer_type (Peers[i]->id) == PEER_ENCR_CHAT) {
if (Peers[i]->encr_chat.state != sc_none && Peers[i]->encr_chat.state != sc_deleted) {
cc ++;
}
}
assert (write (fd, &cc, 4) == 4);
for (i = 0; i < peer_num; i++) if (get_peer_type (Peers[i]->id) == PEER_ENCR_CHAT) {
if (Peers[i]->encr_chat.state != sc_none && Peers[i]->encr_chat.state != sc_deleted) {
int t = get_peer_id (Peers[i]->id);
assert (write (fd, &t, 4) == 4);
t = Peers[i]->flags;
assert (write (fd, &t, 4) == 4);
t = strlen (Peers[i]->print_name);
assert (write (fd, &t, 4) == 4);
assert (write (fd, Peers[i]->print_name, t) == t);
assert (write (fd, &Peers[i]->encr_chat.state, 4) == 4);
assert (write (fd, &Peers[i]->encr_chat.user_id, 4) == 4);
assert (write (fd, &Peers[i]->encr_chat.admin_id, 4) == 4);
assert (write (fd, &Peers[i]->encr_chat.ttl, 4) == 4);
assert (write (fd, &Peers[i]->encr_chat.access_hash, 8) == 8);
if (Peers[i]->encr_chat.state != sc_waiting) {
assert (write (fd, Peers[i]->encr_chat.g_key, 256) == 256);
}
if (Peers[i]->encr_chat.state != sc_waiting) {
assert (write (fd, Peers[i]->encr_chat.nonce, 256) == 256);
}
assert (write (fd, Peers[i]->encr_chat.key, 256) == 256);
assert (write (fd, &Peers[i]->encr_chat.key_fingerprint, 8) == 8);
}
}
peer_iterator_ex (count_encr_peer, &cc);
peer_iterator_ex (write_encr_peer, &fd);
assert (write (fd, &encr_root, 4) == 4);
if (encr_root) {
assert (write (fd, &encr_param_version, 4) == 4);
......
......@@ -343,11 +343,7 @@ void *lua_ptr[MAX_LUA_COMMANDS];
static int pos;
static peer_t *get_peer (const char *s) {
int index = 0;
while (index < peer_num && (!Peers[index]->print_name || strcmp (Peers[index]->print_name, s))) {
index ++;
}
return index == peer_num ? 0 : Peers[index];
return peer_lookup_name (s);
}
void lua_do_all (void) {
......
......@@ -57,6 +57,8 @@
# include "lua-tg.h"
#endif
#include "tgl.h"
#define PROGNAME "telegram-client"
#define VERSION "0.01"
......@@ -79,7 +81,6 @@ char *auth_token;
int msg_num_mode;
char *config_filename;
char *prefix;
int test_dc;
char *auth_file_name;
char *state_file_name;
char *secret_chat_file_name;
......@@ -296,9 +297,10 @@ void parse_config (void) {
memcpy (buf, prefix, l);
buf[l ++] = '.';
}
test_dc = 0;
tgl_params.test_mode = 0;
strcpy (buf + l, "test");
config_lookup_bool (&conf, buf, &test_dc);
config_lookup_bool (&conf, buf, &tgl_params.test_mode);
strcpy (buf + l, "log_level");
long long t = log_level;
......@@ -369,7 +371,6 @@ void usage (void) {
}
extern char *rsa_public_key_name;
extern int verbosity;
extern int default_dc_num;
char *log_net_file;
......@@ -392,7 +393,7 @@ void args_parse (int argc, char **argv) {
rsa_public_key_name = tstrdup (optarg);
break;
case 'v':
verbosity ++;
tgl_params.verbosity ++;
break;
case 'N':
msg_num_mode ++;
......
......@@ -779,7 +779,6 @@ int auth_work_start (struct connection *c UU) {
void rpc_execute_answer (struct connection *c, long long msg_id UU);
int unread_messages;
int our_id;
int pts;
int qts;
int last_date;
......@@ -881,8 +880,8 @@ void work_update_binlog (void) {
} else {
assert (y == CODE_user_profile_photo);
U->photo_id = fetch_long ();
fetch_file_location (&U->photo_small);
fetch_file_location (&U->photo_big);
tglf_fetch_file_location (&U->photo_small);
tglf_fetch_file_location (&U->photo_big);
}
} else {
struct file_location t;
......@@ -891,8 +890,8 @@ void work_update_binlog (void) {
} else {
assert (y == CODE_user_profile_photo);
fetch_long (); // photo_id
fetch_file_location (&t);
fetch_file_location (&t);
tglf_fetch_file_location (&t);
tglf_fetch_file_location (&t);
}
}
fetch_bool ();
......@@ -908,7 +907,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
switch (op) {
case CODE_update_new_message:
{
struct message *M = fetch_alloc_message ();
struct message *M = tglf_fetch_alloc_message ();
assert (M);
fetch_pts ();
unread_messages ++;
......@@ -990,7 +989,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
peer_id_t user_id = MK_USER (fetch_int ());
peer_t *U = peer_get (user_id);
if (U) {
fetch_user_status (&U->user.status);
tglf_fetch_user_status (&U->user.status);
if (log_level >= 3) {
print_start ();
push_color (COLOR_YELLOW);
......@@ -1004,7 +1003,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
}
} else {
struct user_status t;
fetch_user_status (&t);
tglf_fetch_user_status (&t);
}
}
break;
......@@ -1055,8 +1054,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
} else {
assert (y == CODE_user_profile_photo);
photo_id = fetch_long ();
fetch_file_location (&small);
fetch_file_location (&big);
tglf_fetch_file_location (&small);
tglf_fetch_file_location (&big);
}
bl_do_set_user_profile_photo (U, photo_id, &big, &small);
......@@ -1075,8 +1074,8 @@ void work_update (struct connection *c UU, long long msg_id UU) {
} else {
assert (y == CODE_user_profile_photo);
fetch_long (); // photo_id
fetch_file_location (&t);
fetch_file_location (&t);
tglf_fetch_file_location (&t);
tglf_fetch_file_location (&t);
}
}
fetch_bool ();
......@@ -1228,7 +1227,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_new_geo_chat_message:
{
struct message *M = fetch_alloc_geo_message ();
struct message *M = tglf_fetch_alloc_geo_message ();
unread_messages ++;
print_message (M);
update_prompt ();
......@@ -1236,7 +1235,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_new_encrypted_message:
{
struct message *M = fetch_alloc_encrypted_message ();
struct message *M = tglf_fetch_alloc_encrypted_message ();
unread_messages ++;
print_message (M);
update_prompt ();
......@@ -1245,7 +1244,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
break;
case CODE_update_encryption:
{
struct secret_chat *E = fetch_alloc_encrypted_chat ();
struct secret_chat *E = tglf_fetch_alloc_encrypted_chat ();
if (verbosity >= 2) {
logprintf ("Secret chat state = %d\n", E->state);
}
......@@ -1441,12 +1440,12 @@ void work_updates (struct connection *c, long long msg_id) {
assert (fetch_int () == CODE_vector);
n = fetch_int ();
for (i = 0; i < n; i++) {
fetch_alloc_user ();
tglf_fetch_alloc_user ();
}
assert (fetch_int () == CODE_vector);
n = fetch_int ();
for (i = 0; i < n; i++) {
fetch_alloc_chat ();
tglf_fetch_alloc_chat ();
}
bl_do_set_date (fetch_int ());
bl_do_set_seq (fetch_int ());
......@@ -1455,7 +1454,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 = fetch_alloc_message_short ();
struct message *M = tglf_fetch_alloc_message_short ();
unread_messages ++;
print_message (M);
update_prompt ();
......@@ -1466,7 +1465,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 = fetch_alloc_message_short_chat ();
struct message *M = tglf_fetch_alloc_message_short_chat ();
unread_messages ++;
print_message (M);
update_prompt ();
......
This diff is collapsed.
This diff is collapsed.
......@@ -20,364 +20,31 @@
#define __STRUCTURES_H__
#include <assert.h>
typedef struct { int type; int id; } peer_id_t;
#include "tgl-layout.h"
#include "tgl-fetch.h"
//#define FLAG_EMPTY 1
#define FLAG_MESSAGE_EMPTY 1
#define FLAG_DELETED 2
#define FLAG_FORBIDDEN 4
#define FLAG_HAS_PHOTO 8
#define FLAG_CREATED 16
#define FLAG_USER_SELF 128
#define FLAG_USER_FOREIGN 256
#define FLAG_USER_CONTACT 512
#define FLAG_USER_IN_CONTACT 1024
#define FLAG_USER_OUT_CONTACT 2048
#define FLAG_CHAT_IN_CHAT 128
#define FLAG_ENCRYPTED 4096
#define FLAG_PENDING 8192
#pragma pack(push,4)
struct file_location {
int dc;
long long volume;
int local_id;
long long secret;
};
#pragma pack(pop)
struct photo_size {
char *type;
struct file_location loc;
int w;
int h;
int size;
char *data;
};
struct geo {
double longitude;
double latitude;
};
struct photo {
long long id;
long long access_hash;
int user_id;
int date;
char *caption;
struct geo geo;
int sizes_num;
struct photo_size *sizes;
};
struct encr_photo {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
int w;
int h;
};
struct encr_video {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
int w;
int h;
int duration;
char *mime_type;
};
struct encr_audio {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
int duration;
char *mime_type;
};
struct encr_document {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
char *file_name;
char *mime_type;
};
struct encr_file {
char *filename;
unsigned char *key;
unsigned char *iv;
};
struct user_status {
int online;
int when;
};
struct user {
peer_id_t id;
int flags;
struct message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
long long photo_id;
struct photo photo;
char *first_name;
char *last_name;
char *phone;
long long access_hash;
struct user_status status;
int blocked;
char *real_first_name;
char *real_last_name;
};
struct chat_user {
int user_id;
int inviter_id;
int date;
};
struct chat {
peer_id_t id;
int flags;
struct message *last;
char *print_title;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
char *title;
int users_num;
int user_list_size;
int user_list_version;
struct chat_user *user_list;
int date;
int version;
int admin_id;
};
enum secret_chat_state {
sc_none,
sc_waiting,
sc_request,
sc_ok,
sc_deleted
};
struct secret_chat {
peer_id_t id;
int flags;
struct message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
int user_id;
int admin_id;
int date;
int ttl;
int layer;
long long access_hash;
unsigned char *g_key;
unsigned char *nonce;
enum secret_chat_state state;
int key[64];
long long key_fingerprint;
};
typedef union peer {
struct {
peer_id_t id;
int flags;
struct message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
};
struct user user;
struct chat chat;
struct secret_chat encr_chat;
} peer_t;
struct video {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
struct photo_size thumb;
char *caption;
int duration;
int w;
int h;
char *mime_type;
};
struct audio {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
int duration;
char *mime_type;
};
struct document {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
struct photo_size thumb;
char *caption;
char *mime_type;
};
struct message_action {
unsigned type;
union {
struct {
char *title;
int user_num;
int *users;
};
char *new_title;
struct photo photo;
int user;
int ttl;
int layer;
int read_cnt;
int delete_cnt;
int screenshot_cnt;
};
};
struct message_media {
unsigned type;
union {
struct photo photo;
struct video video;
struct audio audio;
struct document document;
struct 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 {
void *data;
int data_size;
};
};
};
struct message {
struct message *next_use, *prev_use;
struct message *next, *prev;
long long id;
int flags;
peer_id_t fwd_from_id;
int fwd_date;
peer_id_t from_id;
peer_id_t to_id;
int out;
int unread;
int date;
int service;
union {
struct message_action action;
struct {
char *message;
int message_len;
struct message_media media;
};
};
};
char *create_print_name (peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
int fetch_file_location (struct file_location *loc);
int fetch_user_status (struct user_status *S);
int fetch_user (struct user *U);
struct user *fetch_alloc_user (void);
struct user *fetch_alloc_user_full (void);
struct chat *fetch_alloc_chat (void);
struct chat *fetch_alloc_chat_full (void);
struct secret_chat *fetch_alloc_encrypted_chat (void);
struct message *fetch_alloc_message (void);
struct message *fetch_alloc_geo_message (void);
struct message *fetch_alloc_message_short (void);
struct message *fetch_alloc_message_short_chat (void);
struct message *fetch_alloc_encrypted_message (void);
void fetch_encrypted_message_file (struct message_media *M);
void fetch_skip_encrypted_message_file (void);
void fetch_encrypted_message_file (struct message_media *M);
void fetch_message_action_encrypted (struct secret_chat *E, struct message_action *M);
peer_id_t fetch_peer_id (void);
void fetch_message_media (struct message_media *M);
void fetch_message_media_encrypted (struct message_media *M);
void fetch_message_action (struct message_action *M);
void message_insert_tree (struct message *M);
struct message *message_alloc (long long id);
void free_user (struct user *U);
void free_chat (struct chat *U);
char *create_print_name (peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
int print_stat (char *s, int len);
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 fetch_photo (struct photo *P);
void insert_encrypted_chat (peer_t *P);
void insert_user (peer_t *P);
void insert_chat (peer_t *P);
void fetch_photo (struct photo *P);
void free_photo (struct photo *P);
void message_insert_unsent (struct message *M);
void message_remove_unsent (struct message *M);
void send_all_unsent (void);
......@@ -388,8 +55,12 @@ 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);
peer_t *peer_lookup_name (const char *s);
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
......
#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);
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);
#endif
#ifndef __TGL_LAYOUT_H__
#define __TGL_LAYOUT_H__
#define FLAG_MESSAGE_EMPTY 1
#define FLAG_DELETED 2
#define FLAG_FORBIDDEN 4
#define FLAG_HAS_PHOTO 8
#define FLAG_CREATED 16
#define FLAG_USER_SELF 128
#define FLAG_USER_FOREIGN 256
#define FLAG_USER_CONTACT 512
#define FLAG_USER_IN_CONTACT 1024
#define FLAG_USER_OUT_CONTACT 2048
#define FLAG_CHAT_IN_CHAT 128
#define FLAG_ENCRYPTED 4096
#define FLAG_PENDING 8192
#pragma pack(push,4)
typedef struct { int type; int id; } peer_id_t;
struct file_location {
int dc;
long long volume;
int local_id;
long long secret;
};
struct photo_size {
char *type;
struct file_location loc;
int w;
int h;
int size;
char *data;
};
struct geo {
double longitude;
double latitude;
};
struct photo {
long long id;
long long access_hash;
int user_id;
int date;
char *caption;
struct geo geo;
int sizes_num;
struct photo_size *sizes;
};
struct encr_photo {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
int w;
int h;
};
struct encr_video {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
int w;
int h;
int duration;
char *mime_type;
};
struct encr_audio {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
int duration;
char *mime_type;
};
struct encr_document {
long long id;
long long access_hash;
int dc_id;
int size;
int key_fingerprint;
unsigned char *key;
unsigned char *iv;
char *file_name;
char *mime_type;
};
struct encr_file {
char *filename;
unsigned char *key;
unsigned char *iv;
};
struct user_status {
int online;
int when;
};
struct user {
peer_id_t id;
int flags;
struct message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
long long photo_id;
struct photo photo;
char *first_name;
char *last_name;
char *phone;
long long access_hash;
struct user_status status;
int blocked;
char *real_first_name;
char *real_last_name;
};
struct chat_user {
int user_id;
int inviter_id;
int date;
};
struct chat {
peer_id_t id;
int flags;
struct message *last;
char *print_title;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
char *title;
int users_num;
int user_list_size;
int user_list_version;
struct chat_user *user_list;
int date;
int version;
int admin_id;
};
enum secret_chat_state {
sc_none,
sc_waiting,
sc_request,
sc_ok,
sc_deleted
};
struct secret_chat {
peer_id_t id;
int flags;
struct message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
int user_id;
int admin_id;
int date;
int ttl;
int layer;
long long access_hash;
unsigned char *g_key;
unsigned char *nonce;
enum secret_chat_state state;
int key[64];
long long key_fingerprint;
};
typedef union peer {
struct {
peer_id_t id;
int flags;
struct message *last;
char *print_name;
int structure_version;
struct file_location photo_big;
struct file_location photo_small;
struct photo photo;
};
struct user user;
struct chat chat;
struct secret_chat encr_chat;
} peer_t;
struct video {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
struct photo_size thumb;
char *caption;
int duration;
int w;
int h;
char *mime_type;
};
struct audio {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
int duration;
char *mime_type;
};
struct document {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
struct photo_size thumb;
char *caption;
char *mime_type;
};
struct message_action {
unsigned type;
union {
struct {
char *title;
int user_num;
int *users;
};
char *new_title;
struct photo photo;
int user;
int ttl;
int layer;
int read_cnt;
int delete_cnt;
int screenshot_cnt;
};
};
struct message_media {
unsigned type;
union {
struct photo photo;
struct video video;
struct audio audio;
struct document document;
struct 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 {
void *data;
int data_size;
};
};
};
struct message {
struct message *next_use, *prev_use;
struct message *next, *prev;
long long id;
int flags;
peer_id_t fwd_from_id;
int fwd_date;
peer_id_t from_id;
peer_id_t to_id;
int out;
int unread;
int date;
int service;
union {
struct message_action action;
struct {
char *message;
int message_len;
struct message_media media;
};
};
};
#pragma pack(pop)
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "tgl.h"
struct tgl_params tgl_params;
struct tgl_state tgl_state;
#ifndef __TGL_H__
#define __TGL_H__
// Do not modify this structure, unless you know what you do
struct tgl_state {
int our_id; // ID of logged in user
};
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;
#endif
......@@ -134,6 +134,13 @@ void tree_act_ ## X_NAME (struct tree_ ## X_NAME *T, void (*act)(X_TYPE)) {\
tree_act_ ## X_NAME (T->right, act); \
}\
\
void tree_act_ex_ ## X_NAME (struct tree_ ## X_NAME *T, void (*act)(X_TYPE, void *), void *extra) {\
if (!T) { return; } \
tree_act_ex_ ## X_NAME (T->left, act, extra); \
act (T->x, extra); \
tree_act_ex_ ## X_NAME (T->right, act, extra); \
}\
\
int tree_count_ ## X_NAME (struct tree_ ## X_NAME *T) { \
if (!T) { return 0; }\
return 1 + tree_count_ ## X_NAME (T->left) + tree_count_ ## X_NAME (T->right); \
......
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