1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-14 18:14:15 -04:00

Add pre chat and room message blocking

This commit is contained in:
James Booth 2017-01-22 18:08:29 +00:00
parent 7090f85d85
commit 83385cdbc0
9 changed files with 85 additions and 21 deletions

View File

@ -61,7 +61,7 @@ void prof_post_chat_message_display(const char * const barejid, const char *cons
Called before a chat message is sent
@param barejid Jabber ID of the message recipient
@param message the message to be sent
@return the new message to send, or NULL to preserve the original message
@return the modified or original message to send, or NULL to cancel sending of the message
*/
char* prof_pre_chat_message_send(const char * const barejid, const char *message);
@ -93,7 +93,7 @@ void prof_post_room_message_display(const char * const barejid, const char * con
Called before a chat room message is sent
@param barejid Jabber ID of the room
@param message the message to be sent
@return the new message to send, or NULL to preserve the original message
@return the modified or original message to send, or NULL to cancel sending of the message
*/
char* prof_pre_room_message_send(const char * const barejid, const char *message);
@ -135,7 +135,7 @@ Called before a private chat room message is sent
@param barejid Jabber ID of the room
@param nick nickname of message recipient
@param message the message to be sent
@return the new message to send, or NULL to preserve the original message
@return the modified or original message to send, or NULL to cancel sending of the message
*/
char* prof_pre_priv_message_send(const char * const barejid, const char * const nick, const char *message);

View File

@ -106,7 +106,7 @@ def prof_pre_chat_message_send(barejid, message):
:param message: the message to be sent
:type barejid: str or unicode
:type message: str or unicode
:return: the new message to send, or ``None`` to preserve the original message
:return: the modified or original message to send, or ``None`` to cancel sending of the message
:rtype: str or unicode
"""
pass
@ -158,7 +158,7 @@ def prof_pre_room_message_send(barejid, message):
:param message: the message to be sent
:type barejid: str or unicode
:type message: str or unicode
:return: the new message to send, or ``None`` to preserve the original message
:return: the modified or original message to send, or ``None`` to cancel sending of the message
:rtype: str or unicode
"""
pass
@ -227,7 +227,7 @@ def prof_pre_priv_message_send(barejid, nick, message):
:type barejid: str or unicode
:type nick: str or unicode
:type message: str or unicode
:return: the new message to send, or ``None`` to preserve the original message
:return: the modified or original message to send, or ``None`` to cancel sending of the message
:rtype: str or unicode
"""
pass

View File

@ -136,6 +136,9 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
}
char *plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg);
if (plugin_msg == NULL) {
return;
}
// OTR suported, PGP supported
#ifdef HAVE_LIBOTR
@ -218,6 +221,9 @@ void
cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url)
{
char *plugin_msg = plugins_pre_room_message_send(mucwin->roomjid, msg);
if (plugin_msg == NULL) {
return;
}
message_send_groupchat(mucwin->roomjid, plugin_msg, oob_url);

View File

@ -81,6 +81,7 @@ c_plugin_create(const char *const filename)
plugin->lang = LANG_C;
plugin->module = handle;
plugin->init_func = c_init_hook;
plugin->contains_hook = c_contains_hook;
plugin->on_start_func = c_on_start_hook;
plugin->on_shutdown_func = c_on_shutdown_hook;
plugin->on_unload_func = c_on_unload_hook;
@ -136,6 +137,16 @@ c_init_hook(ProfPlugin *plugin, const char *const version, const char *const sta
func(version, status, account_name, fulljid);
}
gboolean
c_contains_hook(ProfPlugin *plugin, const char *const hook)
{
if (dlsym(plugin->module, hook)) {
return TRUE;
} else {
return FALSE;
}
}
void
c_on_start_hook(ProfPlugin *plugin)
{

View File

@ -45,6 +45,9 @@ void c_shutdown(void);
void c_init_hook(ProfPlugin *plugin, const char *const version, const char *const status, const char *const account_name,
const char *const fulljid);
gboolean c_contains_hook(ProfPlugin *plugin, const char *const hook);
void c_on_start_hook(ProfPlugin *plugin);
void c_on_shutdown_hook(ProfPlugin *plugin);
void c_on_unload_hook(ProfPlugin *plugin);

View File

@ -413,11 +413,18 @@ plugins_pre_chat_message_send(const char * const barejid, const char *message)
GList *curr = values;
while (curr) {
ProfPlugin *plugin = curr->data;
new_message = plugin->pre_chat_message_send(plugin, barejid, curr_message);
if (new_message) {
free(curr_message);
curr_message = strdup(new_message);
free(new_message);
if (plugin->contains_hook(plugin, "prof_pre_chat_message_send")) {
new_message = plugin->pre_chat_message_send(plugin, barejid, curr_message);
if (new_message) {
free(curr_message);
curr_message = strdup(new_message);
free(new_message);
} else {
free(curr_message);
g_list_free(values);
return NULL;
}
}
curr = g_list_next(curr);
}
@ -485,11 +492,18 @@ plugins_pre_room_message_send(const char * const barejid, const char *message)
GList *curr = values;
while (curr) {
ProfPlugin *plugin = curr->data;
new_message = plugin->pre_room_message_send(plugin, barejid, curr_message);
if (new_message) {
free(curr_message);
curr_message = strdup(new_message);
free(new_message);
if (plugin->contains_hook(plugin, "prof_pre_room_message_send")) {
new_message = plugin->pre_room_message_send(plugin, barejid, curr_message);
if (new_message) {
free(curr_message);
curr_message = strdup(new_message);
free(new_message);
} else {
free(curr_message);
g_list_free(values);
return NULL;
}
}
curr = g_list_next(curr);
}
@ -587,11 +601,19 @@ plugins_pre_priv_message_send(const char * const fulljid, const char * const mes
GList *curr = values;
while (curr) {
ProfPlugin *plugin = curr->data;
new_message = plugin->pre_priv_message_send(plugin, jidp->barejid, jidp->resourcepart, curr_message);
if (new_message) {
free(curr_message);
curr_message = strdup(new_message);
free(new_message);
if (plugin->contains_hook(plugin, "prof_pre_priv_message_send")) {
new_message = plugin->pre_priv_message_send(plugin, jidp->barejid, jidp->resourcepart, curr_message);
if (new_message) {
free(curr_message);
curr_message = strdup(new_message);
free(new_message);
} else {
free(curr_message);
g_list_free(values);
jid_destroy(jidp);
return NULL;
}
}
curr = g_list_next(curr);
}

View File

@ -49,6 +49,8 @@ typedef struct prof_plugin_t {
void (*init_func)(struct prof_plugin_t* plugin, const char * const version,
const char * const status, const char *const account_name, const char *const fulljid);
gboolean (*contains_hook)(struct prof_plugin_t* plugin, const char *const hook);
void (*on_start_func)(struct prof_plugin_t* plugin);
void (*on_shutdown_func)(struct prof_plugin_t* plugin);
void (*on_unload_func)(struct prof_plugin_t* plugin);

View File

@ -125,6 +125,7 @@ python_plugin_create(const char *const filename)
plugin->lang = LANG_PYTHON;
plugin->module = p_module;
plugin->init_func = python_init_hook;
plugin->contains_hook = python_contains_hook;
plugin->on_start_func = python_on_start_hook;
plugin->on_shutdown_func = python_on_shutdown_hook;
plugin->on_unload_func = python_on_unload_hook;
@ -184,6 +185,22 @@ python_init_hook(ProfPlugin *plugin, const char *const version, const char *cons
allow_python_threads();
}
gboolean
python_contains_hook(ProfPlugin *plugin, const char *const hook)
{
disable_python_threads();
gboolean res = FALSE;
PyObject *p_module = plugin->module;
if (PyObject_HasAttrString(p_module, hook)) {
res = TRUE;
}
allow_python_threads();
return res;
}
void
python_on_start_hook(ProfPlugin *plugin)
{

View File

@ -47,6 +47,9 @@ const char* python_get_version(void);
void python_init_hook(ProfPlugin *plugin, const char *const version, const char *const status,
const char *const account_name, const char *const fulljid);
gboolean python_contains_hook(ProfPlugin *plugin, const char *const hook);
void python_on_start_hook(ProfPlugin *plugin);
void python_on_shutdown_hook(ProfPlugin *plugin);
void python_on_unload_hook(ProfPlugin *plugin);