Merge pull request #848 from orium/print-priority-847

Print{,_attr} and server{,_attr} hooks priority fix
This commit is contained in:
TingPing 2013-11-27 18:19:42 -08:00
commit ae4e55b922
5 changed files with 49 additions and 60 deletions

View File

@ -557,8 +557,7 @@ dcc_chat_line (struct DCC *dcc, char *line)
for (i = 5; i < PDIWORDS; i++) for (i = 5; i < PDIWORDS; i++)
word[i] = "\000"; word[i] = "\000";
ret = plugin_emit_print (sess, word) ret = plugin_emit_print (sess, word, 0);
+ plugin_emit_print_attrs (sess, word, 0);
/* did the plugin close it? */ /* did the plugin close it? */
if (!g_slist_find (dcc_list, dcc)) if (!g_slist_find (dcc_list, dcc))

View File

@ -102,16 +102,21 @@ enum
LIST_USERS LIST_USERS
}; };
/* We use binary flags here because it makes it possible for plugin_hook_find()
* to match several types of hooks. This is used so that plugin_hook_run()
* match both HOOK_SERVER and HOOK_SERVER_ATTRS hooks when plugin_emit_server()
* is called.
*/
enum enum
{ {
HOOK_COMMAND, /* /command */ HOOK_COMMAND = 1 << 0, /* /command */
HOOK_SERVER, /* PRIVMSG, NOTICE, numerics */ HOOK_SERVER = 1 << 1, /* PRIVMSG, NOTICE, numerics */
HOOK_SERVER_ATTRS, /* same as above, with attributes */ HOOK_SERVER_ATTRS = 1 << 2, /* same as above, with attributes */
HOOK_PRINT, /* All print events */ HOOK_PRINT = 1 << 3, /* All print events */
HOOK_PRINT_ATTRS, /* same as above, with attributes */ HOOK_PRINT_ATTRS = 1 << 4, /* same as above, with attributes */
HOOK_TIMER, /* timeouts */ HOOK_TIMER = 1 << 5, /* timeouts */
HOOK_FD, /* sockets & fds */ HOOK_FD = 1 << 6, /* sockets & fds */
HOOK_DELETED /* marked for deletion */ HOOK_DELETED = 1 << 7 /* marked for deletion */
}; };
GSList *plugin_list = NULL; /* export for plugingui.c */ GSList *plugin_list = NULL; /* export for plugingui.c */
@ -560,16 +565,14 @@ plugin_hook_find (GSList *list, int type, char *name)
while (list) while (list)
{ {
hook = list->data; hook = list->data;
if (hook && hook->type == type) if (hook && (hook->type & type))
{ {
if (g_ascii_strcasecmp (hook->name, name) == 0) if (g_ascii_strcasecmp (hook->name, name) == 0)
return list; return list;
if (type == HOOK_SERVER) if ((type & HOOK_SERVER)
{ && g_ascii_strcasecmp (hook->name, "RAW LINE") == 0)
if (g_ascii_strcasecmp (hook->name, "RAW LINE") == 0)
return list; return list;
}
} }
list = list->next; list = list->next;
} }
@ -599,7 +602,7 @@ plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[],
hook->pl->context = sess; hook->pl->context = sess;
/* run the plugin's callback function */ /* run the plugin's callback function */
switch (type) switch (hook->type)
{ {
case HOOK_COMMAND: case HOOK_COMMAND:
ret = ((hexchat_cmd_cb *)hook->callback) (word, word_eol, hook->userdata); ret = ((hexchat_cmd_cb *)hook->callback) (word, word_eol, hook->userdata);
@ -676,39 +679,30 @@ hexchat_event_attrs_free (hexchat_plugin *ph, hexchat_event_attrs *attrs)
} }
/* got a server PRIVMSG, NOTICE, numeric etc... */ /* got a server PRIVMSG, NOTICE, numeric etc... */
int
plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[])
{
return plugin_hook_run (sess, name, word, word_eol, NULL, HOOK_SERVER);
}
int int
plugin_emit_server_attrs (session *sess, char *name, char *word[], char *word_eol[], plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[],
time_t server_time) time_t server_time)
{ {
hexchat_event_attrs attrs; hexchat_event_attrs attrs;
attrs.server_time_utc = server_time; attrs.server_time_utc = server_time;
return plugin_hook_run (sess, name, word, word_eol, &attrs, HOOK_SERVER_ATTRS); return plugin_hook_run (sess, name, word, word_eol, &attrs,
HOOK_SERVER | HOOK_SERVER_ATTRS);
} }
/* see if any plugins are interested in this print event */ /* see if any plugins are interested in this print event */
int int
plugin_emit_print (session *sess, char *word[]) plugin_emit_print (session *sess, char *word[], time_t server_time)
{
return plugin_hook_run (sess, word[0], word, NULL, NULL, HOOK_PRINT);
}
int
plugin_emit_print_attrs (session *sess, char *word[], time_t server_time)
{ {
hexchat_event_attrs attrs; hexchat_event_attrs attrs;
attrs.server_time_utc = server_time; attrs.server_time_utc = server_time;
return plugin_hook_run (sess, word[0], word, NULL, &attrs, HOOK_PRINT_ATTRS); return plugin_hook_run (sess, word[0], word, NULL, &attrs,
HOOK_PRINT | HOOK_PRINT_ATTRS);
} }
int int
@ -783,12 +777,27 @@ plugin_insert_hook (hexchat_hook *new_hook)
{ {
GSList *list; GSList *list;
hexchat_hook *hook; hexchat_hook *hook;
int new_hook_type;
switch (new_hook->type)
{
case HOOK_PRINT:
case HOOK_PRINT_ATTRS:
new_hook_type = HOOK_PRINT | HOOK_PRINT_ATTRS;
break;
case HOOK_SERVER:
case HOOK_SERVER_ATTRS:
new_hook_type = HOOK_SERVER | HOOK_PRINT_ATTRS;
break;
default:
new_hook_type = new_hook->type;
}
list = hook_list; list = hook_list;
while (list) while (list)
{ {
hook = list->data; hook = list->data;
if (hook && hook->type == new_hook->type && hook->pri <= new_hook->pri) if (hook && (hook->type & new_hook_type) && hook->pri <= new_hook->pri)
{ {
hook_list = g_slist_insert_before (hook_list, list, new_hook); hook_list = g_slist_insert_before (hook_list, list, new_hook);
return; return;

View File

@ -170,11 +170,9 @@ int plugin_kill (char *name, int by_filename);
void plugin_kill_all (void); void plugin_kill_all (void);
void plugin_auto_load (session *sess); void plugin_auto_load (session *sess);
int plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[]); 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[]); int plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[],
int plugin_emit_server_attrs (session *sess, char *name, char *word[], time_t server_time);
char *word_eol[], time_t server_time); int plugin_emit_print (session *sess, char *word[], time_t server_time);
int plugin_emit_print (session *sess, char *word[]);
int plugin_emit_print_attrs (session *sess, char *word[], time_t server_time);
int plugin_emit_dummy_print (session *sess, char *name); int plugin_emit_dummy_print (session *sess, char *name);
int plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval, int len, char *string); int plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval, int len, char *string);
GList* plugin_command_list(GList *tmp_list); GList* plugin_command_list(GList *tmp_list);

View File

@ -1503,9 +1503,6 @@ irc_inline (server *serv, char *buf, int len)
if (buf[0] == ':') if (buf[0] == ':')
{ {
int eat1;
int eat2;
/* find a context for this message */ /* find a context for this message */
if (is_channel (serv, word[3])) if (is_channel (serv, word[3]))
{ {
@ -1520,11 +1517,8 @@ irc_inline (server *serv, char *buf, int len)
word[0] = type; word[0] = type;
word_eol[1] = buf; /* keep the ":" for plugins */ word_eol[1] = buf; /* keep the ":" for plugins */
eat1 = plugin_emit_server (sess, type, word, word_eol); if (plugin_emit_server (sess, type, word, word_eol,
eat2 = plugin_emit_server_attrs (sess, type, word, word_eol, tags_data.timestamp))
tags_data.timestamp);
if (eat1 || eat2)
goto xit; goto xit;
word[1]++; word[1]++;
@ -1532,16 +1526,10 @@ irc_inline (server *serv, char *buf, int len)
} else } else
{ {
int eat1;
int eat2;
word[0] = type = word[1]; word[0] = type = word[1];
eat1 = plugin_emit_server (sess, type, word, word_eol); if (plugin_emit_server (sess, type, word, word_eol,
eat2 = plugin_emit_server_attrs (sess, type, word, word_eol, tags_data.timestamp))
tags_data.timestamp);
if (eat1 || eat2)
goto xit; goto xit;
} }

View File

@ -2074,8 +2074,6 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
int i; int i;
unsigned int stripcolor_args = (chanopt_is_set (prefs.hex_text_stripcolor_msg, sess->text_strip) ? 0xFFFFFFFF : 0); unsigned int stripcolor_args = (chanopt_is_set (prefs.hex_text_stripcolor_msg, sess->text_strip) ? 0xFFFFFFFF : 0);
char tbuf[NICKLEN + 4]; char tbuf[NICKLEN + 4];
int eat1;
int eat2;
if (prefs.hex_text_color_nicks && (index == XP_TE_CHANACTION || index == XP_TE_CHANMSG)) if (prefs.hex_text_color_nicks && (index == XP_TE_CHANACTION || index == XP_TE_CHANMSG))
{ {
@ -2092,10 +2090,7 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
for (i = 5; i < PDIWORDS; i++) for (i = 5; i < PDIWORDS; i++)
word[i] = "\000"; word[i] = "\000";
eat1 = plugin_emit_print (sess, word); if (plugin_emit_print (sess, word, timestamp))
eat2 = plugin_emit_print_attrs (sess, word, timestamp);
if (eat1 || eat2)
return; return;
/* If a plugin's callback executes "/close", 'sess' may be invalid */ /* If a plugin's callback executes "/close", 'sess' may be invalid */