forked from vysheng/tg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structures.h
413 lines (364 loc) · 8.5 KB
/
structures.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
This file is part of telegram-client.
Telegram-client is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Telegram-client is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this telegram-client. If not, see <http://www.gnu.org/licenses/>.
Copyright Vitaly Valtman 2013
*/
#ifndef __STRUCTURES_H__
#define __STRUCTURES_H__
#include <assert.h>
typedef struct { int type; int id; } peer_id_t;
//#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
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;
};
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;
};
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;
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;
};
struct audio {
long long id;
long long access_hash;
int user_id;
int date;
int size;
int dc_id;
int duration;
};
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;
};
};
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;
};
};
};
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 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);
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);
peer_t *user_chat_get (peer_id_t id);
struct message *message_get (long long id);
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);
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);
peer_t *peer_lookup_name (const char *s);
#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));
}
#endif