switch to lmdb++

master
Tony Olagbaiye 3 years ago
parent 2482fd4691
commit 5011ae9fa2
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -6,7 +6,7 @@ endif
RM=rm -f RM=rm -f
FIND=find FIND=find
INCLUDES=-Ilibstrophe -Ideps \ INCLUDES=-Ilibstrophe -Ideps -Ideps/fmt/include \
$(shell xml2-config --cflags) \ $(shell xml2-config --cflags) \
$(shell pkg-config --cflags librnp-0) \ $(shell pkg-config --cflags librnp-0) \
$(shell pkg-config --cflags libomemo-c) $(shell pkg-config --cflags libomemo-c)
@ -88,14 +88,11 @@ xmpp.so: $(OBJS) $(DEPS) $(HDRS)
patchelf --set-rpath $(LIBRARY_PATH):$(shell realpath $(shell dirname $(shell gcc --print-libgcc-file-name))/../../../) xmpp.so && \ patchelf --set-rpath $(LIBRARY_PATH):$(shell realpath $(shell dirname $(shell gcc --print-libgcc-file-name))/../../../) xmpp.so && \
patchelf --shrink-rpath xmpp.so || true patchelf --shrink-rpath xmpp.so || true
.%.o: %.cpp
@$(CXX) $(CPPFLAGS) -c $< -o $@
.%.o: %.c .%.o: %.c
@$(CC) $(CFLAGS) -c $< -o $@ @$(CC) $(CFLAGS) -c $< -o $@
xmpp/.%.o: xmpp/%.c .%.o: %.cpp
@$(CC) $(CFLAGS) -c $< -o $@ @$(CXX) $(CPPFLAGS) -c $< -o $@
xmpp/.%.o: xmpp/%.cpp xmpp/.%.o: xmpp/%.cpp
@$(CXX) $(CPPFLAGS) -c $< -o $@ @$(CXX) $(CPPFLAGS) -c $< -o $@

@ -2,6 +2,7 @@
// License, version 2.0. If a copy of the MPL was not distributed with this // License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <fmt/core.h>
#include <memory> #include <memory>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -17,7 +18,7 @@
#include <session_pre_key.h> #include <session_pre_key.h>
#include <protocol.h> #include <protocol.h>
#include <curve.h> #include <curve.h>
#include <lmdb.h> #include <lmdb++.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
@ -2107,28 +2108,21 @@ void omemo__init(struct t_gui_buffer *buffer, struct t_omemo **omemo,
return; return;
} }
try {
MDB_txn *parentTransaction = NULL; MDB_txn *parentTransaction = NULL;
MDB_txn *transaction = NULL; lmdb::txn transaction = lmdb::txn::begin(new_omemo->db->env, parentTransaction);
if (mdb_txn_begin(new_omemo->db->env, parentTransaction, 0, &transaction)) {
weechat_printf(NULL, "%sxmpp: failed to open lmdb transaction",
weechat_prefix("error"));
return;
}
size_t db_name_len = strlen("omemo_") + strlen(account_name); size_t db_name_len = strlen("omemo_") + strlen(account_name);
char *db_name = (char *)malloc(sizeof(char) * (db_name_len + 1)); char *db_name = (char *)malloc(sizeof(char) * (db_name_len + 1));
snprintf(db_name, db_name_len+1, "omemo_%s", account_name); snprintf(db_name, db_name_len+1, "omemo_%s", account_name);
if (mdb_dbi_open(transaction, db_name, MDB_CREATE, &new_omemo->db->dbi_omemo)) { new_omemo->db->dbi_omemo = lmdb::dbi::open(transaction, db_name, MDB_CREATE);
weechat_printf(NULL, "%sxmpp: failed to open lmdb database",
weechat_prefix("error"));
return;
}
if (mdb_txn_commit(transaction)) { transaction.commit();
weechat_printf(NULL, "%sxmpp: failed to close lmdb transaction", } catch (const std::exception& ex) {
weechat_prefix("error")); auto format = fmt::format("%sxmpp: lmdb failure {}", ex.what());
weechat_printf(NULL, format.data(), weechat_prefix("error"));
return; return;
}; }
struct signal_crypto_provider crypto_provider = { struct signal_crypto_provider crypto_provider = {
.random_func = &cp_random_generator, .random_func = &cp_random_generator,

Loading…
Cancel
Save