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; -*-
export CC=gcc CXX=g++
export CC=gcc CXX="g++ -fdiagnostics-color=always"
# Miscellaneous packages.
ENVIRONMENTS=(

@ -40,6 +40,7 @@ LIBDIR ?= $(PREFIX)/lib
HDRS=plugin.hh \
plugin.h \
strophe.hh \
account.h \
buffer.h \
channel.h \
@ -56,6 +57,7 @@ HDRS=plugin.hh \
xmpp/stanza.h \
SRCS=plugin.cpp \
strophe.cpp \
account.c \
buffer.c \
channel.c \
@ -74,11 +76,14 @@ SRCS=plugin.cpp \
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))))
JOBS=$(patsubst tests/%.cc,tests/.%.o,$(TSTS))
all: weechat-xmpp
all:
make depend
make weechat-xmpp && make test
weechat-xmpp: $(DEPS) xmpp.so
xmpp.so: $(OBJS) $(DEPS) $(HDRS)
@ -120,7 +125,7 @@ debug: xmpp.so
depend: .depend
.depend: $(SRCS)
.depend: $(SRCS) $(HDRS) $(TSTS)
$(RM) ./.depend
$(CXX) $(CPPFLAGS) -MM $^>>./.depend
@ -147,7 +152,7 @@ else
chmod 755 ~/.weechat/plugins/xmpp.so
endif
.PHONY: check
.PHONY: all weechat-xmpp test debug depend tidy clean distclean install check
check:
clang-check --analyze *.c *.cc *.cpp

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

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

@ -8,7 +8,6 @@
#include <stdio.h>
#include <time.h>
#include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.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 ? weechat_color("reset") : "");
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"),
jid_resource ? user__as_prefix_raw(account, jid_bare) : "You",
jid_resource ? jid_resource : user__as_prefix_raw(account, jid_bare),
user__as_prefix_raw(account, jid_bare),
jid_resource,
user->profile.status ? "is " : "",
weechat_color("irc.color.message_join"),
user->profile.status ? user->profile.status : (user->profile.idle ? "idle" : "entered"),
weechat_color("reset"),
user->profile.idle ? "since " : "",
user->profile.status ? user->profile.status : "entered",
user->profile.idle ? " (idle since " : "",
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 ? "]" : "",

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

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

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

@ -9,7 +9,6 @@
#include <string.h>
#include <sys/utsname.h>
#include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.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);
user->profile.status_text = status ? strdup(status) : 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->profile.role = role ? strdup(role) : NULL;
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);
user->profile.status_text = status ? strdup(status) : 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->profile.role = role ? strdup(role) : NULL;
user->profile.affiliation = affiliation && strcmp(affiliation, "none") != 0

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

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

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

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

@ -3,17 +3,13 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "plugin.hh"
#include "strophe.hh"
#define WEECHAT_XMPP_PLUGIN_NAME "xmpp"
#define WEECHAT_XMPP_PLUGIN_VERSION "0.2.0"
namespace c {
extern "C" {
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <strophe.h>
#include "plugin.h"
#include "config.h"
#include "account.h"
@ -24,101 +20,91 @@ namespace c {
#include "completion.h"
struct t_weechat_plugin *weechat_xmpp_plugin() {
return weechat_plugin;
return (struct t_weechat_plugin*)weechat::globals::plugin;
};
const char *weechat_xmpp_plugin_name() {
return weechat::plugin::instance.name().data();
return WEECHAT_XMPP_PLUGIN_NAME;
};
const char *weechat_xmpp_plugin_version() {
return weechat::plugin::instance.version().data();
return WEECHAT_XMPP_PLUGIN_VERSION;
};
}
}
#define TIMER_INTERVAL_SEC 0.01
struct t_hook *weechat_xmpp_process_timer = NULL;
struct t_gui_bar_item *weechat_xmpp_typing_bar_item = NULL;
namespace weechat {
plugin::plugin()
: std::reference_wrapper<weechat_plugin>(
// try not to think about it too hard
*(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;
}
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,
&account__timer_cb,
NULL, NULL);
globals::process_timer =
weechat::hook_timer(plugin::timer_interval_sec * 1000, 0, 0,
&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",
"1", "1", "default", "default", "default", "default",
"off", "xmpp_typing");
}
weechat_xmpp_typing_bar_item = weechat_bar_item_new("xmpp_typing",
&buffer__typing_bar_cb,
NULL, NULL);
globals::typing_bar_item =
weechat::bar_item_new("xmpp_typing",
(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;
}
void weechat_plugin_end()
{
if (weechat_xmpp_typing_bar_item)
weechat_bar_item_remove(weechat_xmpp_typing_bar_item);
bool plugin::end() {
if (globals::typing_bar_item)
weechat::bar_item_remove(globals::typing_bar_item);
if (weechat_xmpp_process_timer)
weechat_unhook(weechat_xmpp_process_timer);
if (globals::process_timer)
weechat::unhook(globals::process_timer);
config__write();
c::config__write();
account__disconnect_all();
c::account__disconnect_all();
account__free_all();
c::account__free_all();
xmpp_shutdown();
}
}
xmpp::shutdown();
namespace weechat {
plugin::plugin() {
}
plugin::plugin(plugin_ptr ptr)
: plugin_ptr(std::move(ptr)) {
this->m_name = WEECHAT_XMPP_PLUGIN_NAME;
this->m_version = WEECHAT_XMPP_PLUGIN_VERSION;
return true;
}
plugin::plugin(struct t_weechat_plugin *ptr)
: plugin(std::move(weechat::plugin_ptr(
ptr, [this] (struct t_weechat_plugin *) { }
))) {
std::string_view plugin::name() const {
return plugin_get_name(*this);
}
bool plugin::init(std::vector<std::string>) {
weechat_printf(nullptr, "%s: It works!", this->name().data());
return c::weechat_plugin_init();
}
struct t_weechat_plugin* globals::plugin = nullptr;
bool plugin::end() {
c::weechat_plugin_end();
return true;
}
hook* globals::process_timer = nullptr;
plugin plugin::instance;
gui_bar_item* globals::typing_bar_item = nullptr;
}
extern "C" {
@ -129,15 +115,15 @@ extern "C" {
WEECHAT_PLUGIN_LICENSE("MPL2");
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);
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_
#ifndef __cplusplus
#include <weechat/weechat-plugin.h>
#define weechat_plugin weechat_xmpp_plugin()
#define WEECHAT_XMPP_PLUGIN_NAME weechat_xmpp_plugin_name()
#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);
}
weechat::plugin c;
CHECK(&c.name() == NULL);
//weechat::plugin c;
//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 <stdio.h>
#include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h"
#include "account.h"

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

Loading…
Cancel
Save