2013-10-23 10:26:17 -04:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2013-10-11 16:52:20 -04:00
|
|
|
#ifndef __STRUCTURES_H__
|
|
|
|
#define __STRUCTURES_H__
|
|
|
|
|
2013-10-31 19:18:34 -04:00
|
|
|
#include <assert.h>
|
2013-11-04 12:34:27 -05:00
|
|
|
typedef struct { int type; int id; } peer_id_t;
|
2013-10-31 19:18:34 -04:00
|
|
|
|
2013-11-21 14:35:49 -05:00
|
|
|
//#define FLAG_EMPTY 1
|
|
|
|
#define FLAG_MESSAGE_EMPTY 1
|
2013-10-24 03:38:32 -04:00
|
|
|
#define FLAG_DELETED 2
|
|
|
|
#define FLAG_FORBIDDEN 4
|
2013-10-24 13:04:44 -04:00
|
|
|
#define FLAG_HAS_PHOTO 8
|
2013-11-14 19:08:24 -05:00
|
|
|
#define FLAG_CREATED 16
|
2013-10-24 03:38:32 -04:00
|
|
|
|
|
|
|
#define FLAG_USER_SELF 128
|
|
|
|
#define FLAG_USER_FOREIGN 256
|
|
|
|
#define FLAG_USER_CONTACT 512
|
2013-10-25 13:29:02 -04:00
|
|
|
#define FLAG_USER_IN_CONTACT 1024
|
|
|
|
#define FLAG_USER_OUT_CONTACT 2048
|
2013-10-24 03:38:32 -04:00
|
|
|
|
|
|
|
#define FLAG_CHAT_IN_CHAT 128
|
2013-10-11 16:52:20 -04:00
|
|
|
|
2013-11-02 13:01:22 -04:00
|
|
|
#define FLAG_ENCRYPTED 4096
|
2013-11-29 16:43:56 -05:00
|
|
|
#define FLAG_PENDING 8192
|
2013-10-31 19:18:34 -04:00
|
|
|
|
2013-10-11 16:52:20 -04:00
|
|
|
struct file_location {
|
|
|
|
int dc;
|
|
|
|
long long volume;
|
|
|
|
int local_id;
|
|
|
|
long long secret;
|
|
|
|
};
|
|
|
|
|
2013-10-24 13:04:44 -04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2013-11-02 13:01:22 -04:00
|
|
|
struct encr_photo {
|
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int dc_id;
|
|
|
|
int size;
|
|
|
|
int key_fingerprint;
|
|
|
|
|
|
|
|
unsigned char *key;
|
|
|
|
unsigned char *iv;
|
2013-11-15 05:37:14 -05:00
|
|
|
int w;
|
|
|
|
int h;
|
2013-11-02 13:01:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct encr_video {
|
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int dc_id;
|
|
|
|
int size;
|
|
|
|
int key_fingerprint;
|
|
|
|
|
2013-11-15 05:37:14 -05:00
|
|
|
unsigned char *key;
|
|
|
|
unsigned char *iv;
|
2013-11-02 13:01:22 -04:00
|
|
|
int w;
|
|
|
|
int h;
|
2013-11-15 05:37:14 -05:00
|
|
|
int duration;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct encr_audio {
|
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int dc_id;
|
|
|
|
int size;
|
|
|
|
int key_fingerprint;
|
|
|
|
|
2013-11-02 13:01:22 -04:00
|
|
|
unsigned char *key;
|
|
|
|
unsigned char *iv;
|
2013-11-04 18:15:24 -05:00
|
|
|
int duration;
|
2013-11-02 13:01:22 -04:00
|
|
|
};
|
|
|
|
|
2013-11-15 05:37:14 -05:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2013-11-02 13:01:22 -04:00
|
|
|
struct encr_file {
|
|
|
|
char *filename;
|
|
|
|
unsigned char *key;
|
|
|
|
unsigned char *iv;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-11 16:52:20 -04:00
|
|
|
struct user_status {
|
|
|
|
int online;
|
|
|
|
int when;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct user {
|
2013-10-31 19:18:34 -04:00
|
|
|
peer_id_t id;
|
2013-10-11 16:52:20 -04:00
|
|
|
int flags;
|
2013-11-04 12:34:27 -05:00
|
|
|
struct message *last;
|
2013-10-14 13:26:25 -04:00
|
|
|
char *print_name;
|
2013-11-14 19:08:24 -05:00
|
|
|
int structure_version;
|
2013-10-14 13:26:25 -04:00
|
|
|
struct file_location photo_big;
|
|
|
|
struct file_location photo_small;
|
2013-11-21 14:35:49 -05:00
|
|
|
long long photo_id;
|
2013-10-24 13:04:44 -04:00
|
|
|
struct photo photo;
|
2013-10-11 16:52:20 -04:00
|
|
|
char *first_name;
|
|
|
|
char *last_name;
|
|
|
|
char *phone;
|
|
|
|
long long access_hash;
|
|
|
|
struct user_status status;
|
2013-10-25 13:29:02 -04:00
|
|
|
int blocked;
|
|
|
|
char *real_first_name;
|
|
|
|
char *real_last_name;
|
2013-10-11 16:52:20 -04:00
|
|
|
};
|
|
|
|
|
2013-10-24 13:04:44 -04:00
|
|
|
struct chat_user {
|
|
|
|
int user_id;
|
|
|
|
int inviter_id;
|
|
|
|
int date;
|
|
|
|
};
|
|
|
|
|
2013-10-13 08:30:53 -04:00
|
|
|
struct chat {
|
2013-10-31 19:18:34 -04:00
|
|
|
peer_id_t id;
|
2013-10-13 08:30:53 -04:00
|
|
|
int flags;
|
2013-11-04 12:34:27 -05:00
|
|
|
struct message *last;
|
2013-10-13 08:30:53 -04:00
|
|
|
char *print_title;
|
2013-11-14 19:08:24 -05:00
|
|
|
int structure_version;
|
2013-10-14 13:26:25 -04:00
|
|
|
struct file_location photo_big;
|
|
|
|
struct file_location photo_small;
|
2013-10-24 13:04:44 -04:00
|
|
|
struct photo photo;
|
2013-10-14 13:26:25 -04:00
|
|
|
char *title;
|
2013-10-24 13:04:44 -04:00
|
|
|
int users_num;
|
2013-11-25 11:13:36 -05:00
|
|
|
int user_list_size;
|
|
|
|
int user_list_version;
|
|
|
|
struct chat_user *user_list;
|
2013-10-13 08:30:53 -04:00
|
|
|
int date;
|
|
|
|
int version;
|
2013-10-23 06:24:59 -04:00
|
|
|
int admin_id;
|
2013-10-14 13:26:25 -04:00
|
|
|
};
|
|
|
|
|
2013-11-02 06:14:30 -04:00
|
|
|
enum secret_chat_state {
|
|
|
|
sc_none,
|
2013-11-02 13:01:22 -04:00
|
|
|
sc_waiting,
|
|
|
|
sc_request,
|
2013-11-02 06:14:30 -04:00
|
|
|
sc_ok,
|
2013-11-02 13:01:22 -04:00
|
|
|
sc_deleted
|
2013-11-02 06:14:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct secret_chat {
|
|
|
|
peer_id_t id;
|
|
|
|
int flags;
|
2013-11-04 12:34:27 -05:00
|
|
|
struct message *last;
|
2013-11-02 06:14:30 -04:00
|
|
|
char *print_name;
|
2013-11-14 19:08:24 -05:00
|
|
|
int structure_version;
|
2013-11-02 06:14:30 -04:00
|
|
|
struct file_location photo_big;
|
|
|
|
struct file_location photo_small;
|
|
|
|
struct photo photo;
|
2013-11-02 13:01:22 -04:00
|
|
|
int user_id;
|
|
|
|
int admin_id;
|
|
|
|
int date;
|
|
|
|
int ttl;
|
|
|
|
long long access_hash;
|
|
|
|
unsigned char *g_key;
|
|
|
|
unsigned char *nonce;
|
2013-11-02 06:14:30 -04:00
|
|
|
|
|
|
|
enum secret_chat_state state;
|
|
|
|
int key[64];
|
|
|
|
long long key_fingerprint;
|
|
|
|
};
|
|
|
|
|
2013-10-31 19:18:34 -04:00
|
|
|
typedef union peer {
|
2013-10-14 13:26:25 -04:00
|
|
|
struct {
|
2013-10-31 19:18:34 -04:00
|
|
|
peer_id_t id;
|
2013-10-14 13:26:25 -04:00
|
|
|
int flags;
|
2013-11-04 12:34:27 -05:00
|
|
|
struct message *last;
|
2013-10-14 13:26:25 -04:00
|
|
|
char *print_name;
|
2013-11-14 19:08:24 -05:00
|
|
|
int structure_version;
|
2013-10-14 13:26:25 -04:00
|
|
|
struct file_location photo_big;
|
|
|
|
struct file_location photo_small;
|
2013-10-24 13:04:44 -04:00
|
|
|
struct photo photo;
|
2013-10-14 13:26:25 -04:00
|
|
|
};
|
|
|
|
struct user user;
|
|
|
|
struct chat chat;
|
2013-11-02 06:14:30 -04:00
|
|
|
struct secret_chat encr_chat;
|
2013-10-31 19:18:34 -04:00
|
|
|
} peer_t;
|
2013-10-14 13:26:25 -04:00
|
|
|
|
|
|
|
struct video {
|
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int user_id;
|
|
|
|
int date;
|
|
|
|
int size;
|
|
|
|
int dc_id;
|
2013-11-15 05:37:14 -05:00
|
|
|
struct photo_size thumb;
|
|
|
|
char *caption;
|
|
|
|
int duration;
|
2013-10-14 13:26:25 -04:00
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
};
|
|
|
|
|
2013-11-15 05:37:14 -05:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2013-10-14 13:26:25 -04:00
|
|
|
struct message_action {
|
2014-03-06 16:07:04 -05:00
|
|
|
unsigned type;
|
2013-10-14 13:26:25 -04:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
char *title;
|
|
|
|
int user_num;
|
|
|
|
int *users;
|
|
|
|
};
|
|
|
|
char *new_title;
|
|
|
|
struct photo photo;
|
|
|
|
int user;
|
2013-11-15 05:37:14 -05:00
|
|
|
int ttl;
|
2013-10-14 13:26:25 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct message_media {
|
2014-03-06 16:07:04 -05:00
|
|
|
unsigned type;
|
2013-10-14 13:26:25 -04:00
|
|
|
union {
|
|
|
|
struct photo photo;
|
|
|
|
struct video video;
|
2013-11-15 05:37:14 -05:00
|
|
|
struct audio audio;
|
|
|
|
struct document document;
|
2013-10-14 13:26:25 -04:00
|
|
|
struct geo geo;
|
|
|
|
struct {
|
|
|
|
char *phone;
|
|
|
|
char *first_name;
|
|
|
|
char *last_name;
|
|
|
|
int user_id;
|
|
|
|
};
|
2013-11-02 13:01:22 -04:00
|
|
|
struct encr_photo encr_photo;
|
|
|
|
struct encr_video encr_video;
|
2013-11-15 05:37:14 -05:00
|
|
|
struct encr_audio encr_audio;
|
|
|
|
struct encr_document encr_document;
|
2013-11-02 13:01:22 -04:00
|
|
|
struct encr_file encr_file;
|
2013-10-14 13:26:25 -04:00
|
|
|
void *data;
|
2014-01-10 09:37:56 -05:00
|
|
|
int data_size;
|
2013-10-14 13:26:25 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct message {
|
|
|
|
struct message *next_use, *prev_use;
|
2013-11-04 12:34:27 -05:00
|
|
|
struct message *next, *prev;
|
2013-11-02 06:14:30 -04:00
|
|
|
long long id;
|
2013-10-14 13:26:25 -04:00
|
|
|
int flags;
|
2013-10-31 19:18:34 -04:00
|
|
|
peer_id_t fwd_from_id;
|
2013-10-14 13:26:25 -04:00
|
|
|
int fwd_date;
|
2013-10-31 19:18:34 -04:00
|
|
|
peer_id_t from_id;
|
|
|
|
peer_id_t to_id;
|
2013-10-14 13:26:25 -04:00
|
|
|
int out;
|
|
|
|
int unread;
|
|
|
|
int date;
|
|
|
|
int service;
|
|
|
|
union {
|
|
|
|
struct message_action action;
|
|
|
|
struct {
|
|
|
|
char *message;
|
2013-10-22 11:28:41 -04:00
|
|
|
int message_len;
|
2013-10-14 13:26:25 -04:00
|
|
|
struct message_media media;
|
|
|
|
};
|
|
|
|
};
|
2013-10-13 08:30:53 -04:00
|
|
|
};
|
|
|
|
|
2013-11-14 19:08:24 -05:00
|
|
|
int fetch_file_location (struct file_location *loc);
|
|
|
|
int fetch_user_status (struct user_status *S);
|
|
|
|
int fetch_user (struct user *U);
|
2013-10-13 06:18:08 -04:00
|
|
|
struct user *fetch_alloc_user (void);
|
2013-10-25 13:29:02 -04:00
|
|
|
struct user *fetch_alloc_user_full (void);
|
2013-10-14 13:26:25 -04:00
|
|
|
struct chat *fetch_alloc_chat (void);
|
2013-10-25 13:29:02 -04:00
|
|
|
struct chat *fetch_alloc_chat_full (void);
|
2013-11-02 13:01:22 -04:00
|
|
|
struct secret_chat *fetch_alloc_encrypted_chat (void);
|
2013-10-16 15:19:39 -04:00
|
|
|
struct message *fetch_alloc_message (void);
|
2013-11-01 15:57:57 -04:00
|
|
|
struct message *fetch_alloc_geo_message (void);
|
2013-10-16 15:19:39 -04:00
|
|
|
struct message *fetch_alloc_message_short (void);
|
|
|
|
struct message *fetch_alloc_message_short_chat (void);
|
2013-11-02 13:01:22 -04:00
|
|
|
struct message *fetch_alloc_encrypted_message (void);
|
|
|
|
void fetch_encrypted_message_file (struct message_media *M);
|
2013-11-29 16:43:56 -05:00
|
|
|
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);
|
2013-10-31 19:18:34 -04:00
|
|
|
peer_id_t fetch_peer_id (void);
|
2013-10-13 06:18:08 -04:00
|
|
|
|
2013-11-29 16:43:56 -05:00
|
|
|
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);
|
|
|
|
|
2013-10-13 06:18:08 -04:00
|
|
|
void free_user (struct user *U);
|
2013-10-14 13:26:25 -04:00
|
|
|
void free_chat (struct chat *U);
|
2013-10-13 06:18:08 -04:00
|
|
|
|
2013-11-14 19:08:24 -05:00
|
|
|
char *create_print_name (peer_id_t id, const char *a1, const char *a2, const char *a3, const char *a4);
|
|
|
|
|
2013-10-13 06:18:08 -04:00
|
|
|
int print_stat (char *s, int len);
|
2013-10-31 19:18:34 -04:00
|
|
|
peer_t *user_chat_get (peer_id_t id);
|
2013-11-02 06:14:30 -04:00
|
|
|
struct message *message_get (long long id);
|
|
|
|
void update_message_id (struct message *M, long long id);
|
2013-10-18 15:30:24 -04:00
|
|
|
void message_insert (struct message *M);
|
2013-10-24 13:04:44 -04:00
|
|
|
void free_photo (struct photo *P);
|
|
|
|
void fetch_photo (struct photo *P);
|
2013-11-04 12:34:27 -05:00
|
|
|
void insert_encrypted_chat (peer_t *P);
|
2013-11-21 14:35:49 -05:00
|
|
|
void insert_user (peer_t *P);
|
2013-11-22 18:26:35 -05:00
|
|
|
void insert_chat (peer_t *P);
|
2013-11-21 14:35:49 -05:00
|
|
|
void fetch_photo (struct photo *P);
|
|
|
|
void free_photo (struct photo *P);
|
2013-11-29 16:43:56 -05:00
|
|
|
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);
|
2013-12-02 12:19:08 -05:00
|
|
|
void free_message (struct message *M);
|
2014-01-11 11:01:01 -05:00
|
|
|
void message_del_use (struct message *M);
|
2014-01-31 11:03:40 -05:00
|
|
|
void peer_insert_name (peer_t *P);
|
|
|
|
void peer_delete_name (peer_t *P);
|
|
|
|
peer_t *peer_lookup_name (const char *s);
|
2013-10-31 19:18:34 -04:00
|
|
|
|
|
|
|
#define PEER_USER 1
|
|
|
|
#define PEER_CHAT 2
|
2013-11-01 15:57:57 -04:00
|
|
|
#define PEER_GEO_CHAT 3
|
2013-11-02 06:14:30 -04:00
|
|
|
#define PEER_ENCR_CHAT 4
|
2013-10-31 19:18:34 -04:00
|
|
|
#define PEER_UNKNOWN 0
|
|
|
|
|
|
|
|
#define MK_USER(id) set_peer_id (PEER_USER,id)
|
|
|
|
#define MK_CHAT(id) set_peer_id (PEER_CHAT,id)
|
2013-11-01 15:57:57 -04:00
|
|
|
#define MK_GEO_CHAT(id) set_peer_id (PEER_GEO_CHAT,id)
|
2013-11-02 06:14:30 -04:00
|
|
|
#define MK_ENCR_CHAT(id) set_peer_id (PEER_ENCR_CHAT,id)
|
2013-10-31 19:18:34 -04:00
|
|
|
|
|
|
|
static inline int get_peer_type (peer_id_t id) {
|
2013-11-04 12:34:27 -05:00
|
|
|
return id.type;
|
2013-10-31 19:18:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int get_peer_id (peer_id_t id) {
|
2013-11-04 12:34:27 -05:00
|
|
|
return id.id;
|
2013-10-31 19:18:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline peer_id_t set_peer_id (int type, int id) {
|
|
|
|
peer_id_t ID;
|
2013-11-04 12:34:27 -05:00
|
|
|
ID.id = id;
|
|
|
|
ID.type = type;
|
|
|
|
return ID;
|
2013-10-31 19:18:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int cmp_peer_id (peer_id_t a, peer_id_t b) {
|
|
|
|
return memcmp (&a, &b, sizeof (a));
|
|
|
|
}
|
|
|
|
|
2013-10-11 16:52:20 -04:00
|
|
|
#endif
|