write secret chat file into user-specific directory and fix config path creation

This commit is contained in:
mjentsch 2014-09-06 01:04:57 +02:00
parent 40485fabdc
commit ce96381ef9
5 changed files with 13 additions and 8 deletions

1
loop.c
View file

@ -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;

3
loop.h
View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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);