restore lost code

v2
Tony Olagbaiye 3 years ago
parent 5377445423
commit e0a3aace3a
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -1,6 +1,6 @@
# -*- mode: sh; -*- # -*- mode: sh; -*-
export CC=gcc CXX=g++ export CC=gcc CXX="g++ -fdiagnostics-color=always"
# Miscellaneous packages. # Miscellaneous packages.
ENVIRONMENTS=( ENVIRONMENTS=(

@ -28,57 +28,62 @@ LDFLAGS+=$(DBGLDFLAGS) \
-shared -gdwarf-4 \ -shared -gdwarf-4 \
$(DBGCFLAGS) $(DBGCFLAGS)
LDLIBS=-lstrophe \ LDLIBS=-lstrophe \
-lpthread \ -lpthread \
$(shell xml2-config --libs) \ $(shell xml2-config --libs) \
$(shell pkg-config --libs librnp-0) \ $(shell pkg-config --libs librnp-0) \
$(shell pkg-config --libs libsignal-protocol-c) \ $(shell pkg-config --libs libsignal-protocol-c) \
-lgcrypt \ -lgcrypt \
-llmdb -llmdb
PREFIX ?= /usr/local PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib LIBDIR ?= $(PREFIX)/lib
HDRS=plugin.hh \ HDRS=plugin.hh \
plugin.h \ plugin.h \
account.h \ strophe.hh \
buffer.h \ account.h \
channel.h \ buffer.h \
command.h \ channel.h \
completion.h \ command.h \
config.h \ completion.h \
connection.h \ config.h \
input.h \ connection.h \
message.h \ input.h \
omemo.h \ message.h \
pgp.h \ omemo.h \
user.h \ pgp.h \
util.h \ user.h \
xmpp/stanza.h \ util.h \
xmpp/stanza.h \
SRCS=plugin.cpp \ SRCS=plugin.cpp \
account.c \ strophe.cpp \
buffer.c \ account.c \
channel.c \ buffer.c \
command.c \ channel.c \
completion.c \ command.c \
config.c \ completion.c \
connection.c \ config.c \
input.c \ connection.c \
message.c \ input.c \
omemo.c \ message.c \
pgp.c \ omemo.c \
user.c \ pgp.c \
util.c \ user.c \
xmpp/presence.c \ util.c \
xmpp/iq.c \ xmpp/presence.c \
xmpp/iq.c \
DEPS=deps/diff/libdiff.a \ DEPS=deps/diff/libdiff.a \
TSTS=$(patsubst %.cpp,tests/%.cc,$(SRCS)) tests/main.cc TSTS=$(patsubst %.cpp,tests/%.cc,$(filter %.cpp,$(SRCS))) tests/main.cc
OBJS=$(patsubst %.cpp,.%.o,$(patsubst %.c,.%.o,$(patsubst xmpp/%.c,xmpp/.%.o,$(SRCS)))) OBJS=$(patsubst %.cpp,.%.o,$(patsubst %.c,.%.o,$(patsubst xmpp/%.c,xmpp/.%.o,$(SRCS))))
JOBS=$(patsubst tests/%.cc,tests/.%.o,$(TSTS)) JOBS=$(patsubst tests/%.cc,tests/.%.o,$(TSTS))
all: weechat-xmpp all:
make depend
make weechat-xmpp && make test
weechat-xmpp: $(DEPS) xmpp.so weechat-xmpp: $(DEPS) xmpp.so
xmpp.so: $(OBJS) $(DEPS) $(HDRS) xmpp.so: $(OBJS) $(DEPS) $(HDRS)
@ -120,7 +125,7 @@ debug: xmpp.so
depend: .depend depend: .depend
.depend: $(SRCS) .depend: $(SRCS) $(HDRS) $(TSTS)
$(RM) ./.depend $(RM) ./.depend
$(CXX) $(CPPFLAGS) -MM $^>>./.depend $(CXX) $(CPPFLAGS) -MM $^>>./.depend
@ -147,7 +152,7 @@ else
chmod 755 ~/.weechat/plugins/xmpp.so chmod 755 ~/.weechat/plugins/xmpp.so
endif endif
.PHONY: check .PHONY: all weechat-xmpp test debug depend tidy clean distclean install check
check: check:
clang-check --analyze *.c *.cc *.cpp clang-check --analyze *.c *.cc *.cpp

@ -9,7 +9,6 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <libxml/xmlwriter.h> #include <libxml/xmlwriter.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "config.h" #include "config.h"

@ -4,7 +4,6 @@
#include <string.h> #include <string.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "account.h" #include "account.h"

@ -8,7 +8,6 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "omemo.h" #include "omemo.h"
@ -901,16 +900,17 @@ struct t_channel_member *channel__add_member(struct t_account *account,
user->profile.pgp_id ? user->profile.pgp_id : "", user->profile.pgp_id ? user->profile.pgp_id : "",
user->profile.pgp_id ? weechat_color("reset") : ""); user->profile.pgp_id ? weechat_color("reset") : "");
else else
weechat_printf_date_tags(channel->buffer, 0, "xmpp_presence,enter,log4", "%s%s (%s) %s%s%s%s %s%s%s%s%s%s%s%s%s", weechat_printf_date_tags(channel->buffer, 0, "xmpp_presence,enter,log4", "%s%s (%s) %s%s%s%s%s %s%s%s%s%s%s%s%s%s",
weechat_prefix("join"), weechat_prefix("join"),
jid_resource ? user__as_prefix_raw(account, jid_bare) : "You", user__as_prefix_raw(account, jid_bare),
jid_resource ? jid_resource : user__as_prefix_raw(account, jid_bare), jid_resource,
user->profile.status ? "is " : "", user->profile.status ? "is " : "",
weechat_color("irc.color.message_join"), weechat_color("irc.color.message_join"),
user->profile.status ? user->profile.status : (user->profile.idle ? "idle" : "entered"), user->profile.status ? user->profile.status : "entered",
weechat_color("reset"), user->profile.idle ? " (idle since " : "",
user->profile.idle ? "since " : "",
user->profile.idle ? user->profile.idle : "", user->profile.idle ? user->profile.idle : "",
user->profile.idle ? ")" : "",
weechat_color("reset"),
user->profile.status_text ? " [" : "", user->profile.status_text ? " [" : "",
user->profile.status_text ? user->profile.status_text : "", user->profile.status_text ? user->profile.status_text : "",
user->profile.status_text ? "]" : "", user->profile.status_text ? "]" : "",

@ -7,7 +7,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
//#include "oauth.h" //#include "oauth.h"

@ -6,7 +6,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "config.h" #include "config.h"

@ -5,7 +5,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "account.h" #include "account.h"

@ -9,7 +9,6 @@
#include <string.h> #include <string.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "deps/diff/diff.h" #include "deps/diff/diff.h"
@ -147,7 +146,16 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
? from_res : from); ? from_res : from);
user->profile.status_text = status ? strdup(status) : NULL; user->profile.status_text = status ? strdup(status) : NULL;
user->profile.status = show ? strdup(show__text) : NULL; user->profile.status = show ? strdup(show__text) : NULL;
user->profile.idle = idle ? strdup(idle__since) : NULL; if (idle)
{
struct tm *since = {0};
strptime(idle__since, "%FT%T", since);
char timestamp[256] = {0};
strftime(timestamp, sizeof(timestamp), "%T", since);
user->profile.idle = strdup(idle__since);
}
else
user->profile.idle = NULL;
user->is_away = show ? weechat_strcasecmp(show__text, "away") == 0 : 0; user->is_away = show ? weechat_strcasecmp(show__text, "away") == 0 : 0;
user->profile.role = role ? strdup(role) : NULL; user->profile.role = role ? strdup(role) : NULL;
user->profile.affiliation = affiliation && strcmp(affiliation, "none") != 0 user->profile.affiliation = affiliation && strcmp(affiliation, "none") != 0
@ -176,7 +184,16 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
? from_res : from); ? from_res : from);
user->profile.status_text = status ? strdup(status) : NULL; user->profile.status_text = status ? strdup(status) : NULL;
user->profile.status = show ? strdup(show__text) : NULL; user->profile.status = show ? strdup(show__text) : NULL;
user->profile.idle = idle ? strdup(idle__since) : NULL; if (idle)
{
struct tm *since = {0};
strptime(idle__since, "%FT%T", since);
char timestamp[256] = {0};
strftime(timestamp, sizeof(timestamp), "%T", since);
user->profile.idle = strdup(idle__since);
}
else
user->profile.idle = NULL;
user->is_away = show ? weechat_strcasecmp(show__text, "away") == 0 : 0; user->is_away = show ? weechat_strcasecmp(show__text, "away") == 0 : 0;
user->profile.role = role ? strdup(role) : NULL; user->profile.role = role ? strdup(role) : NULL;
user->profile.affiliation = affiliation && strcmp(affiliation, "none") != 0 user->profile.affiliation = affiliation && strcmp(affiliation, "none") != 0

@ -4,7 +4,6 @@
#include <strophe.h> #include <strophe.h>
#include <stdlib.h> #include <stdlib.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "account.h" #include "account.h"

@ -7,7 +7,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <regex.h> #include <regex.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "account.h" #include "account.h"

@ -12,7 +12,6 @@
#include <curve.h> #include <curve.h>
#include <lmdb.h> #include <lmdb.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
struct t_omemo_db { struct t_omemo_db {
MDB_env *env; MDB_env *env;

@ -7,7 +7,6 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <rnp/rnp.h> #include <rnp/rnp.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "pgp.h" #include "pgp.h"

@ -3,17 +3,13 @@
// 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 "plugin.hh" #include "plugin.hh"
#include "strophe.hh"
#define WEECHAT_XMPP_PLUGIN_NAME "xmpp" #define WEECHAT_XMPP_PLUGIN_NAME "xmpp"
#define WEECHAT_XMPP_PLUGIN_VERSION "0.2.0" #define WEECHAT_XMPP_PLUGIN_VERSION "0.2.0"
namespace c { namespace c {
extern "C" { extern "C" {
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <strophe.h>
#include "plugin.h" #include "plugin.h"
#include "config.h" #include "config.h"
#include "account.h" #include "account.h"
@ -24,101 +20,91 @@ namespace c {
#include "completion.h" #include "completion.h"
struct t_weechat_plugin *weechat_xmpp_plugin() { struct t_weechat_plugin *weechat_xmpp_plugin() {
return weechat_plugin; return (struct t_weechat_plugin*)weechat::globals::plugin;
}; };
const char *weechat_xmpp_plugin_name() { const char *weechat_xmpp_plugin_name() {
return weechat::plugin::instance.name().data(); return WEECHAT_XMPP_PLUGIN_NAME;
}; };
const char *weechat_xmpp_plugin_version() { const char *weechat_xmpp_plugin_version() {
return weechat::plugin::instance.version().data(); return WEECHAT_XMPP_PLUGIN_VERSION;
}; };
} }
}
#define TIMER_INTERVAL_SEC 0.01 namespace weechat {
plugin::plugin()
struct t_hook *weechat_xmpp_process_timer = NULL; : std::reference_wrapper<weechat_plugin>(
// try not to think about it too hard
struct t_gui_bar_item *weechat_xmpp_typing_bar_item = NULL; *(weechat_plugin*)nullptr) {
}
bool weechat_plugin_init() bool plugin::init(std::vector<std::string>) {
{ if (!c::config__init())
if (!config__init()) {
weechat::printf(nullptr, "%s: Error during config init",
globals::plugin->name);
return false; return false;
}
config__read(); c::config__read();
connection__init(); c::connection__init();
command__init(); c::command__init();
completion__init(); c::completion__init();
weechat_xmpp_process_timer = weechat_hook_timer(TIMER_INTERVAL_SEC * 1000, 0, 0, globals::process_timer =
&account__timer_cb, weechat::hook_timer(plugin::timer_interval_sec * 1000, 0, 0,
NULL, NULL); &c::account__timer_cb, nullptr, nullptr);
if (!weechat_bar_search("typing")) if (!weechat::bar_search("typing"))
{ {
weechat_bar_new("typing", "off", "400", "window", "${typing}", weechat::bar_new("typing", "off", "400", "window", "${typing}",
"bottom", "horizontal", "vertical", "bottom", "horizontal", "vertical",
"1", "1", "default", "default", "default", "default", "1", "1", "default", "default", "default", "default",
"off", "xmpp_typing"); "off", "xmpp_typing");
} }
weechat_xmpp_typing_bar_item = weechat_bar_item_new("xmpp_typing", globals::typing_bar_item =
&buffer__typing_bar_cb, weechat::bar_item_new("xmpp_typing",
NULL, NULL); (char* (*)(const void*, void*,
t_gui_bar_item*, t_gui_window*,
t_gui_buffer*, t_hashtable*))(&c::buffer__typing_bar_cb),
nullptr, nullptr);
weechat_hook_signal("input_text_changed", &input__text_changed_cb, NULL, NULL); weechat::hook_signal("input_text_changed", &c::input__text_changed_cb, nullptr, nullptr);
return true; return true;
} }
void weechat_plugin_end() bool plugin::end() {
{ if (globals::typing_bar_item)
if (weechat_xmpp_typing_bar_item) weechat::bar_item_remove(globals::typing_bar_item);
weechat_bar_item_remove(weechat_xmpp_typing_bar_item);
if (weechat_xmpp_process_timer)
weechat_unhook(weechat_xmpp_process_timer);
config__write(); if (globals::process_timer)
weechat::unhook(globals::process_timer);
account__disconnect_all(); c::config__write();
account__free_all(); c::account__disconnect_all();
xmpp_shutdown(); c::account__free_all();
}
}
namespace weechat { xmpp::shutdown();
plugin::plugin() {
}
plugin::plugin(plugin_ptr ptr) return true;
: plugin_ptr(std::move(ptr)) {
this->m_name = WEECHAT_XMPP_PLUGIN_NAME;
this->m_version = WEECHAT_XMPP_PLUGIN_VERSION;
} }
plugin::plugin(struct t_weechat_plugin *ptr) std::string_view plugin::name() const {
: plugin(std::move(weechat::plugin_ptr( return plugin_get_name(*this);
ptr, [this] (struct t_weechat_plugin *) { }
))) {
} }
bool plugin::init(std::vector<std::string>) { struct t_weechat_plugin* globals::plugin = nullptr;
weechat_printf(nullptr, "%s: It works!", this->name().data());
return c::weechat_plugin_init();
}
bool plugin::end() { hook* globals::process_timer = nullptr;
c::weechat_plugin_end();
return true;
}
plugin plugin::instance; gui_bar_item* globals::typing_bar_item = nullptr;
} }
extern "C" { extern "C" {
@ -129,15 +115,15 @@ extern "C" {
WEECHAT_PLUGIN_LICENSE("MPL2"); WEECHAT_PLUGIN_LICENSE("MPL2");
WEECHAT_PLUGIN_PRIORITY(5500); WEECHAT_PLUGIN_PRIORITY(5500);
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[]) weechat::rc weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
{ {
weechat::plugin::instance = std::move(weechat::plugin(plugin)); weechat::globals::plugin = (weechat::weechat_plugin*)plugin;
std::vector<std::string> args(argv, argv+argc); std::vector<std::string> args(argv, argv+argc);
return weechat::plugin::instance.init(args) ? WEECHAT_RC_OK : WEECHAT_RC_ERROR; return weechat::plugin::init(args) ? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
} }
int weechat_plugin_end(struct t_weechat_plugin *) weechat::rc weechat_plugin_end(struct t_weechat_plugin *)
{ {
return weechat::plugin::instance.end() ? WEECHAT_RC_OK : WEECHAT_RC_ERROR; return weechat::plugin::end() ? WEECHAT_RC_OK : WEECHAT_RC_ERROR;
} }
} }

@ -6,6 +6,7 @@
#define _WEECHAT_XMPP_PLUGIN_H_ #define _WEECHAT_XMPP_PLUGIN_H_
#ifndef __cplusplus #ifndef __cplusplus
#include <weechat/weechat-plugin.h>
#define weechat_plugin weechat_xmpp_plugin() #define weechat_plugin weechat_xmpp_plugin()
#define WEECHAT_XMPP_PLUGIN_NAME weechat_xmpp_plugin_name() #define WEECHAT_XMPP_PLUGIN_NAME weechat_xmpp_plugin_name()
#define WEECHAT_XMPP_PLUGIN_VERSION weechat_xmpp_plugin_version() #define WEECHAT_XMPP_PLUGIN_VERSION weechat_xmpp_plugin_version()

File diff suppressed because it is too large Load Diff

@ -0,0 +1,33 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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 "strophe.hh"
xmpp_log_t* logger = nullptr;
namespace xmpp {
context::context()
: context(xmpp_ctx_new(nullptr, logger)) {
}
context::context(xmpp_ctx_ptr ptr)
: xmpp_ctx_ptr(std::move(ptr)) {
}
context::context(xmpp_ctx_t *ptr)
: context(std::move(xmpp_ctx_ptr(
ptr, [this] (xmpp_ctx_t *ctx) {
xmpp_ctx_free(ctx);
}
))) {
}
context::~context() {
this->reset(nullptr);
}
void shutdown() {
xmpp_shutdown();
}
}

@ -0,0 +1,28 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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/.
#pragma once
#include <memory>
#include <functional>
extern "C" {
#include <strophe.h>
}
namespace xmpp {
typedef std::unique_ptr<
xmpp_ctx_t,
std::function<void(xmpp_ctx_t*)>> xmpp_ctx_ptr;
class context : public xmpp_ctx_ptr {
public:
context();
context(xmpp_ctx_ptr ptr);
context(xmpp_ctx_t *ptr);
~context();
};
void shutdown();
}

@ -13,6 +13,6 @@ TEST_CASE("placeholder")
CHECK(argc != 1); CHECK(argc != 1);
} }
weechat::plugin c; //weechat::plugin c;
CHECK(&c.name() == NULL); //CHECK(&c.name() == NULL);
} }

@ -0,0 +1,11 @@
#include <iostream>
#include <doctest/doctest.h>
#include "../strophe.hh"
TEST_CASE("create context")
{
xmpp::context ctx;
CHECK(ctx.get());
}

@ -6,7 +6,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "account.h" #include "account.h"

@ -5,7 +5,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h" #include "plugin.h"
#include "util.h" #include "util.h"

Loading…
Cancel
Save