You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.8 KiB
C++

3 years ago
// 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/.
3 years ago
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <ctime>
3 years ago
#include <csignal>
3 years ago
#include <strophe.h>
3 years ago
#include <weechat/weechat-plugin.h>
3 years ago
3 years ago
#include "plugin.hh"
3 years ago
#include "config.hh"
#include "account.hh"
#include "connection.hh"
#include "command.hh"
3 years ago
#include "input.hh"
#include "buffer.hh"
#include "completion.hh"
3 years ago
3 years ago
struct t_weechat_plugin *weechat_xmpp_plugin = NULL;
struct t_hook *weechat_xmpp_process_timer = NULL;
struct t_gui_bar_item *weechat_xmpp_typing_bar_item = NULL;
#pragma GCC visibility push(default)
extern "C" {
3 years ago
WEECHAT_PLUGIN_NAME(WEECHAT_XMPP_PLUGIN_NAME);
3 years ago
WEECHAT_PLUGIN_DESCRIPTION(N_("XMPP client protocol"));
3 years ago
WEECHAT_PLUGIN_AUTHOR("bqv <weechat@fron.io>");
3 years ago
WEECHAT_PLUGIN_VERSION(WEECHAT_XMPP_PLUGIN_VERSION);
3 years ago
WEECHAT_PLUGIN_LICENSE("MPL2");
WEECHAT_PLUGIN_PRIORITY(5500);
}
3 years ago
3 years ago
extern "C"
void weechat_signal_handler(int)
{
__asm__("int3");
}
extern "C"
3 years ago
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
{
3 years ago
(void) argc;
(void) argv;
3 years ago
3 years ago
std::signal(SIGSEGV, weechat_signal_handler);
3 years ago
weechat_xmpp_plugin = plugin;
3 years ago
if (!weechat::config::init())
3 years ago
return WEECHAT_RC_ERROR;
3 years ago
weechat::config::read();
3 years ago
weechat::connection::init();
3 years ago
3 years ago
command__init();
completion__init();
3 years ago
3 years ago
weechat_xmpp_process_timer = weechat_hook_timer(TIMER_INTERVAL_SEC * 1000, 0, 0,
&weechat::account::timer_cb,
3 years ago
NULL, NULL);
3 years ago
if (!weechat_bar_search("typing"))
{
weechat_bar_new("typing", "off", "400", "window", "${typing}",
"bottom", "horizontal", "vertical",
"1", "1", "default", "default", "default", "default",
3 years ago
"off", "xmpp_typing");
}
3 years ago
weechat_xmpp_typing_bar_item = weechat_bar_item_new("xmpp_typing",
&buffer__typing_bar_cb,
NULL, NULL);
3 years ago
3 years ago
weechat_hook_signal("input_text_changed", &input__text_changed_cb, NULL, NULL);
3 years ago
return WEECHAT_RC_OK;
}
extern "C"
3 years ago
int weechat_plugin_end(struct t_weechat_plugin *plugin)
{
3 years ago
// make C compiler happy
3 years ago
(void) plugin;
3 years ago
if (weechat_xmpp_typing_bar_item)
weechat_bar_item_remove(weechat_xmpp_typing_bar_item);
3 years ago
3 years ago
if (weechat_xmpp_process_timer)
weechat_unhook(weechat_xmpp_process_timer);
3 years ago
weechat::config::write();
weechat::account::disconnect_all();
3 years ago
weechat::accounts.clear();
3 years ago
3 years ago
xmpp_shutdown();
3 years ago
return WEECHAT_RC_OK;
}