diff --git a/plugins/RubyTest.rb b/plugins/RubyTest.rb index bee7edb0..c4abcf1c 100644 --- a/plugins/RubyTest.rb +++ b/plugins/RubyTest.rb @@ -17,6 +17,7 @@ module RubyTest def self.prof_on_message_received(jid, message) Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message) Prof::cons_alert + return message + "[RUBY]" end def self.cmd_ruby() diff --git a/plugins/python-test.py b/plugins/python-test.py index 4639dd7c..21af15df 100644 --- a/plugins/python-test.py +++ b/plugins/python-test.py @@ -14,6 +14,7 @@ def prof_on_connect(account_name, fulljid): def prof_on_message_received(jid, message): prof.cons_show("python-test: on_message_received, " + jid + ", " + message) prof.cons_alert() + return message + "[PYTHON]" def cmd_python(msg): if msg: diff --git a/plugins/test-c-plugin/test-c-plugin.c b/plugins/test-c-plugin/test-c-plugin.c index 042bc9cd..fe9716ee 100644 --- a/plugins/test-c-plugin/test-c-plugin.c +++ b/plugins/test-c-plugin/test-c-plugin.c @@ -1,8 +1,7 @@ #include #include #include - -static FILE * f = NULL; +#include void prof_init (const char * const version, const char * const status) @@ -22,10 +21,14 @@ prof_on_connect (const char * const account_name, const char * const fulljid) fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, account_name, fulljid); } -void -prof_on_message_received (const char * const jid, const char * const message) +char * +prof_on_message_received (const char * const jid, const char *message) { fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, jid, message); + char *result = malloc(strlen(message) + 4); + sprintf(result, "%s%s", message, "[C]"); + + return result; } diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index 5f7dcacd..110eca07 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -95,19 +95,18 @@ c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const ch } -// FIXME wooow, if the message is cosntant, then how could I possibly fiddle around with it? -void -c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message) +char * +c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message) { void * f = NULL; - void (*func)(const char * const __jid, const char * const __message); + char* (*func)(const char * const __jid, const char * __message); assert (plugin && plugin->module); if (NULL == (f = dlsym (plugin->module, "prof_on_message_received"))) - return; + return NULL; - func = (void (*)(const char * const, const char * const)) f; - func (jid, message); + func = (char* (*)(const char * const, const char *)) f; + return func (jid, message); } diff --git a/src/plugins/c_plugins.h b/src/plugins/c_plugins.h index a118ffc9..a3f83c39 100644 --- a/src/plugins/c_plugins.h +++ b/src/plugins/c_plugins.h @@ -8,7 +8,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_on_start_hook (ProfPlugin *plugin); void c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const char * const fulljid); -void c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message); +char * c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message); void c_close_library (ProfPlugin * plugin); #endif diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 51a1953d..c15967fe 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -20,6 +20,9 @@ * */ +#include +#include + #include "config/preferences.h" #include "plugins/callbacks.h" #include "plugins/plugins.h" @@ -109,15 +112,25 @@ plugins_on_connect(const char * const account_name, const char * const fulljid) } } -void -plugins_on_message_received(const char * const jid, const char * const message) +char * +plugins_on_message_received(const char * const jid, const char *message) { GSList *curr = plugins; + char *new_message = NULL; + char *curr_message = strdup(message); + while (curr != NULL) { ProfPlugin *plugin = curr->data; - plugin->on_message_received_func(plugin, jid, message); + new_message = plugin->on_message_received_func(plugin, jid, curr_message); + if (new_message != NULL) { + free(curr_message); + curr_message = strdup(new_message); + free(new_message); + } curr = g_slist_next(curr); } + + return curr_message; } void diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 1a002adf..1c59357a 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -38,14 +38,14 @@ typedef struct prof_plugin_t { void (*on_start_func)(struct prof_plugin_t* plugin); void (*on_connect_func)(struct prof_plugin_t* plugin, const char * const account_name, const char * const fulljid); - void (*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); } ProfPlugin; void plugins_init(void); void plugins_on_start(void); void plugins_on_connect(const char * const account_name, const char * const fulljid); -void plugins_on_message_received(const char * const jid, const char * const message); +char * plugins_on_message_received(const char * const jid, const char *message); void plugins_shutdown(void); gboolean plugins_run_command(const char * const cmd); void plugins_run_timed(void); diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index b3f547b2..bcd2619a 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -122,9 +122,9 @@ python_on_connect_hook(ProfPlugin *plugin, const char * const account_name, } } -void +char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, - const char * const message) + const char *message) { PyObject *p_args = Py_BuildValue("ss", jid, message); PyObject *p_function; @@ -134,11 +134,20 @@ python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, p_function = PyObject_GetAttrString(p_module, "prof_on_message_received"); python_check_error(); if (p_function && PyCallable_Check(p_function)) { - PyObject_CallObject(p_function, p_args); + PyObject *result = PyObject_CallObject(p_function, p_args); python_check_error(); Py_XDECREF(p_function); + if (result != Py_None) { + char *result_str = strdup(PyString_AsString(result)); + Py_XDECREF(result); + return result_str;; + } else { + return NULL; + } } } + + return NULL; } void diff --git a/src/plugins/python_plugins.h b/src/plugins/python_plugins.h index b554044f..e213f333 100644 --- a/src/plugins/python_plugins.h +++ b/src/plugins/python_plugins.h @@ -30,7 +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_on_start_hook(ProfPlugin *plugin); void python_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid); -void python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message); +char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message); void python_check_error(void); diff --git a/src/plugins/ruby_plugins.c b/src/plugins/ruby_plugins.c index 04d58129..16642df9 100644 --- a/src/plugins/ruby_plugins.c +++ b/src/plugins/ruby_plugins.c @@ -94,17 +94,26 @@ ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, } } -void +char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, - const char * const message) + const char *message) { VALUE v_jid = rb_str_new2(jid); VALUE v_message = rb_str_new2(message); VALUE module = (VALUE) plugin->module; if (_method_exists(plugin, "prof_on_message_received")) { - rb_funcall(module, rb_intern("prof_on_message_received"), 2, v_jid, v_message); + VALUE result = rb_funcall(module, rb_intern("prof_on_message_received"), 2, v_jid, v_message); + if (TYPE(result) != T_NIL) { + char *result_str = STR2CSTR(result); + rb_gc_unregister_address(&result); + return result_str; + } else { + return NULL; + } } + + return NULL; } void diff --git a/src/plugins/ruby_plugins.h b/src/plugins/ruby_plugins.h index 293f1307..78cb72d0 100644 --- a/src/plugins/ruby_plugins.h +++ b/src/plugins/ruby_plugins.h @@ -30,7 +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_on_start_hook(ProfPlugin *plugin); void ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid); -void ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message); +char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message); void ruby_check_error(void); diff --git a/src/profanity.c b/src/profanity.c index 6b662562..99233f39 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -116,11 +116,6 @@ prof_handle_typing(char *from) void prof_handle_incoming_message(char *from, char *message, gboolean priv) { - ui_incoming_msg(from, message, NULL, priv); - ui_current_page_off(); - - plugins_on_message_received(from, message); - if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); const char *jid = jabber_get_fulljid(); @@ -129,17 +124,19 @@ prof_handle_incoming_message(char *from, char *message, gboolean priv) jid_destroy(jidp); jid_destroy(from_jid); } + + char *new_message = plugins_on_message_received(from, message); + + ui_incoming_msg(from, new_message, NULL, priv); + ui_current_page_off(); + + free(new_message); } void prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp, gboolean priv) { - ui_incoming_msg(from, message, &tv_stamp, priv); - ui_current_page_off(); - - plugins_on_message_received(from, message); - if (prefs_get_boolean(PREF_CHLOG) && !priv) { Jid *from_jid = jid_create(from); const char *jid = jabber_get_fulljid(); @@ -148,6 +145,13 @@ prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp, jid_destroy(jidp); jid_destroy(from_jid); } + + char * new_message = plugins_on_message_received(from, message); + + ui_incoming_msg(from, new_message, &tv_stamp, priv); + ui_current_page_off(); + + free(new_message); } void