mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Add signal-protocol locking
This commit is contained in:
parent
bfbc8edcad
commit
519cf295f3
@ -1,13 +1,24 @@
|
||||
#include <pthread.h>
|
||||
#include <signal/signal_protocol.h>
|
||||
|
||||
#include "config/account.h"
|
||||
#include "ui/ui.h"
|
||||
#include "omemo/omemo.h"
|
||||
#include "omemo/crypto.h"
|
||||
|
||||
static void lock(void *user_data);
|
||||
static void unlock(void *user_data);
|
||||
|
||||
struct omemo_context_t {
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutex_t lock;
|
||||
};
|
||||
|
||||
void
|
||||
omemo_init(ProfAccount *account)
|
||||
{
|
||||
signal_context *global_context;
|
||||
signal_context *signal_ctx;
|
||||
omemo_context *ctx = malloc(sizeof(omemo_context));
|
||||
signal_crypto_provider crypto_provider = {
|
||||
.random_func = omemo_random_func,
|
||||
.hmac_sha256_init_func = omemo_hmac_sha256_init_func,
|
||||
@ -27,14 +38,33 @@ omemo_init(ProfAccount *account)
|
||||
cons_show("Error initializing Omemo crypto");
|
||||
}
|
||||
|
||||
if (signal_context_create(&global_context, NULL) != 0) {
|
||||
pthread_mutexattr_init(&ctx->attr);
|
||||
pthread_mutexattr_settype(&ctx->attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&ctx->lock, &ctx->attr);
|
||||
|
||||
if (signal_context_create(&signal_ctx, ctx) != 0) {
|
||||
cons_show("Error initializing Omemo context");
|
||||
return;
|
||||
}
|
||||
|
||||
if (signal_context_set_crypto_provider(global_context, &crypto_provider) != 0) {
|
||||
if (signal_context_set_crypto_provider(signal_ctx, &crypto_provider) != 0) {
|
||||
cons_show("Error initializing Omemo crypto");
|
||||
return;
|
||||
}
|
||||
//signal_context_set_locking_functions(global_context, lock_function, unlock_function);
|
||||
|
||||
signal_context_set_locking_functions(signal_ctx, lock, unlock);
|
||||
}
|
||||
|
||||
static void
|
||||
lock(void *user_data)
|
||||
{
|
||||
omemo_context *ctx = (omemo_context *)user_data;
|
||||
pthread_mutex_lock(&ctx->lock);
|
||||
}
|
||||
|
||||
static void
|
||||
unlock(void *user_data)
|
||||
{
|
||||
omemo_context *ctx = (omemo_context *)user_data;
|
||||
pthread_mutex_unlock(&ctx->lock);
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include "config/account.h"
|
||||
|
||||
typedef struct omemo_context_t omemo_context;
|
||||
|
||||
void omemo_init(ProfAccount *account);
|
||||
|
Loading…
Reference in New Issue
Block a user