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.7 KiB
C++

4 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>
4 years ago
#include <strophe.h>
4 years ago
#include <weechat/weechat-plugin.h>
4 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"
4 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" {
4 years ago
WEECHAT_PLUGIN_NAME(WEECHAT_XMPP_PLUGIN_NAME);
4 years ago
WEECHAT_PLUGIN_DESCRIPTION(N_("XMPP client protocol"));
4 years ago
WEECHAT_PLUGIN_AUTHOR("bqv <weechat@fron.io>");
4 years ago
WEECHAT_PLUGIN_VERSION(WEECHAT_XMPP_PLUGIN_VERSION);
4 years ago
WEECHAT_PLUGIN_LICENSE("MPL2");
WEECHAT_PLUGIN_PRIORITY(5500);
}
4 years ago
3 years ago
extern "C"
void weechat_signal_handler(int)
{
__asm__("int3");
}
extern "C"
4 years ago
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
{
4 years ago
(void) argc;
(void) argv;
4 years ago
3 years ago
std::signal(SIGSEGV, weechat_signal_handler);
4 years ago
weechat_xmpp_plugin = plugin;
4 years ago
4 years ago
if (!config__init())
4 years ago
return WEECHAT_RC_ERROR;
4 years ago
4 years ago
config__read();
4 years ago
4 years ago
connection__init();
4 years ago
4 years ago
command__init();
completion__init();
4 years ago
4 years ago
weechat_xmpp_process_timer = weechat_hook_timer(TIMER_INTERVAL_SEC * 1000, 0, 0,
4 years ago
&account__timer_cb,
NULL, NULL);
4 years ago
if (!weechat_bar_search("typing"))
{
weechat_bar_new("typing", "off", "400", "window", "${typing}",
"bottom", "horizontal", "vertical",
"1", "1", "default", "default", "default", "default",
4 years ago
"off", "xmpp_typing");
}
4 years ago
weechat_xmpp_typing_bar_item = weechat_bar_item_new("xmpp_typing",
&buffer__typing_bar_cb,
NULL, NULL);
4 years ago
3 years ago
weechat_hook_signal("input_text_changed", &input__text_changed_cb, NULL, NULL);
4 years ago
return WEECHAT_RC_OK;
}
extern "C"
4 years ago
int weechat_plugin_end(struct t_weechat_plugin *plugin)
{
4 years ago
// make C compiler happy
4 years ago
(void) plugin;
4 years ago
if (weechat_xmpp_typing_bar_item)
weechat_bar_item_remove(weechat_xmpp_typing_bar_item);
4 years ago
4 years ago
if (weechat_xmpp_process_timer)
weechat_unhook(weechat_xmpp_process_timer);
4 years ago
4 years ago
config__write();
4 years ago
account__disconnect_all();
4 years ago
4 years ago
account__free_all();
4 years ago
4 years ago
xmpp_shutdown();
4 years ago
return WEECHAT_RC_OK;
}