diff --git a/persistance.c b/persistance.c index ebcaf2f..9fcb23a 100644 --- a/persistance.c +++ b/persistance.c @@ -145,3 +145,15 @@ void persistance_read_forging_key(otrng_global_state_s *otrng_state) { PERSISTANCE_READ(FORGING_KEY_FILE_NAME, otrng_global_state_forging_key_read_from); } + +int persistance_write_expired_client_profile( + otrng_global_state_s *otrng_state) { + PERSISTANCE_WRITE(EXP_CLIENT_PROFILE_FILE_NAME, + otrng_global_state_expired_client_profile_write_to); +} + +void persistance_read_expired_client_profile( + otrng_global_state_s *otrng_state) { + PERSISTANCE_READ(EXP_CLIENT_PROFILE_FILE_NAME, + otrng_global_state_expired_client_profile_read_from); +} diff --git a/persistance.h b/persistance.h index 82ee1ab..0ceaeb8 100644 --- a/persistance.h +++ b/persistance.h @@ -30,6 +30,7 @@ #define PREKEY_PROFILE_FILE_NAME "otr4.prekey_profile" #define PREKEYS_FILE_NAME "otr4.prekey_messages" #define FORGING_KEY_FILE_NAME "otr4.forging_key" +#define EXP_CLIENT_PROFILE_FILE_NAME "otr4.exp_client_profile" int persistance_write_privkey_v4_FILEp(otrng_global_state_s *otrng_state); @@ -51,4 +52,8 @@ int persistance_write_forging_key(otrng_global_state_s *otrng_state); void persistance_read_forging_key(otrng_global_state_s *otrng_state); +int persistance_write_expired_client_profile(otrng_global_state_s *otrng_state); + +void persistance_read_expired_client_profile(otrng_global_state_s *otrng_state); + #endif diff --git a/plugin-all.c b/plugin-all.c index 228bf0b..b74bfe2 100644 --- a/plugin-all.c +++ b/plugin-all.c @@ -138,15 +138,6 @@ static void otrng_plugin_read_instance_tags_FILEp(FILE *instagf) { } } -static void otrng_plugin_read_expired_client_profile(FILE *profiles_filep) { - if (otrng_failed(otrng_global_state_expired_client_profile_read_from( - otrng_state, profiles_filep, - protocol_and_account_to_purple_conversation))) { - // TODO: react better on failure - return; - } -} - static void otrng_plugin_read_expired_prekey_profile(FILE *profiles_filep) { if (otrng_failed(otrng_global_state_expired_prekey_profile_read_from( otrng_state, profiles_filep, @@ -313,42 +304,6 @@ static int otrng_plugin_write_privkey_v3_FILEp(PurpleAccount *account) { return err; } -static int otrng_plugin_write_expired_client_profile_FILEp(void) { -#ifndef WIN32 - mode_t mask; -#endif /* WIN32 */ - FILE *filep; - - gchar *file_name = - g_build_filename(purple_user_dir(), EXP_CLIENT_PROFILE_FILE_NAME, NULL); - if (!file_name) { - fprintf(stderr, _("Out of memory building filenames!\n")); - return -1; - } -#ifndef WIN32 - mask = umask(0077); -#endif /* WIN32 */ - filep = g_fopen(file_name, "w+b"); -#ifndef WIN32 - umask(mask); -#endif /* WIN32 */ - - g_free(file_name); - if (!filep) { - fprintf(stderr, _("Could not write client profile file\n")); - return -1; - } - - int err = 0; - if (otrng_failed( - otrng_global_state_client_profile_write_to(otrng_state, filep))) { - err = -1; - } - fclose(filep); - - return err; -} - static int otrng_plugin_write_expired_prekey_profile_FILEp(void) { #ifndef WIN32 mode_t mask; @@ -401,14 +356,6 @@ void otrng_plugin_create_privkey_v3(const PurpleAccount *account) { otrng_dialog_private_key_wait_done(waithandle); } -void otrng_plugin_write_expired_client_profile(const PurpleAccount *account) { - if (otrng_succeeded(otrng_global_state_generate_client_profile( - otrng_state, purple_account_to_client_id(account)))) { - // TODO: check the return error - otrng_plugin_write_expired_client_profile_FILEp(); - } -} - void otrng_plugin_write_expired_prekey_profile(const PurpleAccount *account) { if (otrng_succeeded(otrng_global_state_generate_prekey_profile( otrng_state, purple_account_to_client_id(account)))) { @@ -1747,12 +1694,6 @@ static void create_privkey_v3(const otrng_client_id_s opdata) { otrng_plugin_create_privkey_v3(client_id_to_purple_account(opdata)); } -static void write_expired_client_profile(struct otrng_client_s *client, - const otrng_client_id_s opdata) { - otrng_plugin_write_expired_client_profile( - client_id_to_purple_account(opdata)); -} - static void write_expired_prekey_profile(struct otrng_client_s *client, const otrng_client_id_s opdata) { otrng_plugin_write_expired_prekey_profile( @@ -1968,7 +1909,6 @@ static otrng_client_callbacks_s *otrng_plugin_client_callbacks_new(void) { cb->create_instag = create_instag_cb; // TODO move to long_term_keys.c cb->create_privkey_v3 = create_privkey_v3; - cb->write_expired_client_profile = write_expired_client_profile; cb->write_expired_prekey_profile = write_expired_prekey_profile; cb->gone_secure = gone_secure_v4; cb->gone_insecure = gone_insecure_v4; @@ -1987,23 +1927,19 @@ static int otrng_plugin_init_userstate(void) { gchar *privkeyfile3 = NULL; gchar *storefile = NULL; gchar *instagfile = NULL; - gchar *exp_client_profile_filename = NULL; gchar *exp_prekey_profile_filename = NULL; privkeyfile3 = g_build_filename(purple_user_dir(), PRIVKEY_FILE_NAME, NULL); storefile = g_build_filename(purple_user_dir(), STORE_FILE_NAME_v4, NULL); instagfile = g_build_filename(purple_user_dir(), INSTAG_FILE_NAME, NULL); - exp_client_profile_filename = - g_build_filename(purple_user_dir(), EXP_CLIENT_PROFILE_FILE_NAME, NULL); exp_prekey_profile_filename = g_build_filename(purple_user_dir(), EXP_PREKEY_PROFILE_FILE_NAME, NULL); if (!privkeyfile3 || !storefile || !instagfile || - !exp_client_profile_filename || !exp_prekey_profile_filename) { + !exp_prekey_profile_filename) { g_free(privkeyfile3); g_free(storefile); g_free(instagfile); - g_free(exp_client_profile_filename); g_free(exp_prekey_profile_filename); return 1; @@ -2012,13 +1948,11 @@ static int otrng_plugin_init_userstate(void) { FILE *priv3f = g_fopen(privkeyfile3, "rb"); FILE *storef = g_fopen(storefile, "rb"); FILE *instagf = g_fopen(instagfile, "rb"); - FILE *exp_client_profile_f = g_fopen(exp_client_profile_filename, "rb"); FILE *exp_prekey_profile_filep = g_fopen(exp_prekey_profile_filename, "rb"); g_free(privkeyfile3); g_free(storefile); g_free(instagfile); - g_free(exp_client_profile_filename); g_free(exp_prekey_profile_filename); otrng_client_callbacks_s *callbacks = otrng_plugin_client_callbacks_new(); @@ -2039,9 +1973,6 @@ static int otrng_plugin_init_userstate(void) { otrng_plugin_read_fingerprints_FILEp(storef); otrng_ui_update_fingerprint(); /* Updates the view */ - /* Read exp client profile */ - otrng_plugin_read_expired_client_profile(exp_client_profile_f); - /* Read prekey profile */ otrng_plugin_read_expired_prekey_profile(exp_prekey_profile_filep); diff --git a/plugin-all.h b/plugin-all.h index f08d845..82bb2ea 100644 --- a/plugin-all.h +++ b/plugin-all.h @@ -39,7 +39,6 @@ #define STORE_FILE_NAME_v4 "otr4.fingerprints" #define SHARED_PREKEY_FILE_NAME "otr4.shared_prekey" -#define EXP_CLIENT_PROFILE_FILE_NAME "otr4.exp_client_profile" #define PREKEY_PROFILE_FILE_NAME "otr4.prekey_profile" #define EXP_PREKEY_PROFILE_FILE_NAME "otr4.exp_prekey_profile" #define PREKEYS_FILE_NAME "otr4.prekey_messages" diff --git a/profiles.c b/profiles.c index a733cf0..aa7050b 100644 --- a/profiles.c +++ b/profiles.c @@ -56,6 +56,14 @@ static void store_prekey_profile(otrng_client_s *client, persistance_write_prekey_profile_FILEp(otrng_state); } +static void store_expired_client_profile(otrng_client_s *client) { + persistance_write_expired_client_profile(otrng_state); +} + +static void load_expired_client_profile(otrng_client_s *client) { + persistance_read_expired_client_profile(otrng_state); +} + void profiles_set_callbacks(otrng_client_callbacks_s *callbacks) { callbacks->create_client_profile = create_client_profile; callbacks->load_client_profile = load_client_profile; @@ -63,4 +71,6 @@ void profiles_set_callbacks(otrng_client_callbacks_s *callbacks) { callbacks->create_prekey_profile = create_prekey_profile; callbacks->load_prekey_profile = load_prekey_profile; callbacks->store_prekey_profile = store_prekey_profile; + callbacks->load_expired_client_profile = load_expired_client_profile; + callbacks->store_expired_client_profile = store_expired_client_profile; }