1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added prof_on_disconnect hook

This commit is contained in:
James Booth 2013-09-03 22:43:53 +01:00
parent b068d84722
commit e094e3d052
9 changed files with 73 additions and 1 deletions

View File

@ -50,6 +50,7 @@ c_plugin_create(const char * const filename)
plugin->init_func = c_init_hook; plugin->init_func = c_init_hook;
plugin->on_start_func = c_on_start_hook; plugin->on_start_func = c_on_start_hook;
plugin->on_connect_func = c_on_connect_hook; plugin->on_connect_func = c_on_connect_hook;
plugin->on_disconnect_func = c_on_disconnect_hook;
plugin->on_message_received_func = c_on_message_received_hook; plugin->on_message_received_func = c_on_message_received_hook;
plugin->on_message_send_func = c_on_message_send_hook; plugin->on_message_send_func = c_on_message_send_hook;
plugin->on_shutdown_func = c_on_shutdown_hook; plugin->on_shutdown_func = c_on_shutdown_hook;
@ -94,7 +95,7 @@ c_on_start_hook (ProfPlugin *plugin)
} }
void void
c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const char * const fulljid) c_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid)
{ {
void * f = NULL; void * f = NULL;
void (*func)(const char * const __account_name, const char * const __fulljid); void (*func)(const char * const __account_name, const char * const __fulljid);
@ -107,6 +108,20 @@ c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const ch
func (account_name, fulljid); func (account_name, fulljid);
} }
void
c_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid)
{
void * f = NULL;
void (*func)(const char * const __account_name, const char * const __fulljid);
assert (plugin && plugin->module);
if (NULL == (f = dlsym (plugin->module, "prof_on_disconnect")))
return ;
func = (void (*)(const char * const, const char * const)) f;
func (account_name, fulljid);
}
char * char *
c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message) c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message)
{ {

View File

@ -10,6 +10,7 @@ ProfPlugin* c_plugin_create(const char * const filename);
void c_init_hook(ProfPlugin *plugin, const char * const version, const char * const status); void c_init_hook(ProfPlugin *plugin, const char * const version, const char * const status);
void c_on_start_hook(ProfPlugin *plugin); void c_on_start_hook(ProfPlugin *plugin);
void c_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid); void c_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
void c_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
char * c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message); char * c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
char * c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message); char * c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
void c_plugin_destroy(ProfPlugin * plugin); void c_plugin_destroy(ProfPlugin * plugin);

View File

@ -135,6 +135,17 @@ plugins_on_connect(const char * const account_name, const char * const fulljid)
} }
} }
void
plugins_on_disconnect(const char * const account_name, const char * const fulljid)
{
GSList *curr = plugins;
while (curr != NULL) {
ProfPlugin *plugin = curr->data;
plugin->on_disconnect_func(plugin, account_name, fulljid);
curr = g_slist_next(curr);
}
}
char * char *
plugins_on_message_received(const char * const jid, const char *message) plugins_on_message_received(const char * const jid, const char *message)
{ {

View File

@ -38,6 +38,8 @@ typedef struct prof_plugin_t {
void (*on_start_func)(struct prof_plugin_t* plugin); void (*on_start_func)(struct prof_plugin_t* plugin);
void (*on_connect_func)(struct prof_plugin_t* plugin, void (*on_connect_func)(struct prof_plugin_t* plugin,
const char * const account_name, const char * const fulljid); const char * const account_name, const char * const fulljid);
void (*on_disconnect_func)(struct prof_plugin_t* plugin,
const char * const account_name, const char * const fulljid);
char* (*on_message_received_func)(struct prof_plugin_t* plugin, char* (*on_message_received_func)(struct prof_plugin_t* plugin,
const char * const jid, const char * const message); const char * const jid, const char * const message);
char* (*on_message_send_func)(struct prof_plugin_t* plugin, char* (*on_message_send_func)(struct prof_plugin_t* plugin,
@ -50,6 +52,7 @@ GSList * plugins_get_list(void);
char * plugins_get_lang_string(ProfPlugin *plugin); char * plugins_get_lang_string(ProfPlugin *plugin);
void plugins_on_start(void); void plugins_on_start(void);
void plugins_on_connect(const char * const account_name, const char * const fulljid); void plugins_on_connect(const char * const account_name, const char * const fulljid);
void plugins_on_disconnect(const char * const account_name, const char * const fulljid);
char * plugins_on_message_received(const char * const jid, const char *message); char * plugins_on_message_received(const char * const jid, const char *message);
char * plugins_on_message_send(const char * const jid, const char *message); char * plugins_on_message_send(const char * const jid, const char *message);
void plugins_on_shutdown(void); void plugins_on_shutdown(void);

View File

@ -63,6 +63,7 @@ python_plugin_create(const char * const filename)
plugin->init_func = python_init_hook; plugin->init_func = python_init_hook;
plugin->on_start_func = python_on_start_hook; plugin->on_start_func = python_on_start_hook;
plugin->on_connect_func = python_on_connect_hook; plugin->on_connect_func = python_on_connect_hook;
plugin->on_disconnect_func = python_on_disconnect_hook;
plugin->on_message_received_func = python_on_message_received_hook; plugin->on_message_received_func = python_on_message_received_hook;
plugin->on_message_send_func = python_on_message_send_hook; plugin->on_message_send_func = python_on_message_send_hook;
plugin->on_shutdown_func = python_on_shutdown_hook; plugin->on_shutdown_func = python_on_shutdown_hook;
@ -128,6 +129,25 @@ python_on_connect_hook(ProfPlugin *plugin, const char * const account_name,
} }
} }
void
python_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name,
const char * const fulljid)
{
PyObject *p_args = Py_BuildValue("ss", account_name, fulljid);
PyObject *p_function;
PyObject *p_module = plugin->module;
if (PyObject_HasAttrString(p_module, "prof_on_disconnect")) {
p_function = PyObject_GetAttrString(p_module, "prof_on_disconnect");
python_check_error();
if (p_function && PyCallable_Check(p_function)) {
PyObject_CallObject(p_function, p_args);
python_check_error();
Py_XDECREF(p_function);
}
}
}
char * char *
python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, python_on_message_received_hook(ProfPlugin *plugin, const char * const jid,
const char *message) const char *message)

View File

@ -30,6 +30,7 @@ ProfPlugin* python_plugin_create(const char * const filename);
void python_init_hook(ProfPlugin *plugin, const char * const version, const char * const status); void python_init_hook(ProfPlugin *plugin, const char * const version, const char * const status);
void python_on_start_hook(ProfPlugin *plugin); void python_on_start_hook(ProfPlugin *plugin);
void python_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid); void python_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
void python_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message); char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
char * python_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message); char * python_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
void python_on_shutdown_hook(ProfPlugin *plugin); void python_on_shutdown_hook(ProfPlugin *plugin);

View File

@ -60,6 +60,7 @@ ruby_plugin_create(const char * const filename)
plugin->init_func = ruby_init_hook; plugin->init_func = ruby_init_hook;
plugin->on_start_func = ruby_on_start_hook; plugin->on_start_func = ruby_on_start_hook;
plugin->on_connect_func = ruby_on_connect_hook; plugin->on_connect_func = ruby_on_connect_hook;
plugin->on_disconnect_func = ruby_on_disconnect_hook;
plugin->on_message_received_func = ruby_on_message_received_hook; plugin->on_message_received_func = ruby_on_message_received_hook;
plugin->on_message_send_func = ruby_on_message_send_hook; plugin->on_message_send_func = ruby_on_message_send_hook;
plugin->on_shutdown_func = ruby_on_shutdown_hook; plugin->on_shutdown_func = ruby_on_shutdown_hook;
@ -100,6 +101,18 @@ ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name,
} }
} }
void
ruby_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name,
const char * const fulljid)
{
VALUE v_account_name = rb_str_new2(account_name);
VALUE v_fulljid = rb_str_new2(fulljid);
VALUE module = (VALUE) plugin->module;
if (_method_exists(plugin, "prof_on_disconnect")) {
rb_funcall(module, rb_intern("prof_on_disconnect"), 2, v_account_name, v_fulljid);
}
}
char * char *
ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid,
const char *message) const char *message)

View File

@ -30,6 +30,7 @@ ProfPlugin* ruby_plugin_create(const char * const filename);
void ruby_init_hook(ProfPlugin *plugin, const char * const version, const char * const status); void ruby_init_hook(ProfPlugin *plugin, const char * const version, const char * const status);
void ruby_on_start_hook(ProfPlugin *plugin); void ruby_on_start_hook(ProfPlugin *plugin);
void ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid); void ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
void ruby_on_disconnect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message); char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
char * ruby_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message); char * ruby_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
void ruby_on_shutdown_hook(ProfPlugin *plugin); void ruby_on_shutdown_hook(ProfPlugin *plugin);

View File

@ -32,6 +32,7 @@
#include "jid.h" #include "jid.h"
#include "log.h" #include "log.h"
#include "muc.h" #include "muc.h"
#include "plugins/plugins.h"
#include "profanity.h" #include "profanity.h"
#include "xmpp/bookmark.h" #include "xmpp/bookmark.h"
#include "xmpp/capabilities.h" #include "xmpp/capabilities.h"
@ -166,6 +167,9 @@ jabber_disconnect(void)
{ {
// if connected, send end stream and wait for response // if connected, send end stream and wait for response
if (jabber_conn.conn_status == JABBER_CONNECTED) { if (jabber_conn.conn_status == JABBER_CONNECTED) {
char *account_name = jabber_get_account_name();
const char *fulljid = jabber_get_fulljid();
plugins_on_disconnect(account_name, fulljid);
log_info("Closing connection"); log_info("Closing connection");
jabber_conn.conn_status = JABBER_DISCONNECTING; jabber_conn.conn_status = JABBER_DISCONNECTING;
xmpp_disconnect(jabber_conn.conn); xmpp_disconnect(jabber_conn.conn);
@ -511,6 +515,9 @@ _connection_handler(xmpp_conn_t * const conn,
// lost connection for unkown reason // lost connection for unkown reason
if (jabber_conn.conn_status == JABBER_CONNECTED) { if (jabber_conn.conn_status == JABBER_CONNECTED) {
log_debug("Connection handler: Lost connection for unknown reason"); log_debug("Connection handler: Lost connection for unknown reason");
char *account_name = jabber_get_account_name();
const char *fulljid = jabber_get_fulljid();
plugins_on_disconnect(account_name, fulljid);
prof_handle_lost_connection(); prof_handle_lost_connection();
if (prefs_get_reconnect() != 0) { if (prefs_get_reconnect() != 0) {
assert(reconnect_timer == NULL); assert(reconnect_timer == NULL);