2 This file is part of tgl-library
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or(at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 Copyright Vitaly Valtman 2014-2015
23 #include "tgl-layout.h"
28 #define TGL_MAX_DC_NUM 100
29 #define TG_SERVER_1 "149.154.175.50"
30 #define TG_SERVER_2 "149.154.167.51"
31 #define TG_SERVER_3 "174.140.142.6"
32 #define TG_SERVER_4 "149.154.167.91"
33 #define TG_SERVER_5 "149.154.171.5"
35 #define TG_SERVER_IPV6_1 "2001:b28:f23d:f001::a"
36 #define TG_SERVER_IPV6_2 "2001:67c:4e8:f002::a"
37 #define TG_SERVER_IPV6_3 "2001:b28:f23d:f003::a"
38 #define TG_SERVER_IPV6_4 "2001:67c:4e8:f004::a"
39 #define TG_SERVER_IPV6_5 "2001:b28:f23f:f005::a"
40 #define TG_SERVER_DEFAULT 2
42 #define TG_SERVER_TEST_1 "173.240.5.253"
43 #define TG_SERVER_TEST_2 "149.154.167.40"
44 #define TG_SERVER_TEST_3 "174.140.142.5"
45 #define TG_SERVER_TEST_IPV6_1 "2001:b28:f23d:f001::e"
46 #define TG_SERVER_TEST_IPV6_2 "2001:67c:4e8:f002::e"
47 #define TG_SERVER_TEST_IPV6_3 "2001:b28:f23d:f003::e"
48 #define TG_SERVER_TEST_DEFAULT 2
51 #define TGL_MAX_DC_NUM 100
52 #define TG_SERVER_1 "149.154.175.50"
53 #define TG_SERVER_2 "149.154.167.51"
54 #define TG_SERVER_3 "149.154.175.100"
55 #define TG_SERVER_4 "149.154.167.91"
56 #define TG_SERVER_5 "149.154.171.5"
57 #define TG_SERVER_IPV6_1 "2001:b28:f23d:f001::a"
58 #define TG_SERVER_IPV6_2 "2001:67c:4e8:f002::a"
59 #define TG_SERVER_IPV6_3 "2001:b28:f23d:f003::a"
60 #define TG_SERVER_IPV6_4 "2001:67c:4e8:f004::a"
61 #define TG_SERVER_IPV6_5 "2001:b28:f23f:f005::a"
62 #define TG_SERVER_DEFAULT 2
64 #define TG_SERVER_TEST_1 "149.154.175.10"
65 #define TG_SERVER_TEST_2 "149.154.167.40"
66 #define TG_SERVER_TEST_3 "149.154.175.117"
67 #define TG_SERVER_TEST_IPV6_1 "2001:b28:f23d:f001::e"
68 #define TG_SERVER_TEST_IPV6_2 "2001:67c:4e8:f002::e"
69 #define TG_SERVER_TEST_IPV6_3 "2001:b28:f23d:f003::e"
70 #define TG_SERVER_TEST_DEFAULT 2
73 #define TGL_BUILD "7832"
74 //#define TGL_VERSION "1.2.0"
75 #define TGL_VERSION "2.0.3"
77 #define TGL_ENCRYPTED_LAYER 17
78 #define TGL_SCHEME_LAYER 22
81 struct mtproto_methods;
85 #define TGL_GROUP_CHAT_CREATED 2065
87 #define TGL_UPDATE_CREATED 1
88 #define TGL_UPDATE_DELETED 2
89 #define TGL_UPDATE_PHONE 4
90 #define TGL_UPDATE_CONTACT 8
91 #define TGL_UPDATE_PHOTO 16
92 #define TGL_UPDATE_BLOCKED 32
93 #define TGL_UPDATE_REAL_NAME 64
94 #define TGL_UPDATE_NAME 128
95 #define TGL_UPDATE_REQUESTED 256
96 #define TGL_UPDATE_WORKING 512
97 #define TGL_UPDATE_FLAGS 1024
98 #define TGL_UPDATE_TITLE 2048
99 #define TGL_UPDATE_ADMIN 4096
100 #define TGL_UPDATE_MEMBERS 8192
101 #define TGL_UPDATE_ACCESS_HASH 16384
102 #define TGL_UPDATE_USERNAME (1 << 15)
104 struct tgl_allocator {
105 void *(*alloc)(size_t size);
106 void *(*realloc)(void *ptr, size_t old_size, size_t size);
107 void(*free)(void *ptr, int size);
109 void(*exists)(void *ptr, int size);
112 extern struct tgl_allocator tgl_allocator_release;
113 extern struct tgl_allocator tgl_allocator_debug;
116 struct tgl_update_callback {
117 void(*new_msg)(struct tgl_state *TLS, struct tgl_message *M);
118 void(*marked_read)(struct tgl_state *TLS, int num, struct tgl_message *list[]);
119 void(*logprintf)(const char *format, ...);// __attribute__((format(printf, 1, 2)));
120 void(*get_string)(struct tgl_state *TLS, const char *prompt, int flags, void(*callback)(struct tgl_state *TLS, char *string, void *arg), void *arg);
121 void(*logged_in)(struct tgl_state *TLS);
122 void(*started)(struct tgl_state *TLS);
123 void(*type_notification)(struct tgl_state *TLS, struct tgl_user *U, enum tgl_typing_status status);
124 void(*type_in_chat_notification)(struct tgl_state *TLS, struct tgl_user *U, struct tgl_chat *C, enum tgl_typing_status status);
125 void(*type_in_secret_chat_notification)(struct tgl_state *TLS, struct tgl_secret_chat *E);
126 void(*status_notification)(struct tgl_state *TLS, struct tgl_user *U);
127 void(*user_registered)(struct tgl_state *TLS, struct tgl_user *U);
128 void(*user_activated)(struct tgl_state *TLS, struct tgl_user *U);
129 void(*new_authorization)(struct tgl_state *TLS, const char *device, const char *location);
130 void(*chat_update)(struct tgl_state *TLS, struct tgl_chat *C, unsigned flags);
131 void(*user_update)(struct tgl_state *TLS, struct tgl_user *C, unsigned flags);
132 void(*secret_chat_update)(struct tgl_state *TLS, struct tgl_secret_chat *C, unsigned flags);
133 void(*msg_receive)(struct tgl_state *TLS, struct tgl_message *M);
134 void(*our_id)(struct tgl_state *TLS, int id);
135 void(*notification)(struct tgl_state *TLS, char *type, char *message);
136 void(*user_status_update)(struct tgl_state *TLS, struct tgl_user *U);
137 char *(*create_print_name)(struct tgl_state *TLS, tgl_peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
140 struct tgl_net_methods {
141 int(*write_out)(struct connection *c, const void *data, int len);
142 int(*read_in)(struct connection *c, void *data, int len);
143 int(*read_in_lookup)(struct connection *c, void *data, int len);
144 void(*flush_out)(struct connection *c);
145 void(*incr_out_packet_num)(struct connection *c);
146 void(*free)(struct connection *c);
147 struct tgl_dc *(*get_dc)(struct connection *c);
148 struct tgl_session *(*get_session)(struct connection *c);
149 struct connection *(*create_connection)(struct tgl_state *TLS, const char *host, int port, struct tgl_session *session, struct tgl_dc *dc, struct mtproto_methods *methods);
152 struct mtproto_methods {
153 int(*ready)(struct tgl_state *TLS, struct connection *c);
154 int(*close)(struct tgl_state *TLS, struct connection *c);
155 int(*execute)(struct tgl_state *TLS, struct connection *c, int op, int len);
160 struct tgl_timer_methods {
161 struct tgl_timer *(*alloc)(struct tgl_state *TLS, void(*cb)(struct tgl_state *TLS, void *arg), void *arg);
162 void(*insert)(struct tgl_timer *t, double timeout);
163 void(*remove)(struct tgl_timer *t);
164 void(*free)(struct tgl_timer *t);
173 #define TGL_LOCK_DIFF 1
174 #define TGL_LOCK_PASSWORD 2
176 #define TGL_MAX_RSA_KEYS_NUM 10
177 // Do not modify this structure, unless you know what you do
180 typedef struct tgl_state {
181 int our_id; // ID of logged in user
183 unsigned char *encr_prime;
185 int encr_param_version;
198 struct tgl_dc *DC_list[TGL_MAX_DC_NUM];
199 struct tgl_dc *DC_working;
203 int temp_key_expire_time;
204 long long cur_uploading_bytes;
205 long long cur_uploaded_bytes;
206 long long cur_downloading_bytes;
207 long long cur_downloaded_bytes;
210 char *downloads_directory;
211 struct tgl_update_callback callback;
213 struct tgl_net_methods *net_methods;
214 char *rsa_key_list[TGL_MAX_RSA_KEYS_NUM];
215 void *rsa_key_loaded[TGL_MAX_RSA_KEYS_NUM];
216 long long rsa_key_fingerprint[TGL_MAX_RSA_KEYS_NUM];
218 struct bignum_ctx *BN_ctx;
219 struct tgl_allocator allocator;
220 struct tree_peer *peer_tree;
221 struct tree_peer_by_name *peer_by_name_tree;
222 struct tree_message *message_tree;
223 struct tree_message *message_unsent_tree;
226 int messages_allocated;
229 int encr_chats_allocated;
230 int geo_chats_allocated;
232 struct tgl_message message_list;
234 struct tgl_timer_methods *timer_methods;
235 struct tree_query *queries_tree;
237 struct tree_user *online_updates;
238 struct tgl_timer *online_updates_timer;
247 extern void tgl_reopen_binlog_for_writing(struct tgl_state *TLS);
248 extern void tgl_replay_log(struct tgl_state *TLS);
250 extern int tgl_print_stat(struct tgl_state *TLS, char *s, int len);
251 extern tgl_peer_t *tgl_peer_get(struct tgl_state *TLS, tgl_peer_id_t id);
252 extern tgl_peer_t *tgl_peer_get_by_name(struct tgl_state *TLS, const char *s);
254 extern struct tgl_message *tgl_message_get(struct tgl_state *TLS, long long id);
255 extern void tgl_peer_iterator_ex(struct tgl_state *TLS, void(*it)(tgl_peer_t *P, void *extra), void *extra);
257 extern int tgl_complete_user_list(struct tgl_state *TLS, int index, const char *text, int len, char **R);
258 extern int tgl_complete_chat_list(struct tgl_state *TLS, int index, const char *text, int len, char **R);
259 extern int tgl_complete_encr_chat_list(struct tgl_state *TLS, int index, const char *text, int len, char **R);
260 extern int tgl_complete_peer_list(struct tgl_state *TLS, int index, const char *text, int len, char **R);
261 extern int tgl_secret_chat_for_user(struct tgl_state *TLS, tgl_peer_id_t user_id);
263 #define TGL_PEER_USER 1
264 #define TGL_PEER_CHAT 2
265 #define TGL_PEER_GEO_CHAT 3
266 #define TGL_PEER_ENCR_CHAT 4
267 #define TGL_PEER_UNKNOWN 0
269 #define TGL_MK_USER(id) tgl_set_peer_id(TGL_PEER_USER,id)
270 #define TGL_MK_CHAT(id) tgl_set_peer_id(TGL_PEER_CHAT,id)
271 #define TGL_MK_GEO_CHAT(id) tgl_set_peer_id(TGL_PEER_GEO_CHAT,id)
272 #define TGL_MK_ENCR_CHAT(id) tgl_set_peer_id(TGL_PEER_ENCR_CHAT,id)
274 extern void tgl_set_binlog_mode(struct tgl_state *TLS, int mode);
275 extern void tgl_set_binlog_path(struct tgl_state *TLS, const char *path);
276 extern void tgl_set_auth_file_path(struct tgl_state *TLS, const char *path);
277 extern void tgl_set_download_directory(struct tgl_state *TLS, const char *path);
278 extern void tgl_set_callback(struct tgl_state *TLS, struct tgl_update_callback *cb, void *cbdata);
279 extern void tgl_set_rsa_key(struct tgl_state *TLS, const char *key);
280 extern void tgl_set_app_version(struct tgl_state *TLS, const char *app_version);
282 static inline int tgl_get_peer_type(tgl_peer_id_t id)
287 static inline int tgl_get_peer_id(tgl_peer_id_t id)
292 static inline tgl_peer_id_t tgl_set_peer_id(int type, int id)
300 static inline int tgl_cmp_peer_id(tgl_peer_id_t a, tgl_peer_id_t b)
302 return memcmp(&a, &b, sizeof(a));
305 extern void tgl_incr_verbosity(struct tgl_state *TLS);
306 extern void tgl_set_verbosity(struct tgl_state *TLS, int val);
307 extern void tgl_enable_pfs(struct tgl_state *TLS);
308 extern void tgl_set_test_mode(struct tgl_state *TLS);
309 extern void tgl_set_net_methods(struct tgl_state *TLS, struct tgl_net_methods *methods);
310 extern void tgl_set_timer_methods(struct tgl_state *TLS, struct tgl_timer_methods *methods);
313 //int tgl_connections_make_poll_array(struct tgl_state *TLS, struct pollfd *fds, int max);
314 //void tgl_connections_poll_result(struct tgl_state *TLS, struct pollfd *fds, int max);
316 extern void tgl_do_help_get_config(struct tgl_state *TLS, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
317 extern void tgl_do_send_code(struct tgl_state *TLS, const char *user, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int registered, const char *hash), void *callback_extra);
318 extern void tgl_do_phone_call(struct tgl_state *TLS, const char *user, const char *hash, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
319 extern int tgl_do_send_code_result(struct tgl_state *TLS, const char *user, const char *hash, const char *code, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *Self), void *callback_extra) ;
320 extern int tgl_do_send_code_result_auth(struct tgl_state *TLS, const char *user, const char *hash, const char *code, const char *first_name, const char *last_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *Self), void *callback_extra);
321 extern void tgl_do_update_contact_list(struct tgl_state *TLS, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_user *contacts[]), void *callback_extra);
322 extern void tgl_do_send_message(struct tgl_state *TLS, tgl_peer_id_t id, const char *msg, int len, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
323 extern void tgl_do_send_msg(struct tgl_state *TLS, struct tgl_message *M, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
324 extern void tgl_do_send_text(struct tgl_state *TLS, tgl_peer_id_t id, char *file, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
325 extern void tgl_do_mark_read(struct tgl_state *TLS, tgl_peer_id_t id, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
326 extern void tgl_do_get_history(struct tgl_state *TLS, tgl_peer_id_t id, int limit, int offline_mode, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_message *list[]), void *callback_extra);
327 extern void tgl_do_get_history_ext(struct tgl_state *TLS, tgl_peer_id_t id, int offset, int limit, int offline_mode, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_message *list[]), void *callback_extra);
328 extern void tgl_do_get_dialog_list(struct tgl_state *TLS, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, tgl_peer_id_t peers[], int last_msg_id[], int unread_count[]), void *callback_extra);
329 extern void tgl_do_send_photo(struct tgl_state *TLS, enum tgl_message_media_type type, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
330 extern void tgl_do_send_document(struct tgl_state *TLS, int flags, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
331 extern void tgl_do_send_audio(struct tgl_state *TLS, tgl_peer_id_t to_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
332 extern void tgl_do_send_video(struct tgl_state *TLS, int flags, tgl_peer_id_t to_id, char *video_name, char *thumb_file, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
333 extern void tgl_do_set_chat_photo(struct tgl_state *TLS, tgl_peer_id_t chat_id, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
334 extern void tgl_do_set_profile_photo(struct tgl_state *TLS, char *file_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
335 extern void tgl_do_set_profile_name(struct tgl_state *TLS, const char *first_name, const char *last_name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
336 extern void tgl_do_set_username(struct tgl_state *TLS, char *name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
337 extern void tgl_do_forward_message(struct tgl_state *TLS, tgl_peer_id_t id, int n, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
338 extern void tgl_do_rename_chat(struct tgl_state *TLS, tgl_peer_id_t id, char *name, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
339 extern void tgl_do_get_chat_info(struct tgl_state *TLS, tgl_peer_id_t id, int offline_mode, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_chat *C), void *callback_extra);
340 extern void tgl_do_get_user_info(struct tgl_state *TLS, tgl_peer_id_t id, int offline_mode, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
341 extern void tgl_do_load_photo(struct tgl_state *TLS, struct tgl_photo *photo, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, char *filename), void *callback_extra);
342 extern void tgl_do_set_password(struct tgl_state *TLS, char *hint, void(*callback)(struct tgl_state *TLS, void *extra, int success), void *extra);
343 extern void tgl_do_check_password(struct tgl_state *TLS, void(*callback)(struct tgl_state *TLS, void *extra, int success), void *callback_extra);
344 extern void tgl_do_load_encr_document(struct tgl_state *TLS, struct tgl_encr_document *V, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, char *filename), void *callback_extra);
345 extern void tgl_do_load_document(struct tgl_state *TLS, struct tgl_document *V, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, char *filename), void *callback_extra);
346 extern void tgl_do_load_document_thumb(struct tgl_state *TLS, struct tgl_document *video, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, char *filename), void *callback_extra);
347 extern void tgl_do_export_auth(struct tgl_state *TLS, int num, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
348 extern void tgl_do_add_contact(struct tgl_state *TLS, const char *phone, const char *first_name, const char *last_name, int force, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_user *users[]), void *callback_extra);
349 extern void tgl_do_msg_search(struct tgl_state *TLS, tgl_peer_id_t id, int from, int to, int limit, int offset, const char *s, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_message *list[]), void *callback_extra);
350 //extern void tgl_do_contacts_search(int limit, const char *s, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, struct tgl_user *users[]), void *callback_extra);
351 extern void tgl_do_create_encr_chat_request(struct tgl_state *TLS, int user_id, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
352 extern void tgl_do_create_secret_chat(struct tgl_state *TLS, tgl_peer_id_t id, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
353 extern void tgl_do_accept_encr_chat_request(struct tgl_state *TLS, struct tgl_secret_chat *E, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
354 extern void tgl_do_get_difference(struct tgl_state *TLS, int sync_from_start, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
355 extern void tgl_do_lookup_state(struct tgl_state *TLS);
356 extern void tgl_do_add_user_to_chat(struct tgl_state *TLS, tgl_peer_id_t chat_id, tgl_peer_id_t id, int limit, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
357 extern void tgl_do_del_user_from_chat(struct tgl_state *TLS, tgl_peer_id_t chat_id, tgl_peer_id_t id, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
358 extern void tgl_do_create_group_chat(struct tgl_state *TLS, tgl_peer_id_t id, char *chat_topic, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
359 extern void tgl_do_create_group_chat_ex(struct tgl_state *TLS, int users_num, tgl_peer_id_t ids[], const char *chat_topic, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
360 extern void tgl_do_delete_msg(struct tgl_state *TLS, long long id, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
361 extern void tgl_do_restore_msg(struct tgl_state *TLS, long long id, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
362 extern void tgl_do_update_status(struct tgl_state *TLS, int online, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
363 extern void tgl_do_help_get_config_dc(struct tgl_state *TLS, struct tgl_dc *D, void(*callback)(struct tgl_state *TLS, void *, int), void *callback_extra);
364 extern void tgl_do_export_card(struct tgl_state *TLS, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int size, int *card), void *callback_extra);
365 extern void tgl_do_import_card(struct tgl_state *TLS, int size, int *card, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_user *U), void *callback_extra);
366 extern void tgl_do_send_contact(struct tgl_state *TLS, tgl_peer_id_t id, const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
367 extern void tgl_do_forward_media(struct tgl_state *TLS, tgl_peer_id_t id, int n, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
368 extern void tgl_do_del_contact(struct tgl_state *TLS, tgl_peer_id_t id, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
369 extern void tgl_do_set_encr_chat_ttl(struct tgl_state *TLS, struct tgl_secret_chat *E, int ttl, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
370 extern void tgl_do_send_location(struct tgl_state *TLS, tgl_peer_id_t id, double latitude, double longitude, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
371 extern void tgl_do_contact_search(struct tgl_state *TLS, char *name, int limit, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, int cnt, struct tgl_user *U[]), void *callback_extra);
372 extern void tgl_do_request_exchange(struct tgl_state *TLS, struct tgl_secret_chat *E);
373 extern void tgl_do_send_typing(struct tgl_state *TLS, tgl_peer_id_t id, enum tgl_typing_status status, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
376 void tgl_do_block_user (struct tgl_state *TLS, tgl_peer_id_t id, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
378 // unblocks blocked user
379 void tgl_do_unblock_user (struct tgl_state *TLS, tgl_peer_id_t id, void (*callback)(struct tgl_state *TLS, void *callback_extra, int success), void *callback_extra);
382 extern void tgl_do_send_broadcast(struct tgl_state *TLS, int num, tgl_peer_id_t id[], const char *text, int text_len, void(*callback)(struct tgl_state *TLS, void *extra, int success, int num, struct tgl_message *ML[]), void *callback_extra);
383 extern void tgl_do_visualize_key(struct tgl_state *TLS, tgl_peer_id_t id, unsigned char buf[16]);
384 extern void tgl_do_send_ping(struct tgl_state *TLS, struct connection *c);
385 extern void tgl_do_send_extf(struct tgl_state *TLS, char *data, int data_len, void(*callback)(struct tgl_state *TLS, void *callback_extra, int success, char *data), void *callback_extra);
386 extern int tgl_authorized_dc(struct tgl_state *TLS, struct tgl_dc *DC);
387 extern int tgl_signed_dc(struct tgl_state *TLS, struct tgl_dc *DC);
388 //void tgl_do_get_suggested(void);
389 extern void tgl_do_create_keys_end(struct tgl_state *TLS, struct tgl_secret_chat *U);
390 extern void tgl_do_send_encr_chat_layer(struct tgl_state *TLS, struct tgl_secret_chat *E);
391 extern void tgl_init(struct tgl_state *TLS);
392 extern void tgl_dc_authorize(struct tgl_state *TLS, struct tgl_dc *DC);
393 extern void tgl_dc_iterator(struct tgl_state *TLS, void(*iterator)(struct tgl_dc *DC));
394 extern void tgl_dc_iterator_ex(struct tgl_state *TLS, void(*iterator)(struct tgl_dc *DC, void *extra), void *extra);
395 extern double tglt_get_double_time(void);
396 extern void tgl_insert_empty_user(struct tgl_state *TLS, int id);
397 extern void tgl_insert_empty_chat(struct tgl_state *TLS, int id);
398 extern int tglf_extf_autocomplete(struct tgl_state *TLS, const char *text, int text_len, int index, char **R, char *data, int data_len);
399 extern struct paramed_type *tglf_extf_store(struct tgl_state *TLS, const char *data, int data_len);
400 extern char *tglf_extf_fetch(struct tgl_state *TLS, struct paramed_type *T);
401 extern void tgl_free_all(struct tgl_state *TLS);
402 extern void tgl_register_app_id(struct tgl_state *TLS, int app_id, char *app_hash);
403 extern void tgl_login(struct tgl_state *TLS);
404 extern void tgl_enable_ipv6(struct tgl_state *TLS);
405 extern struct tgl_state *tgl_state_alloc(void);
406 extern void tgl_state_free(struct tgl_state *TLS);