diff --git a/loop.c b/loop.c index 392e2dd..2f6d251 100644 --- a/loop.c +++ b/loop.c @@ -237,7 +237,6 @@ void write_state_file (struct protocol_state *state, const char* filename) { close (state_file_fd); } -// TODO: Refactor void read_secret_chat_file (struct telegram *instance, const char *file) { struct binlog *bl = instance->bl; diff --git a/loop.h b/loop.h index a6cdfa0..a48e34c 100644 --- a/loop.h +++ b/loop.h @@ -73,4 +73,7 @@ struct authorization_state read_auth_file (const char *filename); void write_state_file (struct protocol_state *state, const char *filename); struct protocol_state read_state_file (const char *filename); +void write_secret_chat_file (struct telegram *instance, const char *filename); +void read_secret_chat_file (struct telegram *instance, const char *filename); + #endif diff --git a/queries.c b/queries.c index 2875870..06ee03a 100644 --- a/queries.c +++ b/queries.c @@ -2587,7 +2587,7 @@ void do_send_create_encr_chat (struct telegram *instance, void *x, unsigned char out_int (mtp, get_peer_id (E->id)); out_cstring (mtp, instance->g_a, 256); // TODO: properly... - write_secret_chat_file (instance, "/home/dev-jessie/.telegram/+4915736384600/secret"); + write_secret_chat_file (instance, instance->secret_path); BN_clear_free (g); BN_clear_free (p); diff --git a/structures.c b/structures.c index d887814..fe66f45 100644 --- a/structures.c +++ b/structures.c @@ -309,8 +309,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U } bl_do_encr_chat_delete (mtp->bl, mtp, U); - // TODO: properly - write_secret_chat_file (instance, "/home/dev-jessie/.telegram/+4915736384600/secret"); + write_secret_chat_file (instance, instance->secret_path); return; } @@ -359,7 +358,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U } bl_do_encr_chat_requested (mtp->bl, mtp, U, access_hash, date, admin_id, user_id, (void *)g_key, (void *)nonce); - write_secret_chat_file (instance, "/home/dev-jessie/.telegram/+4915736384600/secret"); + write_secret_chat_file (instance, instance->secret_path); } else { bl_do_set_encr_chat_access_hash (mtp->bl, mtp, U, fetch_long (mtp)); bl_do_set_encr_chat_date (mtp->bl, mtp, U, fetch_int (mtp)); @@ -373,7 +372,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U } if (x == CODE_encrypted_chat_waiting) { bl_do_set_encr_chat_state (mtp->bl, mtp, U, sc_waiting); - write_secret_chat_file (instance, "/home/dev-jessie/.telegram/+4915736384600/secret"); + write_secret_chat_file (instance, instance->secret_path); return; // We needed only access hash from here } @@ -405,7 +404,7 @@ void fetch_encrypted_chat (struct mtproto_connection *mtp, struct secret_chat *U } bl_do_encr_chat_accepted (mtp->bl, mtp, U, (void *)g_key, (void *)nonce, fetch_long (mtp)); } - write_secret_chat_file (instance, "/home/dev-jessie/.telegram/+4915736384600/secret"); + write_secret_chat_file (instance, instance->secret_path); } void fetch_notify_settings (struct mtproto_connection *mtp); diff --git a/telegram.c b/telegram.c index 0ac15e5..99492f5 100755 --- a/telegram.c +++ b/telegram.c @@ -12,6 +12,7 @@ #include "tools.h" #include "mtproto-client.h" #include "binlog.h" +#include "loop.h" @@ -66,7 +67,7 @@ void event_update_user_typing (struct telegram *instance, void *peer) */ char *telegram_get_config(struct telegram *instance, char *config) { - return g_strdup_printf("%s/%s", instance->config->base_config_path, config); + return g_strdup_printf("%s/%s", instance->config_path, config); } /** @@ -299,6 +300,7 @@ void telegram_restore_session(struct telegram *instance) g_mkdir_with_parents(instance->config_path, 0700); instance->auth = read_auth_file(instance->auth_path); instance->proto = read_state_file(instance->state_path); + read_secret_chat_file (instance, instance->secret_path); } /** @@ -308,8 +310,10 @@ void telegram_store_session(struct telegram *instance) { assure_file_exists(instance->config_path, "auth"); assure_file_exists(instance->config_path, "state"); + assure_file_exists(instance->config_path, "secret"); write_auth_file(&instance->auth, instance->auth_path); write_state_file(&instance->proto, instance->state_path); + write_secret_chat_file(instance, instance->state_path); } void on_authorized(struct mtproto_connection *c, void* data);