move omemo database, to prepare for more DBs

master
bqv 2 years ago
parent 6b52e59a79
commit bf6b5d2e0f
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -820,6 +820,8 @@ config/../channel.hh:
config/../connection.hh: config/../connection.hh:
config/../xmpp/ns.hh: config/../xmpp/ns.hh:
config/../user.hh: config/../user.hh:
data/.omemo.o: data/omemo.cpp
data/.capability.o: data/capability.cpp
xmpp/.presence.o: xmpp/presence.cpp xmpp/stanza.hh xmpp/.presence.o: xmpp/presence.cpp xmpp/stanza.hh
xmpp/stanza.hh: xmpp/stanza.hh:
xmpp/.iq.o: xmpp/iq.cpp xmpp/stanza.hh xmpp/.iq.o: xmpp/iq.cpp xmpp/stanza.hh

@ -133,7 +133,8 @@
* [X] Single media on a line * [X] Single media on a line
* [ ] [#D] Multiple media inline (protocol?) * [ ] [#D] Multiple media inline (protocol?)
* [ ] [#C] Encrypted (pgp/omemo) * [ ] [#C] Encrypted (pgp/omemo)
* [ ] Join and handle events asynchronously * [X] Join and handle events asynchronously
* [ ] Cache caps
* [ ] Handle wide errors gracefully * [ ] Handle wide errors gracefully
* [ ] [#C] Event-driven MUC entrance * [ ] [#C] Event-driven MUC entrance
* [ ] XMPP Ping (xep-199) * [ ] XMPP Ping (xep-199)

@ -0,0 +1,23 @@
#!/usr/bin/env -S gmake clean
# vim: set noexpandtab:
.PHONY: tidy
tidy:
$(FIND) . -name "*.o" -delete
$(FIND) . -name "*.gcno" -delete
$(FIND) . -name "*.gcda" -delete
.PHONY: clean
clean: tidy
$(RM) -f $(OBJS) $(COVS) \
sexp/parser.tab.cc sexp/parser.tab.hh \
sexp/location.hh sexp/position.hh \
sexp/stack.hh sexp/parser.output sexp/parser.o \
sexp/lexer.o sexp/lexer.yy.cc sexp/sexp.a
$(MAKE) -C deps/diff clean || true
git submodule foreach --recursive git clean -xfd || true
git submodule foreach --recursive git reset --hard || true
.PHONY: distclean
distclean: clean
$(RM) *~ .depend

@ -0,0 +1,24 @@
#!/usr/bin/env -S gmake depend
# vim: set noexpandtab:
.PHONY: depend
depend: $(DEPS) $(SRCS) $(HDRS)
echo > ./.depend
for src in $(SRCS) tests/main.cc; do \
dir="$$(dirname $$src)"; \
src="$$(basename $$src)"; \
if [[ $$src == *.cpp ]]; then \
echo "g++ $(CPPFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.cpp/.o} $$dir/$$src >> ./.depend"; \
g++ $(CPPFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.cpp/.o} $$dir/$$src >> ./.depend || true ; \
elif [[ $$src == *.c ]]; then \
echo "gcc $(CFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.c/.o} $$dir/$$src >> ./.depend"; \
gcc $(CFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.c/.o} $$dir/$$src >> ./.depend || true ; \
else continue; \
fi; \
done
include .depend

@ -0,0 +1,25 @@
#!/usr/bin/env -S gmake install
# vim: set noexpandtab:
HOME ?=~
install: xmpp.so
ifeq ($(shell id -u),0)
mkdir -p $(DESTDIR)$(LIBDIR)/weechat/plugins
cp xmpp.so $(DESTDIR)$(LIBDIR)/weechat/plugins/xmpp.so
chmod 644 $(DESTDIR)$(LIBDIR)/weechat/plugins/xmpp.so
else
mkdir -p $(HOME)/.weechat/plugins
cp xmpp.so $(HOME)/.weechat/plugins/xmpp.so
chmod 755 $(HOME)/.weechat/plugins/xmpp.so
endif
release: xmpp.so
cp xmpp.so .xmpp.so.$(SUFFIX)
ln -sf .xmpp.so.$(SUFFIX) .xmpp.so
.xmpp.so.%:
mkdir src$@
objcopy --dump-section .source=/dev/stdout $@ | tar -C src$@ xz
.PHONY: install release .xmpp.so.%

@ -1,5 +1,8 @@
#!/usr/bin/env -S gmake all
# vim: set noexpandtab:
ifdef DEBUG ifdef DEBUG
DBGCFLAGS=-fno-omit-frame-pointer -fsanitize=address #-fsanitize=undefined -fsanitize=leak DBGCFLAGS=-DDEBUG -fno-omit-frame-pointer -fsanitize=address #-fsanitize=undefined -fsanitize=leak
DBGLDFLAGS=-lasan -lrt -lasan #-lubsan -llsan DBGLDFLAGS=-lasan -lrt -lasan #-lubsan -llsan
endif endif
@ -23,7 +26,7 @@ CFLAGS+=$(DBGCFLAGS) \
ifeq ($(CC),clang) ifeq ($(CC),clang)
CFLAGS+= CFLAGS+=
else else
CFLAGS+= -fkeep-inline-functions CFLAGS+=
endif endif
CPPFLAGS+=$(DBGCFLAGS) \ CPPFLAGS+=$(DBGCFLAGS) \
-fno-omit-frame-pointer -fPIC \ -fno-omit-frame-pointer -fPIC \
@ -36,10 +39,10 @@ CPPFLAGS+=$(DBGCFLAGS) \
ifeq ($(CXX),clang) ifeq ($(CXX),clang)
CPPFLAGS+= CPPFLAGS+=
else else
CPPFLAGS+= -fkeep-inline-functions CPPFLAGS+=
endif endif
LDFLAGS+=$(DBGLDFLAGS) \ LDFLAGS+=$(DBGLDFLAGS) \
-gdwarf-4 \ -std=c++23 -gdwarf-4 \
-fuse-ld=mold \ -fuse-ld=mold \
$(DBGCFLAGS) $(DBGCFLAGS)
LDLIBS=-lstrophe \ LDLIBS=-lstrophe \
@ -72,6 +75,8 @@ HDRS=plugin.hh \
config/section.hh \ config/section.hh \
config/account.hh \ config/account.hh \
config/option.hh \ config/option.hh \
data/omemo.hh \
data/capability.hh \
xmpp/stanza.hh \ xmpp/stanza.hh \
xmpp/ns.hh \ xmpp/ns.hh \
xmpp/node.hh \ xmpp/node.hh \
@ -95,6 +100,8 @@ SRCS=plugin.cpp \
config/section.cpp \ config/section.cpp \
config/account.cpp \ config/account.cpp \
config/option.cpp \ config/option.cpp \
data/omemo.cpp \
data/capability.cpp \
xmpp/presence.cpp \ xmpp/presence.cpp \
xmpp/iq.cpp \ xmpp/iq.cpp \
xmpp/node.cpp \ xmpp/node.cpp \
@ -102,47 +109,49 @@ SRCS=plugin.cpp \
DEPS=deps/diff/libdiff.a \ DEPS=deps/diff/libdiff.a \
sexp/sexp.a \ sexp/sexp.a \
OBJS=$(patsubst %.cpp,.%.o,$(patsubst %.c,.%.o,$(patsubst config/%.cpp,config/.%.o,$(patsubst xmpp/%.cpp,xmpp/.%.o,$(SRCS))))) OBJS=$(patsubst %.cpp,.%.o,$(patsubst %.c,.%.o,$(patsubst config/%.cpp,config/.%.o,$(patsubst data/%.cpp,data/.%.o,$(patsubst xmpp/%.cpp,xmpp/.%.o,$(SRCS))))))
COVS=$(patsubst %.cpp,.%.cov.o,$(patsubst config/%.cpp,config/.%.cov.o,$(patsubst xmpp/%.cpp,xmpp/.%.cov.o,$(SRCS)))) COVS=$(patsubst %.cpp,.%.cov.o,$(patsubst config/%.cpp,config/.%.cov.o,$(patsubst data/%.cpp,data/.%.cov.o,$(patsubst xmpp/%.cpp,xmpp/.%.cov.o,$(SRCS)))))
SUFFIX=$(shell date +%s) SUFFIX=$(shell date +%s)
$(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true))
.DEFAULT_GOAL := all
include test.mk
include install.mk
include clean.mk
include depend.mk
.PHONY: all .PHONY: all
all: all: depend
make depend $(MAKE) weechat-xmpp && $(MAKE) test
make weechat-xmpp && make test
.PHONY: weechat-xmpp release .PHONY: weechat-xmpp
weechat-xmpp: $(DEPS) xmpp.so weechat-xmpp: $(DEPS) xmpp.so
release: xmpp.so
cp xmpp.so .xmpp.so.$(SUFFIX)
ln -sf .xmpp.so.$(SUFFIX) .xmpp.so
xmpp.so: $(DEPS) $(OBJS) $(HDRS) xmpp.so: $(DEPS) $(OBJS) $(HDRS)
$(CXX) -shared $(LDFLAGS) -o $@ -Wl,--as-needed $(OBJS) $(DEPS) $(LDLIBS) $(CXX) -shared $(LDFLAGS) -o $@ -Wl,--as-needed $(OBJS) $(DEPS) $(LDLIBS)
git ls-files | xargs ls -d | xargs tar cz | objcopy --add-section .source=/dev/stdin xmpp.so git ls-files | xargs ls -d | xargs tar cz | objcopy --add-section .source=/dev/stdin xmpp.so
#objcopy --dump-section .source=/dev/stdout xmpp.so | tar tz
sexp/sexp.a: sexp/parser.o sexp/lexer.o sexp/driver.o sexp/sexp.a: sexp/parser.o sexp/lexer.o sexp/driver.o
ar -r $@ $^ ar -r $@ $^
sexp/parser.o: sexp/parser.yy sexp/parser.o: sexp/parser.yy
cd sexp && bison -t -d -v parser.yy cd sexp && bison -t -d -v parser.yy
$(CXX) $(CPPFLAGS) -c sexp/parser.tab.cc -o $@ $(CXX) $(CPPFLAGS) -fvisibility=default -c sexp/parser.tab.cc -o $@
sexp/lexer.o: sexp/lexer.l sexp/lexer.o: sexp/lexer.l
cd sexp && flex -d --outfile=lexer.yy.cc lexer.l cd sexp && flex -d --outfile=lexer.yy.cc lexer.l
$(CXX) $(CPPFLAGS) -c sexp/lexer.yy.cc -o $@ $(CXX) $(CPPFLAGS) -fvisibility=default -c sexp/lexer.yy.cc -o $@
sexp/driver.o: sexp/driver.cpp sexp/driver.o: sexp/driver.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@ $(CXX) $(CPPFLAGS) -fvisibility=default -c $< -o $@
.%.o: %.c .%.o: %.c
$(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true))
$(CC) -DGIT_COMMIT=$(GIT_REF) $(CFLAGS) -c $< -o $@ $(CC) -DGIT_COMMIT=$(GIT_REF) $(CFLAGS) -c $< -o $@
.%.o: %.cpp .%.o: %.cpp
$(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true))
$(CXX) -DGIT_COMMIT=$(GIT_REF) $(CPPFLAGS) -c $< -o $@ $(CXX) -DGIT_COMMIT=$(GIT_REF) $(CPPFLAGS) -c $< -o $@
.%.cov.o: %.cpp .%.cov.o: %.cpp
@ -154,6 +163,12 @@ config/.%.o: config/%.cpp
config/.%.cov.o: config/%.cpp config/.%.cov.o: config/%.cpp
@$(CXX) --coverage $(CPPFLAGS) -c $< -o $@ @$(CXX) --coverage $(CPPFLAGS) -c $< -o $@
data/.%.o: data/%.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@
data/.%.cov.o: data/%.cpp
@$(CXX) --coverage $(CPPFLAGS) -c $< -o $@
xmpp/.%.o: xmpp/%.cpp xmpp/.%.o: xmpp/%.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@ $(CXX) $(CPPFLAGS) -c $< -o $@
@ -166,82 +181,3 @@ deps/diff/libdiff.a:
cd deps/diff && env -u MAKEFLAGS ./configure cd deps/diff && env -u MAKEFLAGS ./configure
$(MAKE) -C deps/diff CFLAGS=-fPIC $(MAKE) -C deps/diff CFLAGS=-fPIC
diff: deps/diff/libdiff.a diff: deps/diff/libdiff.a
tests/xmpp.cov.so: $(COVS) $(DEPS) $(HDRS)
$(CXX) --coverage -shared $(LDFLAGS) -o tests/xmpp.cov.so -Wl,--as-needed $(DEPS) $(LDLIBS) $(COVS)
tests/run: $(COVS) tests/main.cc tests/xmpp.cov.so $(wildcard tests/*.inl)
env --chdir tests $(CXX) $(CPPFLAGS) $(LDFLAGS) -o run -Wl,--as-needed ./xmpp.cov.so main.cc $(patsubst %,../%,$(DEPS)) $(LDLIBS) -lstdc++
.PHONY: test
test: tests/run
env --chdir tests ./run -sm
.PHONY: coverage
coverage: tests/run
gcovr --txt -s
.PHONY: debug
debug: xmpp.so
env LD_PRELOAD=$(DEBUG) gdb -ex "handle SIGPIPE nostop noprint pass" --args \
weechat -a -P 'alias,buflist,exec,irc,relay' -r '/plugin load ./xmpp.so'
.PHONY: depend
depend: $(DEPS) $(SRCS) $(HDRS)
$(RM) -f ./.depend
echo > ./.depend
for src in $(SRCS) tests/main.cc; do \
dir="$$(dirname $$src)"; \
src="$$(basename $$src)"; \
if [[ $$src == *.cpp ]]; then \
echo "g++ $(CPPFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.cpp/.o} $$dir/$$src >> ./.depend"; \
g++ $(CPPFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.cpp/.o} $$dir/$$src >> ./.depend || true ; \
elif [[ $$src == *.c ]]; then \
echo "gcc $(CFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.c/.o} $$dir/$$src >> ./.depend"; \
gcc $(CFLAGS) -MM -MMD -MP -MF - \
-MT $$dir/.$${src/.c/.o} $$dir/$$src >> ./.depend || true ; \
else continue; \
fi; \
done
.PHONY: tidy
tidy:
$(FIND) . -name "*.o" -delete
$(FIND) . -name "*.gcno" -delete
$(FIND) . -name "*.gcda" -delete
.PHONY: clean
clean: tidy
$(RM) -f $(OBJS) $(COVS) \
sexp/parser.tab.cc sexp/parser.tab.hh \
sexp/location.hh sexp/position.hh \
sexp/stack.hh sexp/parser.output sexp/parser.o \
sexp/lexer.o sexp/lexer.yy.cc sexp/sexp.a
$(MAKE) -C deps/diff clean || true
git submodule foreach --recursive git clean -xfd || true
git submodule foreach --recursive git reset --hard || true
.PHONY: distclean
distclean: clean
$(RM) *~ .depend
.PHONY: install
install: xmpp.so
ifeq ($(shell id -u),0)
mkdir -p $(DESTDIR)$(LIBDIR)/weechat/plugins
cp xmpp.so $(DESTDIR)$(LIBDIR)/weechat/plugins/xmpp.so
chmod 644 $(DESTDIR)$(LIBDIR)/weechat/plugins/xmpp.so
else
mkdir -p ~/.weechat/plugins
cp xmpp.so ~/.weechat/plugins/xmpp.so
chmod 755 ~/.weechat/plugins/xmpp.so
endif
.PHONY: check
check:
clang-check --analyze *.c *.cc *.cpp
include .depend

@ -16,6 +16,7 @@
#include <limits.h> #include <limits.h>
#include <optional> #include <optional>
#include <ranges> #include <ranges>
#include <filesystem>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
@ -1906,9 +1907,12 @@ void omemo::init(struct t_gui_buffer *buffer, const char *account_name)
try { try {
omemo->db_path = std::shared_ptr<char>( omemo->db_path = std::shared_ptr<char>(
weechat_string_eval_expression("${weechat_data_dir}/xmpp.omemo.db", weechat_string_eval_expression("${weechat_data_dir}/xmpp/omemo.db",
NULL, NULL, NULL), NULL, NULL, NULL),
&free).get(); &free).get();
std::filesystem::path path(omemo->db_path.data());
std::filesystem::create_directories(
std::filesystem::path(omemo->db_path.data()).parent_path());
omemo->db_env = lmdb::env::create(); omemo->db_env = lmdb::env::create();
omemo->db_env.set_max_dbs(50); omemo->db_env.set_max_dbs(50);

@ -0,0 +1,25 @@
#!/usr/bin/env -S gmake test coverage
# vim: set noexpandtab:
.PHONY: debug
debug: xmpp.so
env LD_PRELOAD=$(DEBUG) gdb -ex "handle SIGPIPE nostop noprint pass" --args \
weechat -a -P 'alias,buflist,exec,irc,relay' -r '/plugin load ./xmpp.so'
tests/xmpp.cov.so: $(COVS) $(DEPS) $(HDRS)
$(CXX) --coverage -shared $(LDFLAGS) -o tests/xmpp.cov.so -Wl,--as-needed $(DEPS) $(LDLIBS) $(COVS)
tests/run: $(COVS) tests/main.cc tests/xmpp.cov.so $(wildcard tests/*.inl)
cd tests && $(CXX) $(CPPFLAGS) $(LDFLAGS) -o run $$PWD/xmpp.cov.so main.cc $(patsubst %,../%,$(DEPS)) $(LDLIBS)
.PHONY: test
test: tests/run
cd tests && ./run -sm
.PHONY: coverage
coverage: tests/run
gcovr --txt -s
.PHONY: check
check:
clang-check --analyze *.c *.cc *.cpp

@ -10,6 +10,8 @@
#include <iterator> #include <iterator>
#include <regex> #include <regex>
#include <exception> #include <exception>
#include <sys/types.h>
#include <sys/wait.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "../deps/fdstream.hpp" #include "../deps/fdstream.hpp"
#include "../plugin.hh" #include "../plugin.hh"

Loading…
Cancel
Save