mirror of
https://github.com/bqv/weechat-xmpp/
synced 2024-11-13 19:10:30 +00:00
plugin.c -> cpp
This commit is contained in:
parent
097e6a7bd5
commit
0e2df206f8
95
Makefile
95
Makefile
@ -1,95 +0,0 @@
|
||||
ifdef DEBUG
|
||||
DBGCFLAGS=-fsanitize=address -fsanitize=undefined -fsanitize=leak
|
||||
DBGLDFLAGS=-lasan -lubsan -llsan
|
||||
endif
|
||||
RM=rm -f
|
||||
FIND=find
|
||||
INCLUDES=-Ilibstrophe $(shell xml2-config --cflags) $(shell pkg-config --cflags librnp-0) $(shell pkg-config --cflags libomemo-c)
|
||||
CFLAGS+=$(DBGCFLAGS) -fno-omit-frame-pointer -fPIC -std=gnu99 -gdwarf-4 -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers -D_XOPEN_SOURCE=700 $(INCLUDES)
|
||||
LDFLAGS+=$(DBGLDFLAGS) -shared -g $(DBGCFLAGS)
|
||||
LDLIBS=-lstrophe -lpthread $(shell xml2-config --libs) $(shell pkg-config --libs librnp-0) $(shell pkg-config --libs libomemo-c) -lgcrypt -llmdb
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
|
||||
SRCS=plugin.c \
|
||||
account.c \
|
||||
buffer.c \
|
||||
channel.c \
|
||||
command.c \
|
||||
completion.c \
|
||||
config.c \
|
||||
connection.c \
|
||||
input.c \
|
||||
message.c \
|
||||
omemo.c \
|
||||
pgp.c \
|
||||
user.c \
|
||||
util.c \
|
||||
xmpp/presence.c \
|
||||
xmpp/iq.c \
|
||||
|
||||
DEPS=diff/libdiff.a
|
||||
OBJS=$(subst .c,.o,$(SRCS))
|
||||
|
||||
all: weechat-xmpp
|
||||
weechat-xmpp: $(DEPS) xmpp.so
|
||||
|
||||
xmpp.so: $(OBJS) $(DEPS)
|
||||
$(CC) $(LDFLAGS) -o xmpp.so $(OBJS) $(DEPS) $(LDLIBS)
|
||||
which patchelf >/dev/null && \
|
||||
patchelf --set-rpath $(LIBRARY_PATH):$(shell realpath $(shell dirname $(shell gcc --print-libgcc-file-name))/../../../) xmpp.so && \
|
||||
patchelf --shrink-rpath xmpp.so || true
|
||||
|
||||
diff/libdiff.a:
|
||||
git submodule update --init --recursive
|
||||
cd diff && ./configure
|
||||
$(MAKE) -C diff CFLAGS=-fPIC
|
||||
diff: diff/libdiff.a
|
||||
|
||||
test: xmpp.so
|
||||
env LD_PRELOAD=$(DEBUG) \
|
||||
weechat -a -P 'alias,buflist,irc' -r '/plugin load ./xmpp.so'
|
||||
|
||||
debug: xmpp.so
|
||||
gdb -ex "handle SIGPIPE nostop noprint pass" --args \
|
||||
weechat -a -r '/plugin load ./xmpp.so'
|
||||
|
||||
depend: .depend
|
||||
|
||||
.depend: $(SRCS)
|
||||
$(RM) ./.depend
|
||||
$(CC) $(CFLAGS) -MM $^>>./.depend
|
||||
|
||||
tidy:
|
||||
$(FIND) . -name "*.o" -delete
|
||||
|
||||
clean:
|
||||
$(RM) -f $(OBJS)
|
||||
$(MAKE) -C diff clean || true
|
||||
git submodule foreach --recursive git clean -xfd || true
|
||||
git submodule foreach --recursive git reset --hard || true
|
||||
|
||||
distclean: clean
|
||||
$(RM) *~ .depend
|
||||
|
||||
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: tags cs
|
||||
|
||||
tags:
|
||||
$(CC) $(CFLAGS) -M $(SRCS) | sed -e "s/[\\ ]/\n/g" | sed -e "/^$$/d" -e "/\.o:[ \t]*$$/d" | sort | uniq | ctags -e -L - -f .git/tags -R --c-kinds=+px --c++-kinds=+px --fields=+iaS --extras=+fq
|
||||
|
||||
cs:
|
||||
cscope -RUbq
|
||||
|
||||
include .depend
|
@ -11,7 +11,7 @@
|
||||
#include <libxml/xmlwriter.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "config.h"
|
||||
#include "input.h"
|
||||
|
1
axc
1
axc
@ -1 +0,0 @@
|
||||
Subproject commit 1d4454ea42d39a2064955f2a8de5f89787743f2a
|
2
buffer.c
2
buffer.c
@ -7,7 +7,7 @@
|
||||
#include <strophe.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "account.h"
|
||||
#include "channel.h"
|
||||
#include "buffer.h"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <strophe.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "account.h"
|
||||
#include "omemo.h"
|
||||
#include "user.h"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <errno.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "account.h"
|
||||
#include "user.h"
|
||||
#include "channel.h"
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <strophe.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "config.h"
|
||||
#include "account.h"
|
||||
#include "channel.h"
|
||||
|
2
config.c
2
config.c
@ -8,7 +8,7 @@
|
||||
#include <strophe.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "account.h"
|
||||
#include "config.h"
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <strophe.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "diff/diff.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "config.h"
|
||||
|
2
input.c
2
input.c
@ -7,7 +7,7 @@
|
||||
#include <stdint.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "account.h"
|
||||
#include "channel.h"
|
||||
#include "buffer.h"
|
||||
|
161
makefile
Normal file
161
makefile
Normal file
@ -0,0 +1,161 @@
|
||||
ifdef DEBUG
|
||||
DBGCFLAGS=-fsanitize=address -fsanitize=undefined -fsanitize=leak
|
||||
DBGLDFLAGS=-lasan -lubsan -llsan
|
||||
endif
|
||||
|
||||
RM=rm -f
|
||||
FIND=find
|
||||
|
||||
INCLUDES=-Ilibstrophe \
|
||||
$(shell xml2-config --cflags) \
|
||||
$(shell pkg-config --cflags librnp-0) \
|
||||
$(shell pkg-config --cflags libomemo-c)
|
||||
CFLAGS+=$(DBGCFLAGS) \
|
||||
-fno-omit-frame-pointer -fPIC \
|
||||
-std=gnu99 -gdwarf-4 \
|
||||
-Wall -Wextra -pedantic \
|
||||
-Werror-implicit-function-declaration \
|
||||
-Wno-missing-field-initializers \
|
||||
-D_XOPEN_SOURCE=700 \
|
||||
$(INCLUDES)
|
||||
CPPFLAGS+=$(DBGCFLAGS) \
|
||||
-fno-omit-frame-pointer -fPIC \
|
||||
-std=c++17 -gdwarf-4 \
|
||||
-Wall -Wextra -pedantic \
|
||||
-Wno-missing-field-initializers \
|
||||
$(INCLUDES)
|
||||
# -DDOCTEST_CONFIG_DISABLE
|
||||
LDFLAGS+=$(DBGLDFLAGS) \
|
||||
-shared -gdwarf-4 \
|
||||
$(DBGCFLAGS)
|
||||
LDLIBS=-lstrophe \
|
||||
-lpthread \
|
||||
$(shell xml2-config --libs) \
|
||||
$(shell pkg-config --libs librnp-0) \
|
||||
$(shell pkg-config --libs libomemo-c) \
|
||||
-lgcrypt \
|
||||
-llmdb
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
|
||||
HDRS=plugin.hh \
|
||||
account.h \
|
||||
buffer.h \
|
||||
channel.h \
|
||||
command.h \
|
||||
completion.h \
|
||||
config.h \
|
||||
connection.h \
|
||||
input.h \
|
||||
message.h \
|
||||
omemo.h \
|
||||
pgp.h \
|
||||
user.h \
|
||||
util.h \
|
||||
xmpp/stanza.h \
|
||||
|
||||
SRCS=plugin.cpp \
|
||||
account.c \
|
||||
buffer.c \
|
||||
channel.c \
|
||||
command.c \
|
||||
completion.c \
|
||||
config.c \
|
||||
connection.c \
|
||||
input.c \
|
||||
message.c \
|
||||
omemo.c \
|
||||
pgp.c \
|
||||
user.c \
|
||||
util.c \
|
||||
xmpp/presence.c \
|
||||
xmpp/iq.c \
|
||||
|
||||
DEPS=deps/diff/libdiff.a \
|
||||
|
||||
OBJS=$(patsubst %.cpp,.%.o,$(patsubst %.c,.%.o,$(patsubst xmpp/%.c,xmpp/.%.o,$(SRCS))))
|
||||
|
||||
all:
|
||||
make depend
|
||||
make weechat-xmpp && make test
|
||||
|
||||
weechat-xmpp: $(DEPS) xmpp.so
|
||||
|
||||
xmpp.so: $(OBJS) $(DEPS) $(HDRS)
|
||||
$(CXX) $(LDFLAGS) -o .$@ $(OBJS) $(DEPS) $(LDLIBS)
|
||||
which patchelf >/dev/null && \
|
||||
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 $@
|
||||
|
||||
deps/diff/libdiff.a:
|
||||
git submodule update --init --recursive
|
||||
cd deps/diff && env -u MAKEFLAGS ./configure
|
||||
$(MAKE) -C deps/diff CFLAGS=-fPIC
|
||||
diff: deps/diff/libdiff.a
|
||||
|
||||
tests/run: xmpp.so tests/main.cpp
|
||||
$(CXX) $(CPPFLAGS) -o tests/run xmpp.so tests/main.cpp $(LDLIBS)
|
||||
which patchelf >/dev/null && \
|
||||
patchelf --set-rpath $(PWD):$(LIBRARY_PATH):$(shell realpath $(shell dirname $(shell gcc --print-libgcc-file-name))/../../../) tests/run && \
|
||||
patchelf --shrink-rpath tests/run || true
|
||||
|
||||
test: tests/run
|
||||
tests/run
|
||||
|
||||
debug: xmpp.so
|
||||
env LD_PRELOAD=$(DEBUG) gdb -ex "handle SIGPIPE nostop noprint pass" --args \
|
||||
weechat -a -P 'alias,buflist,exec,irc' -r '/plugin load ./xmpp.so'
|
||||
|
||||
depend: $(SRCS) $(HDRS)
|
||||
$(RM) -f ./.depend
|
||||
echo > ./.depend
|
||||
for src in $(SRCS) ; do \
|
||||
if [[ $$src == *.cpp ]]; then \
|
||||
$(CXX) $(CPPFLAGS) -MM -MMD -MP -MF - \
|
||||
-MT .$${src/.cpp/.o} $$src >> ./.depend ; \
|
||||
elif [[ $$src == *.c ]]; then \
|
||||
$(CC) $(CFLAGS) -MM -MMD -MP -MF - \
|
||||
-MT .$${src/.c/.o} $$src >> ./.depend ; \
|
||||
fi \
|
||||
done
|
||||
sed -i 's/\.\([a-z]*\/\)/\1./' .depend
|
||||
|
||||
tidy:
|
||||
$(FIND) . -name "*.o" -delete
|
||||
|
||||
clean:
|
||||
$(RM) -f $(OBJS)
|
||||
$(MAKE) -C deps/diff clean || true
|
||||
git submodule foreach --recursive git clean -xfd || true
|
||||
git submodule foreach --recursive git reset --hard || true
|
||||
|
||||
distclean: clean
|
||||
$(RM) *~ .depend
|
||||
|
||||
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: all weechat-xmpp test debug depend tidy clean distclean install check
|
||||
|
||||
check:
|
||||
clang-check --analyze *.c *.cc *.cpp
|
||||
|
||||
include .depend
|
@ -10,7 +10,7 @@
|
||||
#include <regex.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "account.h"
|
||||
#include "channel.h"
|
||||
#include "user.h"
|
||||
|
1
omemo
1
omemo
@ -1 +0,0 @@
|
||||
Subproject commit 7667e54d6488aba85701bb4dd6e09fd98bfb3a2c
|
2
omemo.c
2
omemo.c
@ -30,7 +30,7 @@ struct t_pre_key {
|
||||
const char *public_key;
|
||||
};
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "account.h"
|
||||
#include "omemo.h"
|
||||
|
2
pgp.c
2
pgp.c
@ -9,7 +9,7 @@
|
||||
#include <rnp/rnp.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "pgp.h"
|
||||
|
||||
#define RNP_SUCCESS 0
|
||||
|
@ -2,14 +2,15 @@
|
||||
// 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 <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <strophe.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
extern "C" {
|
||||
#include "plugin.hh"
|
||||
#include "config.h"
|
||||
#include "account.h"
|
||||
#include "connection.h"
|
||||
@ -18,7 +19,6 @@
|
||||
#include "buffer.h"
|
||||
#include "completion.h"
|
||||
|
||||
|
||||
WEECHAT_PLUGIN_NAME(WEECHAT_XMPP_PLUGIN_NAME);
|
||||
WEECHAT_PLUGIN_DESCRIPTION(N_("XMPP client protocol"));
|
||||
WEECHAT_PLUGIN_AUTHOR("bqv <weechat@fron.io>");
|
||||
@ -92,3 +92,4 @@ int weechat_plugin_end(struct t_weechat_plugin *plugin)
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
}
|
@ -2,8 +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/.
|
||||
|
||||
#ifndef _WEECHAT_XMPP_PLUGIN_H_
|
||||
#define _WEECHAT_XMPP_PLUGIN_H_
|
||||
#pragma once
|
||||
|
||||
#define weechat_plugin weechat_xmpp_plugin
|
||||
#define WEECHAT_XMPP_PLUGIN_NAME "xmpp"
|
||||
@ -11,5 +10,3 @@
|
||||
#define TIMER_INTERVAL_SEC 0.01
|
||||
|
||||
extern struct t_weechat_plugin *weechat_xmpp_plugin;
|
||||
|
||||
#endif /*WEECHAT_XMPP_PLUGIN_H*/
|
10
tests/account.inl
Normal file
10
tests/account.inl
Normal file
@ -0,0 +1,10 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include "../account.hh"
|
||||
|
||||
TEST_CASE("create account")
|
||||
{
|
||||
weechat::xmpp::account acc("demo");
|
||||
|
||||
CHECK(acc.name == "demo");
|
||||
}
|
10
tests/config.inl
Normal file
10
tests/config.inl
Normal file
@ -0,0 +1,10 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include "../config.hh"
|
||||
|
||||
TEST_CASE("create config")
|
||||
{
|
||||
weechat::xmpp::config cfg;
|
||||
|
||||
CHECK(cfg.name() == weechat::xmpp::config::default_name);
|
||||
}
|
3
tests/main.cpp
Normal file
3
tests/main.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
|
||||
#include <doctest/doctest.h>
|
18
tests/plugin.inl
Normal file
18
tests/plugin.inl
Normal file
@ -0,0 +1,18 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include "../plugin.hh"
|
||||
|
||||
TEST_CASE("placeholder")
|
||||
{
|
||||
int argc = 2;
|
||||
const char *argv[2] = {"a", "b"};
|
||||
|
||||
SUBCASE("takes no arguments")
|
||||
{
|
||||
CHECK(argc != 1);
|
||||
}
|
||||
|
||||
(void) argv;
|
||||
//weechat::plugin c;
|
||||
//CHECK(&c.name() == NULL);
|
||||
}
|
2
user.c
2
user.c
@ -9,7 +9,7 @@
|
||||
#include <strophe.h>
|
||||
#include <weechat/weechat-plugin.h>
|
||||
|
||||
#include "plugin.h"
|
||||
#include "plugin.hh"
|
||||
#include "account.h"
|
||||
#include "user.h"
|
||||
#include "channel.h"
|
||||
|
Loading…
Reference in New Issue
Block a user