mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-10-17 10:37:12 +00:00
add opt-in post-display print hooks
This commit is contained in:
@@ -143,6 +143,7 @@ enum
|
||||
HOOK_PRINT_ATTRS = 1 << 4, /* same as above, with attributes */
|
||||
HOOK_TIMER = 1 << 5, /* timeouts */
|
||||
HOOK_FD = 1 << 6, /* sockets & fds */
|
||||
HOOK_PRINT_AFTER = 1 << 8, /* opt-in post-display observers */
|
||||
HOOK_DELETED = 1 << 7 /* marked for deletion */
|
||||
};
|
||||
|
||||
@@ -351,6 +352,7 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func,
|
||||
pl->zoitechat_emit_print_attrs = zoitechat_emit_print_attrs;
|
||||
pl->zoitechat_event_attrs_create = zoitechat_event_attrs_create;
|
||||
pl->zoitechat_event_attrs_free = zoitechat_event_attrs_free;
|
||||
pl->zoitechat_hook_print_after = zoitechat_hook_print_after;
|
||||
|
||||
/* run zoitechat_plugin_init, if it returns 0, close the plugin */
|
||||
if (((zoitechat_init_func *)init_func) (pl, &pl->name, &pl->desc, &pl->version, arg) == 0)
|
||||
@@ -621,6 +623,13 @@ plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[],
|
||||
|
||||
hook = list->data;
|
||||
next = list->next;
|
||||
if (type == HOOK_PRINT_AFTER && hook->tag)
|
||||
{
|
||||
list = next;
|
||||
continue; /* no recursive invocation of this same observer */
|
||||
}
|
||||
if (type == HOOK_PRINT_AFTER)
|
||||
hook->tag = 1;
|
||||
hook->pl->context = sess;
|
||||
|
||||
/* run the plugin's callback function */
|
||||
@@ -629,6 +638,7 @@ plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[],
|
||||
case HOOK_COMMAND:
|
||||
ret = ((zoitechat_cmd_cb *)hook->callback) (word, word_eol, hook->userdata);
|
||||
break;
|
||||
case HOOK_PRINT_AFTER:
|
||||
case HOOK_PRINT_ATTRS:
|
||||
ret = ((zoitechat_print_attrs_cb *)hook->callback) (word, attrs, hook->userdata);
|
||||
break;
|
||||
@@ -643,6 +653,15 @@ plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[],
|
||||
break;
|
||||
}
|
||||
|
||||
if (type == HOOK_PRINT_AFTER)
|
||||
{
|
||||
hook->tag = 0;
|
||||
if (!is_session (sess))
|
||||
goto xit;
|
||||
list = next;
|
||||
continue; /* display already happened; observers cannot eat it */
|
||||
}
|
||||
|
||||
if ((ret & ZOITECHAT_EAT_ZOITECHAT) && (ret & ZOITECHAT_EAT_PLUGIN))
|
||||
{
|
||||
eat = 1;
|
||||
@@ -725,6 +744,15 @@ plugin_emit_print (session *sess, char *word[], time_t server_time)
|
||||
HOOK_PRINT | HOOK_PRINT_ATTRS);
|
||||
}
|
||||
|
||||
void
|
||||
plugin_emit_print_after (session *sess, char *word[], time_t server_time)
|
||||
{
|
||||
zoitechat_event_attrs attrs;
|
||||
attrs.server_time_utc = server_time;
|
||||
if (is_session (sess))
|
||||
plugin_hook_run (sess, word[0], word, NULL, &attrs, HOOK_PRINT_AFTER);
|
||||
}
|
||||
|
||||
int
|
||||
plugin_emit_dummy_print (session *sess, char *name)
|
||||
{
|
||||
@@ -1028,6 +1056,15 @@ zoitechat_unhook (zoitechat_plugin *ph, zoitechat_hook *hook)
|
||||
return hook->userdata;
|
||||
}
|
||||
|
||||
zoitechat_hook *
|
||||
zoitechat_hook_print_after (zoitechat_plugin *ph, const char *name, int pri,
|
||||
int flags, zoitechat_print_attrs_cb *callback, void *userdata)
|
||||
{
|
||||
if (flags != 0 || !name || !callback)
|
||||
return NULL;
|
||||
return plugin_add_hook (ph, HOOK_PRINT_AFTER, pri, name, NULL, callback, 0, userdata);
|
||||
}
|
||||
|
||||
zoitechat_hook *
|
||||
zoitechat_hook_command (zoitechat_plugin *ph, const char *name, int pri,
|
||||
zoitechat_cmd_cb *callb, const char *help_text, void *userdata)
|
||||
@@ -1197,6 +1234,9 @@ zoitechat_get_info (zoitechat_plugin *ph, const char *id)
|
||||
? "ascii" : "rfc1459";
|
||||
}
|
||||
|
||||
if (strcmp (id, "api_hook_print_after") == 0)
|
||||
return "1";
|
||||
|
||||
hash = str_hash (id);
|
||||
/* do the session independant ones first */
|
||||
switch (hash)
|
||||
|
||||
@@ -183,6 +183,7 @@ int plugin_emit_command (session *sess, char *name, char *word[], char *word_eol
|
||||
int plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[],
|
||||
time_t server_time);
|
||||
int plugin_emit_print (session *sess, char *word[], time_t server_time);
|
||||
void plugin_emit_print_after (session *sess, char *word[], time_t server_time);
|
||||
int plugin_emit_dummy_print (session *sess, char *name);
|
||||
int plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval, gunichar key);
|
||||
GList* plugin_command_list(GList *tmp_list);
|
||||
|
||||
@@ -2306,6 +2306,7 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
|
||||
if (!prefs.hex_away_omit_alerts || !sess->server->is_away)
|
||||
sound_play_event (index);
|
||||
display_event (sess, index, word, stripcolor_args, timestamp);
|
||||
plugin_emit_print_after (sess, word, timestamp);
|
||||
}
|
||||
|
||||
char *
|
||||
|
||||
@@ -206,6 +206,12 @@ struct _zoitechat_plugin
|
||||
#endif
|
||||
|
||||
|
||||
/* api_hook_print_after=1: observer returns are ignored; flags must be zero. */
|
||||
zoitechat_hook *zoitechat_hook_print_after (zoitechat_plugin *ph,
|
||||
const char *name, int pri, int flags,
|
||||
int (*callback) (char *word[], zoitechat_event_attrs *attrs, void *userdata),
|
||||
void *userdata);
|
||||
|
||||
zoitechat_hook *
|
||||
zoitechat_hook_command (zoitechat_plugin *ph,
|
||||
const char *name,
|
||||
@@ -425,6 +431,7 @@ zoitechat_pluginpref_list (zoitechat_plugin *ph,
|
||||
#define zoitechat_hook_server ((ZOITECHAT_PLUGIN_HANDLE)->zoitechat_hook_server)
|
||||
#define zoitechat_hook_server_attrs ((ZOITECHAT_PLUGIN_HANDLE)->zoitechat_hook_server_attrs)
|
||||
#define zoitechat_hook_print ((ZOITECHAT_PLUGIN_HANDLE)->zoitechat_hook_print)
|
||||
#define zoitechat_hook_print_after ((ZOITECHAT_PLUGIN_HANDLE)->zoitechat_hook_print_after)
|
||||
#define zoitechat_hook_print_attrs ((ZOITECHAT_PLUGIN_HANDLE)->zoitechat_hook_print_attrs)
|
||||
#define zoitechat_hook_timer ((ZOITECHAT_PLUGIN_HANDLE)->zoitechat_hook_timer)
|
||||
#define zoitechat_hook_fd ((ZOITECHAT_PLUGIN_HANDLE)->zoitechat_hook_fd)
|
||||
|
||||
Reference in New Issue
Block a user