2014-08-21 18:02:43 -04:00
|
|
|
/*
|
|
|
|
This file is part of tgl-library
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Copyright Vitaly Valtman 2014
|
|
|
|
*/
|
2014-08-13 08:56:55 -04:00
|
|
|
#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)
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
typedef struct { int type; int id; } tgl_peer_id_t;
|
2014-08-13 08:56:55 -04:00
|
|
|
|
2014-08-20 23:24:52 -04:00
|
|
|
enum tgl_dc_state {
|
|
|
|
st_init,
|
|
|
|
st_reqpq_sent,
|
|
|
|
st_reqdh_sent,
|
|
|
|
st_client_dh_sent,
|
2014-08-29 09:33:15 -04:00
|
|
|
st_init_temp,
|
|
|
|
st_reqpq_sent_temp,
|
|
|
|
st_reqdh_sent_temp,
|
|
|
|
st_client_dh_sent_temp,
|
2014-08-20 23:24:52 -04:00
|
|
|
st_authorized,
|
|
|
|
st_error
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_DC_SESSIONS 3
|
|
|
|
|
|
|
|
struct tgl_session {
|
|
|
|
struct tgl_dc *dc;
|
|
|
|
long long session_id;
|
|
|
|
int seq_no;
|
|
|
|
struct connection *c;
|
|
|
|
struct tree_long *ack_tree;
|
|
|
|
struct event *ev;
|
|
|
|
//struct event_timer ev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tgl_dc {
|
|
|
|
int id;
|
|
|
|
int port;
|
|
|
|
int flags;
|
|
|
|
enum tgl_dc_state state;
|
|
|
|
char *ip;
|
2014-09-18 09:57:23 -04:00
|
|
|
//char *user;
|
2014-08-20 23:24:52 -04:00
|
|
|
struct tgl_session *sessions[MAX_DC_SESSIONS];
|
|
|
|
char auth_key[256];
|
2014-08-29 09:33:15 -04:00
|
|
|
char temp_auth_key[256];
|
|
|
|
char nonce[256];
|
|
|
|
char new_nonce[256];
|
|
|
|
char server_nonce[256];
|
2014-08-20 23:24:52 -04:00
|
|
|
long long auth_key_id;
|
2014-08-29 09:33:15 -04:00
|
|
|
long long temp_auth_key_id;
|
|
|
|
|
2014-08-20 23:24:52 -04:00
|
|
|
long long server_salt;
|
2014-08-29 09:33:15 -04:00
|
|
|
struct event *ev;
|
2014-08-20 23:24:52 -04:00
|
|
|
|
|
|
|
int server_time_delta;
|
|
|
|
double server_time_udelta;
|
|
|
|
int has_auth;
|
|
|
|
};
|
|
|
|
|
2014-08-18 12:39:04 -04:00
|
|
|
enum tgl_message_media_type {
|
|
|
|
tgl_message_media_none,
|
|
|
|
tgl_message_media_photo,
|
|
|
|
tgl_message_media_video,
|
|
|
|
tgl_message_media_audio,
|
|
|
|
tgl_message_media_document,
|
|
|
|
tgl_message_media_geo,
|
|
|
|
tgl_message_media_contact,
|
|
|
|
tgl_message_media_unsupported,
|
|
|
|
tgl_message_media_photo_encr,
|
|
|
|
tgl_message_media_video_encr,
|
|
|
|
tgl_message_media_audio_encr,
|
|
|
|
tgl_message_media_document_encr,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum tgl_message_action_type {
|
|
|
|
tgl_message_action_none,
|
|
|
|
tgl_message_action_geo_chat_create,
|
|
|
|
tgl_message_action_geo_chat_checkin,
|
|
|
|
tgl_message_action_chat_create,
|
|
|
|
tgl_message_action_chat_edit_title,
|
|
|
|
tgl_message_action_chat_edit_photo,
|
|
|
|
tgl_message_action_chat_delete_photo,
|
|
|
|
tgl_message_action_chat_add_user,
|
|
|
|
tgl_message_action_chat_delete_user,
|
|
|
|
tgl_message_action_set_message_ttl,
|
|
|
|
tgl_message_action_read_messages,
|
|
|
|
tgl_message_action_delete_messages,
|
|
|
|
tgl_message_action_screenshot_messages,
|
|
|
|
tgl_message_action_flush_history,
|
|
|
|
tgl_message_action_notify_layer
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_file_location {
|
2014-08-13 08:56:55 -04:00
|
|
|
int dc;
|
|
|
|
long long volume;
|
|
|
|
int local_id;
|
|
|
|
long long secret;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo_size {
|
2014-08-13 08:56:55 -04:00
|
|
|
char *type;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_file_location loc;
|
2014-08-13 08:56:55 -04:00
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int size;
|
|
|
|
char *data;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_geo {
|
2014-08-13 08:56:55 -04:00
|
|
|
double longitude;
|
|
|
|
double latitude;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo {
|
2014-08-13 08:56:55 -04:00
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int user_id;
|
|
|
|
int date;
|
|
|
|
char *caption;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_geo geo;
|
2014-08-13 08:56:55 -04:00
|
|
|
int sizes_num;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo_size *sizes;
|
2014-08-13 08:56:55 -04:00
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_encr_photo {
|
2014-08-13 08:56:55 -04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_encr_video {
|
2014-08-13 08:56:55 -04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_encr_audio {
|
2014-08-13 08:56:55 -04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_encr_document {
|
2014-08-13 08:56:55 -04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_encr_file {
|
2014-08-13 08:56:55 -04:00
|
|
|
char *filename;
|
|
|
|
unsigned char *key;
|
|
|
|
unsigned char *iv;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_user_status {
|
2014-08-13 08:56:55 -04:00
|
|
|
int online;
|
|
|
|
int when;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_user {
|
|
|
|
tgl_peer_id_t id;
|
2014-08-13 08:56:55 -04:00
|
|
|
int flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message *last;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *print_name;
|
|
|
|
int structure_version;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_file_location photo_big;
|
|
|
|
struct tgl_file_location photo_small;
|
2014-08-13 08:56:55 -04:00
|
|
|
long long photo_id;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo photo;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *first_name;
|
|
|
|
char *last_name;
|
|
|
|
char *phone;
|
|
|
|
long long access_hash;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_user_status status;
|
2014-08-13 08:56:55 -04:00
|
|
|
int blocked;
|
|
|
|
char *real_first_name;
|
|
|
|
char *real_last_name;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_chat_user {
|
2014-08-13 08:56:55 -04:00
|
|
|
int user_id;
|
|
|
|
int inviter_id;
|
|
|
|
int date;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_chat {
|
|
|
|
tgl_peer_id_t id;
|
2014-08-13 08:56:55 -04:00
|
|
|
int flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message *last;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *print_title;
|
|
|
|
int structure_version;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_file_location photo_big;
|
|
|
|
struct tgl_file_location photo_small;
|
|
|
|
struct tgl_photo photo;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *title;
|
|
|
|
int users_num;
|
|
|
|
int user_list_size;
|
|
|
|
int user_list_version;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_chat_user *user_list;
|
2014-08-13 08:56:55 -04:00
|
|
|
int date;
|
|
|
|
int version;
|
|
|
|
int admin_id;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
enum tgl_secret_chat_state {
|
2014-08-13 08:56:55 -04:00
|
|
|
sc_none,
|
|
|
|
sc_waiting,
|
|
|
|
sc_request,
|
|
|
|
sc_ok,
|
|
|
|
sc_deleted
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_secret_chat {
|
|
|
|
tgl_peer_id_t id;
|
2014-08-13 08:56:55 -04:00
|
|
|
int flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message *last;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *print_name;
|
|
|
|
int structure_version;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_file_location photo_big;
|
|
|
|
struct tgl_file_location photo_small;
|
|
|
|
struct tgl_photo photo;
|
2014-08-13 08:56:55 -04:00
|
|
|
int user_id;
|
|
|
|
int admin_id;
|
|
|
|
int date;
|
|
|
|
int ttl;
|
|
|
|
int layer;
|
|
|
|
long long access_hash;
|
|
|
|
unsigned char *g_key;
|
|
|
|
unsigned char *nonce;
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
enum tgl_secret_chat_state state;
|
2014-08-13 08:56:55 -04:00
|
|
|
int key[64];
|
|
|
|
long long key_fingerprint;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
typedef union tgl_peer {
|
2014-08-13 08:56:55 -04:00
|
|
|
struct {
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t id;
|
2014-08-13 08:56:55 -04:00
|
|
|
int flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message *last;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *print_name;
|
|
|
|
int structure_version;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_file_location photo_big;
|
|
|
|
struct tgl_file_location photo_small;
|
|
|
|
struct tgl_photo photo;
|
2014-08-13 08:56:55 -04:00
|
|
|
};
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_user user;
|
|
|
|
struct tgl_chat chat;
|
|
|
|
struct tgl_secret_chat encr_chat;
|
|
|
|
} tgl_peer_t;
|
2014-08-13 08:56:55 -04:00
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_video {
|
2014-08-13 08:56:55 -04:00
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int user_id;
|
|
|
|
int date;
|
|
|
|
int size;
|
|
|
|
int dc_id;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo_size thumb;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *caption;
|
|
|
|
int duration;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
char *mime_type;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_audio {
|
2014-08-13 08:56:55 -04:00
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int user_id;
|
|
|
|
int date;
|
|
|
|
int size;
|
|
|
|
int dc_id;
|
|
|
|
int duration;
|
|
|
|
char *mime_type;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_document {
|
2014-08-13 08:56:55 -04:00
|
|
|
long long id;
|
|
|
|
long long access_hash;
|
|
|
|
int user_id;
|
|
|
|
int date;
|
|
|
|
int size;
|
|
|
|
int dc_id;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo_size thumb;
|
2014-08-13 08:56:55 -04:00
|
|
|
char *caption;
|
|
|
|
char *mime_type;
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message_action {
|
2014-08-18 12:39:04 -04:00
|
|
|
enum tgl_message_action_type type;
|
2014-08-13 08:56:55 -04:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
char *title;
|
|
|
|
int user_num;
|
|
|
|
int *users;
|
|
|
|
};
|
|
|
|
char *new_title;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo photo;
|
2014-08-13 08:56:55 -04:00
|
|
|
int user;
|
|
|
|
int ttl;
|
|
|
|
int layer;
|
|
|
|
int read_cnt;
|
|
|
|
int delete_cnt;
|
|
|
|
int screenshot_cnt;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message_media {
|
2014-08-18 12:39:04 -04:00
|
|
|
enum tgl_message_media_type type;
|
2014-08-13 08:56:55 -04:00
|
|
|
union {
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_photo photo;
|
|
|
|
struct tgl_video video;
|
|
|
|
struct tgl_audio audio;
|
|
|
|
struct tgl_document document;
|
|
|
|
struct tgl_geo geo;
|
2014-08-13 08:56:55 -04:00
|
|
|
struct {
|
|
|
|
char *phone;
|
|
|
|
char *first_name;
|
|
|
|
char *last_name;
|
|
|
|
int user_id;
|
|
|
|
};
|
2014-08-13 11:55:16 -04:00
|
|
|
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;
|
2014-08-13 08:56:55 -04:00
|
|
|
struct {
|
|
|
|
void *data;
|
|
|
|
int data_size;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message {
|
|
|
|
struct tgl_message *next_use, *prev_use;
|
|
|
|
struct tgl_message *next, *prev;
|
2014-08-13 08:56:55 -04:00
|
|
|
long long id;
|
|
|
|
int flags;
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t fwd_from_id;
|
2014-08-13 08:56:55 -04:00
|
|
|
int fwd_date;
|
2014-08-13 11:55:16 -04:00
|
|
|
tgl_peer_id_t from_id;
|
|
|
|
tgl_peer_id_t to_id;
|
2014-08-13 08:56:55 -04:00
|
|
|
int out;
|
|
|
|
int unread;
|
|
|
|
int date;
|
|
|
|
int service;
|
|
|
|
union {
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message_action action;
|
2014-08-13 08:56:55 -04:00
|
|
|
struct {
|
|
|
|
char *message;
|
|
|
|
int message_len;
|
2014-08-13 11:55:16 -04:00
|
|
|
struct tgl_message_media media;
|
2014-08-13 08:56:55 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
#endif
|