diff --git a/makefile b/makefile index e22df34..4b540cd 100644 --- a/makefile +++ b/makefile @@ -6,7 +6,7 @@ endif RM=rm -f FIND=find -INCLUDES=-Ilibstrophe -Ideps \ +INCLUDES=-Ilibstrophe -Ideps -Ideps/fmt/include \ $(shell xml2-config --cflags) \ $(shell pkg-config --cflags librnp-0) \ $(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 --shrink-rpath xmpp.so || true -.%.o: %.cpp - @$(CXX) $(CPPFLAGS) -c $< -o $@ - .%.o: %.c @$(CC) $(CFLAGS) -c $< -o $@ -xmpp/.%.o: xmpp/%.c - @$(CC) $(CFLAGS) -c $< -o $@ +.%.o: %.cpp + @$(CXX) $(CPPFLAGS) -c $< -o $@ xmpp/.%.o: xmpp/%.cpp @$(CXX) $(CPPFLAGS) -c $< -o $@ diff --git a/omemo.cpp b/omemo.cpp index 5f4c1ad..b95151f 100644 --- a/omemo.cpp +++ b/omemo.cpp @@ -2,6 +2,7 @@ // 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/. +#include #include #include #include @@ -17,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -2107,28 +2108,21 @@ void omemo__init(struct t_gui_buffer *buffer, struct t_omemo **omemo, return; } - MDB_txn *parentTransaction = NULL; - MDB_txn *transaction = NULL; - if (mdb_txn_begin(new_omemo->db->env, parentTransaction, 0, &transaction)) { - weechat_printf(NULL, "%sxmpp: failed to open lmdb transaction", - weechat_prefix("error")); - return; - } + try { + MDB_txn *parentTransaction = NULL; + lmdb::txn transaction = lmdb::txn::begin(new_omemo->db->env, parentTransaction); - size_t db_name_len = strlen("omemo_") + strlen(account_name); - char *db_name = (char *)malloc(sizeof(char) * (db_name_len + 1)); - 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)) { - weechat_printf(NULL, "%sxmpp: failed to open lmdb database", - weechat_prefix("error")); - return; - } + size_t db_name_len = strlen("omemo_") + strlen(account_name); + char *db_name = (char *)malloc(sizeof(char) * (db_name_len + 1)); + snprintf(db_name, db_name_len+1, "omemo_%s", account_name); + new_omemo->db->dbi_omemo = lmdb::dbi::open(transaction, db_name, MDB_CREATE); - if (mdb_txn_commit(transaction)) { - weechat_printf(NULL, "%sxmpp: failed to close lmdb transaction", - weechat_prefix("error")); + transaction.commit(); + } catch (const std::exception& ex) { + auto format = fmt::format("%sxmpp: lmdb failure {}", ex.what()); + weechat_printf(NULL, format.data(), weechat_prefix("error")); return; - }; + } struct signal_crypto_provider crypto_provider = { .random_func = &cp_random_generator,