1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Ensure signal context is built on connection

We can't keep it between two connection because signal context is
specific to a given account.
This commit is contained in:
Paul Fariello 2019-03-27 17:15:59 +01:00
parent 075d4cf35b
commit 904528b490

View File

@ -72,6 +72,31 @@ void
omemo_init(void)
{
log_info("OMEMO: initialising");
if (omemo_crypto_init() != 0) {
cons_show("Error initializing OMEMO crypto");
}
pthread_mutexattr_init(&omemo_ctx.attr);
pthread_mutexattr_settype(&omemo_ctx.attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&omemo_ctx.lock, &omemo_ctx.attr);
omemo_ctx.fingerprint_ac = autocomplete_new();
}
void
omemo_on_connect(ProfAccount *account)
{
GError *error = NULL;
if (signal_context_create(&omemo_ctx.signal, &omemo_ctx) != 0) {
cons_show("Error initializing OMEMO context");
return;
}
if (signal_context_set_log_function(omemo_ctx.signal, omemo_log) != 0) {
cons_show("Error initializing OMEMO log");
}
signal_crypto_provider crypto_provider = {
.random_func = omemo_random_func,
.hmac_sha256_init_func = omemo_hmac_sha256_init_func,
@ -87,23 +112,6 @@ omemo_init(void)
.user_data = NULL
};
if (omemo_crypto_init() != 0) {
cons_show("Error initializing OMEMO crypto");
}
pthread_mutexattr_init(&omemo_ctx.attr);
pthread_mutexattr_settype(&omemo_ctx.attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&omemo_ctx.lock, &omemo_ctx.attr);
if (signal_context_create(&omemo_ctx.signal, &omemo_ctx) != 0) {
cons_show("Error initializing OMEMO context");
return;
}
if (signal_context_set_log_function(omemo_ctx.signal, omemo_log) != 0) {
cons_show("Error initializing OMEMO log");
}
if (signal_context_set_crypto_provider(omemo_ctx.signal, &crypto_provider) != 0) {
cons_show("Error initializing OMEMO crypto");
return;
@ -166,12 +174,7 @@ omemo_init(void)
omemo_ctx.known_devices = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_free);
omemo_ctx.fingerprint_ac = autocomplete_new();
}
void
omemo_on_connect(ProfAccount *account)
{
GError *error = NULL;
char *omemodir = files_get_data_path(DIR_OMEMO);
GString *basedir = g_string_new(omemodir);
free(omemodir);