mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
on_message_received hook may return new message
This commit is contained in:
parent
c5e39e0f54
commit
17013d1a05
@ -17,6 +17,7 @@ module RubyTest
|
|||||||
def self.prof_on_message_received(jid, message)
|
def self.prof_on_message_received(jid, message)
|
||||||
Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message)
|
Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message)
|
||||||
Prof::cons_alert
|
Prof::cons_alert
|
||||||
|
return message + "[RUBY]"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cmd_ruby()
|
def self.cmd_ruby()
|
||||||
|
@ -14,6 +14,7 @@ def prof_on_connect(account_name, fulljid):
|
|||||||
def prof_on_message_received(jid, message):
|
def prof_on_message_received(jid, message):
|
||||||
prof.cons_show("python-test: on_message_received, " + jid + ", " + message)
|
prof.cons_show("python-test: on_message_received, " + jid + ", " + message)
|
||||||
prof.cons_alert()
|
prof.cons_alert()
|
||||||
|
return message + "[PYTHON]"
|
||||||
|
|
||||||
def cmd_python(msg):
|
def cmd_python(msg):
|
||||||
if msg:
|
if msg:
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
static FILE * f = NULL;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
prof_init (const char * const version, const char * const status)
|
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);
|
fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, account_name, fulljid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char *
|
||||||
prof_on_message_received (const char * const jid, const char * const message)
|
prof_on_message_received (const char * const jid, const char *message)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, jid, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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?
|
char *
|
||||||
void
|
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 * const message)
|
|
||||||
{
|
{
|
||||||
void * f = NULL;
|
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);
|
assert (plugin && plugin->module);
|
||||||
|
|
||||||
if (NULL == (f = dlsym (plugin->module, "prof_on_message_received")))
|
if (NULL == (f = dlsym (plugin->module, "prof_on_message_received")))
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
func = (void (*)(const char * const, const char * const)) f;
|
func = (char* (*)(const char * const, const char *)) f;
|
||||||
func (jid, message);
|
return func (jid, message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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_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_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);
|
void c_close_library (ProfPlugin * plugin);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "config/preferences.h"
|
#include "config/preferences.h"
|
||||||
#include "plugins/callbacks.h"
|
#include "plugins/callbacks.h"
|
||||||
#include "plugins/plugins.h"
|
#include "plugins/plugins.h"
|
||||||
@ -109,15 +112,25 @@ plugins_on_connect(const char * const account_name, const char * const fulljid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char *
|
||||||
plugins_on_message_received(const char * const jid, const char * const message)
|
plugins_on_message_received(const char * const jid, const char *message)
|
||||||
{
|
{
|
||||||
GSList *curr = plugins;
|
GSList *curr = plugins;
|
||||||
|
char *new_message = NULL;
|
||||||
|
char *curr_message = strdup(message);
|
||||||
|
|
||||||
while (curr != NULL) {
|
while (curr != NULL) {
|
||||||
ProfPlugin *plugin = curr->data;
|
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);
|
curr = g_slist_next(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return curr_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -38,14 +38,14 @@ 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_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);
|
||||||
} ProfPlugin;
|
} ProfPlugin;
|
||||||
|
|
||||||
void plugins_init(void);
|
void plugins_init(void);
|
||||||
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_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);
|
void plugins_shutdown(void);
|
||||||
gboolean plugins_run_command(const char * const cmd);
|
gboolean plugins_run_command(const char * const cmd);
|
||||||
void plugins_run_timed(void);
|
void plugins_run_timed(void);
|
||||||
|
@ -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,
|
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_args = Py_BuildValue("ss", jid, message);
|
||||||
PyObject *p_function;
|
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");
|
p_function = PyObject_GetAttrString(p_module, "prof_on_message_received");
|
||||||
python_check_error();
|
python_check_error();
|
||||||
if (p_function && PyCallable_Check(p_function)) {
|
if (p_function && PyCallable_Check(p_function)) {
|
||||||
PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
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
|
void
|
||||||
|
@ -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_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_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);
|
void python_check_error(void);
|
||||||
|
|
||||||
|
@ -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,
|
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_jid = rb_str_new2(jid);
|
||||||
VALUE v_message = rb_str_new2(message);
|
VALUE v_message = rb_str_new2(message);
|
||||||
|
|
||||||
VALUE module = (VALUE) plugin->module;
|
VALUE module = (VALUE) plugin->module;
|
||||||
if (_method_exists(plugin, "prof_on_message_received")) {
|
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
|
void
|
||||||
|
@ -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_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_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);
|
void ruby_check_error(void);
|
||||||
|
|
||||||
|
@ -116,11 +116,6 @@ prof_handle_typing(char *from)
|
|||||||
void
|
void
|
||||||
prof_handle_incoming_message(char *from, char *message, gboolean priv)
|
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) {
|
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||||
Jid *from_jid = jid_create(from);
|
Jid *from_jid = jid_create(from);
|
||||||
const char *jid = jabber_get_fulljid();
|
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(jidp);
|
||||||
jid_destroy(from_jid);
|
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
|
void
|
||||||
prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||||
gboolean priv)
|
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) {
|
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||||
Jid *from_jid = jid_create(from);
|
Jid *from_jid = jid_create(from);
|
||||||
const char *jid = jabber_get_fulljid();
|
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(jidp);
|
||||||
jid_destroy(from_jid);
|
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
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user