From 798db7368a2df832924be1f28c9720ae6bc60236 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 9 Jul 2013 20:21:16 +0100 Subject: Added hexchat_hook_server_attrs() and hexchat_hook_print_attrs() to the plugin interface. This hooks are similar to hexchat_hook_{server,print}() except the callback passes an extra argument with the (new) structure hexchat_event_attrs. This structure contains attributes related to the event; by now it only contains the server_time_utc member which is non-zero if server-time is enabled and the server used this extension to pass a timestamp. See issue #661. (Note: this hooks are still not called by hexchat in this commit.) --- src/common/hexchat-plugin.h | 30 +++++++++++++++++ src/common/plugin.c | 79 ++++++++++++++++++++++++++++++++++++++------- src/common/plugin.h | 15 +++++++++ 3 files changed, 112 insertions(+), 12 deletions(-) diff --git a/src/common/hexchat-plugin.h b/src/common/hexchat-plugin.h index 36dc544f..fd730459 100644 --- a/src/common/hexchat-plugin.h +++ b/src/common/hexchat-plugin.h @@ -46,6 +46,7 @@ extern "C" { typedef struct _hexchat_plugin hexchat_plugin; typedef struct _hexchat_list hexchat_list; typedef struct _hexchat_hook hexchat_hook; +typedef struct _hexchat_event_attrs hexchat_event_attrs; #ifndef PLUGIN_C typedef struct _hexchat_context hexchat_context; #endif @@ -164,6 +165,18 @@ struct _hexchat_plugin const char *var); int (*hexchat_pluginpref_list) (hexchat_plugin *ph, char *dest); + hexchat_hook *(*hexchat_hook_server_attrs) (hexchat_plugin *ph, + const char *name, + int pri, + int (*callback) (char *word[], char *word_eol[], + hexchat_event_attrs *attrs, void *user_data), + void *userdata); + hexchat_hook *(*hexchat_hook_print_attrs) (hexchat_plugin *ph, + const char *name, + int pri, + int (*callback) (char *word[], hexchat_event_attrs *attrs, + void *user_data), + void *userdata); }; #endif @@ -183,6 +196,15 @@ hexchat_hook_server (hexchat_plugin *ph, int (*callback) (char *word[], char *word_eol[], void *user_data), void *userdata); + +hexchat_hook * +hexchat_hook_server_attrs (hexchat_plugin *ph, + const char *name, + int pri, + int (*callback) (char *word[], char *word_eol[], + hexchat_event_attrs *attrs, void *user_data), + void *userdata); + hexchat_hook * hexchat_hook_print (hexchat_plugin *ph, const char *name, @@ -190,6 +212,14 @@ hexchat_hook_print (hexchat_plugin *ph, int (*callback) (char *word[], void *user_data), void *userdata); +hexchat_hook * +hexchat_hook_print_attrs (hexchat_plugin *ph, + const char *name, + int pri, + int (*callback) (char *word[], hexchat_event_attrs *attrs, + void *user_data), + void *userdata); + hexchat_hook * hexchat_hook_timer (hexchat_plugin *ph, int timeout, diff --git a/src/common/plugin.c b/src/common/plugin.c index 5a6a42a6..90c6bbc4 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -74,6 +74,11 @@ struct _hexchat_hook int pri; /* fd */ /* priority / fd for HOOK_FD only */ }; +struct _hexchat_event_attrs +{ + time_t server_time_utc; /* 0 if not used */ +}; + struct _hexchat_list { int type; /* LIST_* */ @@ -86,6 +91,8 @@ struct _hexchat_list typedef int (hexchat_cmd_cb) (char *word[], char *word_eol[], void *user_data); typedef int (hexchat_serv_cb) (char *word[], char *word_eol[], void *user_data); typedef int (hexchat_print_cb) (char *word[], void *user_data); +typedef int (hexchat_serv_attrs_cb) (char *word[], char *word_eol[], hexchat_event_attrs *attrs, void *user_data); +typedef int (hexchat_print_attrs_cb) (char *word[], hexchat_event_attrs *attrs, void *user_data); typedef int (hexchat_fd_cb) (int fd, int flags, void *user_data); typedef int (hexchat_timer_cb) (void *user_data); typedef int (hexchat_init_func) (hexchat_plugin *, char **, char **, char **, char *); @@ -102,12 +109,14 @@ enum enum { - HOOK_COMMAND, /* /command */ - HOOK_SERVER, /* PRIVMSG, NOTICE, numerics */ - HOOK_PRINT, /* All print events */ - HOOK_TIMER, /* timeouts */ - HOOK_FD, /* sockets & fds */ - HOOK_DELETED /* marked for deletion */ + HOOK_COMMAND, /* /command */ + HOOK_SERVER, /* PRIVMSG, NOTICE, numerics */ + HOOK_SERVER_ATTRS, /* same as above, with attributes */ + HOOK_PRINT, /* All print events */ + HOOK_PRINT_ATTRS, /* same as above, with attributes */ + HOOK_TIMER, /* timeouts */ + HOOK_FD, /* sockets & fds */ + HOOK_DELETED /* marked for deletion */ }; GSList *plugin_list = NULL; /* export for plugingui.c */ @@ -289,6 +298,8 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func, pl->hexchat_pluginpref_get_int = hexchat_pluginpref_get_int; pl->hexchat_pluginpref_delete = hexchat_pluginpref_delete; pl->hexchat_pluginpref_list = hexchat_pluginpref_list; + pl->hexchat_hook_server_attrs = hexchat_hook_server_attrs; + pl->hexchat_hook_print_attrs = hexchat_hook_print_attrs; /* incase new plugins are loaded on older HexChat */ pl->hexchat_dummy4 = hexchat_dummy; @@ -539,7 +550,8 @@ plugin_hook_find (GSList *list, int type, char *name) /* check for plugin hooks and run them */ static int -plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[], int type) +plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[], + hexchat_event_attrs *attrs, int type) { GSList *list, *next; hexchat_hook *hook; @@ -562,9 +574,15 @@ plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[], int case HOOK_COMMAND: ret = ((hexchat_cmd_cb *)hook->callback) (word, word_eol, hook->userdata); break; + case HOOK_PRINT_ATTRS: + ret = ((hexchat_print_attrs_cb *)hook->callback) (word, attrs, hook->userdata); + break; case HOOK_SERVER: ret = ((hexchat_serv_cb *)hook->callback) (word, word_eol, hook->userdata); break; + case HOOK_SERVER_ATTRS: + ret = ((hexchat_serv_attrs_cb *)hook->callback) (word, word_eol, attrs, hook->userdata); + break; default: /*case HOOK_PRINT:*/ ret = ((hexchat_print_cb *)hook->callback) (word, hook->userdata); break; @@ -606,7 +624,7 @@ xit: int plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[]) { - return plugin_hook_run (sess, name, word, word_eol, HOOK_COMMAND); + return plugin_hook_run (sess, name, word, word_eol, NULL, HOOK_COMMAND); } /* got a server PRIVMSG, NOTICE, numeric etc... */ @@ -614,7 +632,18 @@ 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[]) { - return plugin_hook_run (sess, name, word, word_eol, HOOK_SERVER); + return plugin_hook_run (sess, name, word, word_eol, NULL, HOOK_SERVER); +} + +int +plugin_emit_server_attr (session *sess, char *name, char *word[], char *word_eol[], + time_t server_time) +{ + hexchat_event_attrs attrs; + + attrs.server_time_utc=server_time; + + return plugin_hook_run (sess, name, word, word_eol, &attrs, HOOK_SERVER_ATTRS); } /* see if any plugins are interested in this print event */ @@ -622,7 +651,17 @@ plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[]) int plugin_emit_print (session *sess, char *word[]) { - return plugin_hook_run (sess, word[0], word, NULL, HOOK_PRINT); + return plugin_hook_run (sess, word[0], word, NULL, NULL, HOOK_PRINT); +} + +int +plugin_emit_print_attr (session *sess, char *word[], time_t server_time) +{ + hexchat_event_attrs attrs; + + attrs.server_time_utc=server_time; + + return plugin_hook_run (sess, word[0], word, NULL, &attrs, HOOK_PRINT_ATTRS); } int @@ -635,7 +674,7 @@ plugin_emit_dummy_print (session *sess, char *name) for (i = 1; i < 32; i++) word[i] = "\000"; - return plugin_hook_run (sess, name, word, NULL, HOOK_PRINT); + return plugin_hook_run (sess, name, word, NULL, NULL, HOOK_PRINT); } int @@ -663,7 +702,7 @@ plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval, for (i = 5; i < PDIWORDS; i++) word[i] = "\000"; - return plugin_hook_run (sess, word[0], word, NULL, HOOK_PRINT); + return plugin_hook_run (sess, word[0], word, NULL, NULL, HOOK_PRINT); } static int @@ -868,6 +907,14 @@ hexchat_hook_server (hexchat_plugin *ph, const char *name, int pri, return plugin_add_hook (ph, HOOK_SERVER, pri, name, 0, callb, 0, userdata); } +hexchat_hook * +hexchat_hook_server_attrs (hexchat_plugin *ph, const char *name, int pri, + hexchat_serv_attrs_cb *callb, void *userdata) +{ + return plugin_add_hook (ph, HOOK_SERVER_ATTRS, pri, name, 0, callb, 0, + userdata); +} + hexchat_hook * hexchat_hook_print (hexchat_plugin *ph, const char *name, int pri, hexchat_print_cb *callb, void *userdata) @@ -875,6 +922,14 @@ hexchat_hook_print (hexchat_plugin *ph, const char *name, int pri, return plugin_add_hook (ph, HOOK_PRINT, pri, name, 0, callb, 0, userdata); } +hexchat_hook * +hexchat_hook_print_attrs (hexchat_plugin *ph, const char *name, int pri, + hexchat_print_attrs_cb *callb, void *userdata) +{ + return plugin_add_hook (ph, HOOK_PRINT_ATTRS, pri, name, 0, callb, 0, + userdata); +} + hexchat_hook * hexchat_hook_timer (hexchat_plugin *ph, int timeout, hexchat_timer_cb *callb, void *userdata) diff --git a/src/common/plugin.h b/src/common/plugin.h index dd878895..d299e5af 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -132,6 +132,18 @@ struct _hexchat_plugin const char *var); int (*hexchat_pluginpref_list) (hexchat_plugin *ph, char *dest); + hexchat_hook *(*hexchat_hook_server_attrs) (hexchat_plugin *ph, + const char *name, + int pri, + int (*callback) (char *word[], char *word_eol[], + hexchat_event_attrs *attrs, void *user_data), + void *userdata); + hexchat_hook *(*hexchat_hook_print_attrs) (hexchat_plugin *ph, + const char *name, + int pri, + int (*callback) (char *word[], hexchat_event_attrs *attrs, + void *user_data), + void *userdata); void *(*hexchat_dummy4) (hexchat_plugin *ph); void *(*hexchat_dummy3) (hexchat_plugin *ph); void *(*hexchat_dummy2) (hexchat_plugin *ph); @@ -156,7 +168,10 @@ void plugin_kill_all (void); void plugin_auto_load (session *sess); 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_attr (session *sess, char *name, char *word[], + char *word_eol[], time_t server_time); int plugin_emit_print (session *sess, char *word[]); +int plugin_emit_print_attr (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, int len, char *string); GList* plugin_command_list(GList *tmp_list); -- cgit 1.4.1 From 98aa62f637d4ced952a168cb19f8d2fb038c6a16 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 9 Jul 2013 22:04:07 +0100 Subject: Removed two dummy functions in plugin interface. --- src/common/plugin.c | 2 -- src/common/plugin.h | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/plugin.c b/src/common/plugin.c index 90c6bbc4..abdd6ea1 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -302,8 +302,6 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func, pl->hexchat_hook_print_attrs = hexchat_hook_print_attrs; /* incase new plugins are loaded on older HexChat */ - pl->hexchat_dummy4 = hexchat_dummy; - pl->hexchat_dummy3 = hexchat_dummy; pl->hexchat_dummy2 = hexchat_dummy; pl->hexchat_dummy1 = hexchat_dummy; diff --git a/src/common/plugin.h b/src/common/plugin.h index d299e5af..32072b7d 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -144,10 +144,12 @@ struct _hexchat_plugin int (*callback) (char *word[], hexchat_event_attrs *attrs, void *user_data), void *userdata); - void *(*hexchat_dummy4) (hexchat_plugin *ph); - void *(*hexchat_dummy3) (hexchat_plugin *ph); + + /* If you add new functions here you should remove the corresponding number + * of dummy functions bellow. */ void *(*hexchat_dummy2) (hexchat_plugin *ph); void *(*hexchat_dummy1) (hexchat_plugin *ph); + /* PRIVATE FIELDS! */ void *handle; /* from dlopen */ char *filename; /* loaded from */ -- cgit 1.4.1 From 7101b7b864df280059750c0de4d6b9d41e907122 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 9 Jul 2013 23:11:28 +0100 Subject: Now hexchat_hook_server_attrs() and hexchat_hook_print_attrs() is called when it should. This should close #661. --- src/common/dcc.c | 3 ++- src/common/hexchat-plugin.h | 7 ++++++- src/common/plugin.c | 9 ++------- src/common/plugin.h | 6 +++--- src/common/proto-irc.c | 13 +++++++++++-- src/common/text.c | 4 +++- src/version-script | 2 ++ 7 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/common/dcc.c b/src/common/dcc.c index c0527510..1137c444 100644 --- a/src/common/dcc.c +++ b/src/common/dcc.c @@ -548,7 +548,8 @@ dcc_chat_line (struct DCC *dcc, char *line) for (i = 5; i < PDIWORDS; i++) word[i] = "\000"; - ret = plugin_emit_print (sess, word); + ret = plugin_emit_print (sess, word) + + plugin_emit_print_attrs (sess, word, 0); /* did the plugin close it? */ if (!g_slist_find (dcc_list, dcc)) diff --git a/src/common/hexchat-plugin.h b/src/common/hexchat-plugin.h index fd730459..f5583e2a 100644 --- a/src/common/hexchat-plugin.h +++ b/src/common/hexchat-plugin.h @@ -46,10 +46,13 @@ extern "C" { typedef struct _hexchat_plugin hexchat_plugin; typedef struct _hexchat_list hexchat_list; typedef struct _hexchat_hook hexchat_hook; -typedef struct _hexchat_event_attrs hexchat_event_attrs; #ifndef PLUGIN_C typedef struct _hexchat_context hexchat_context; #endif +typedef struct +{ + time_t server_time_utc; /* 0 if not used */ +} hexchat_event_attrs; #ifndef PLUGIN_C struct _hexchat_plugin @@ -381,7 +384,9 @@ hexchat_pluginpref_list (hexchat_plugin *ph, #endif #define hexchat_hook_command ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_command) #define hexchat_hook_server ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_server) +#define hexchat_hook_server_attrs ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_server_attrs) #define hexchat_hook_print ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_print) +#define hexchat_hook_print_attrs ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_print_attrs) #define hexchat_hook_timer ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_timer) #define hexchat_hook_fd ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_fd) #define hexchat_unhook ((HEXCHAT_PLUGIN_HANDLE)->hexchat_unhook) diff --git a/src/common/plugin.c b/src/common/plugin.c index abdd6ea1..ee7c7179 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -74,11 +74,6 @@ struct _hexchat_hook int pri; /* fd */ /* priority / fd for HOOK_FD only */ }; -struct _hexchat_event_attrs -{ - time_t server_time_utc; /* 0 if not used */ -}; - struct _hexchat_list { int type; /* LIST_* */ @@ -634,7 +629,7 @@ plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[]) } int -plugin_emit_server_attr (session *sess, char *name, char *word[], char *word_eol[], +plugin_emit_server_attrs (session *sess, char *name, char *word[], char *word_eol[], time_t server_time) { hexchat_event_attrs attrs; @@ -653,7 +648,7 @@ plugin_emit_print (session *sess, char *word[]) } int -plugin_emit_print_attr (session *sess, char *word[], time_t server_time) +plugin_emit_print_attrs (session *sess, char *word[], time_t server_time) { hexchat_event_attrs attrs; diff --git a/src/common/plugin.h b/src/common/plugin.h index 32072b7d..9af54426 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -170,10 +170,10 @@ void plugin_kill_all (void); void plugin_auto_load (session *sess); 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_attr (session *sess, char *name, char *word[], - char *word_eol[], time_t server_time); +int plugin_emit_server_attrs (session *sess, char *name, char *word[], + char *word_eol[], time_t server_time); int plugin_emit_print (session *sess, char *word[]); -int plugin_emit_print_attr (session *sess, char *word[], time_t server_time); +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_keypress (session *sess, unsigned int state, unsigned int keyval, int len, char *string); GList* plugin_command_list(GList *tmp_list); diff --git a/src/common/proto-irc.c b/src/common/proto-irc.c index bea9f6f7..07c2b696 100644 --- a/src/common/proto-irc.c +++ b/src/common/proto-irc.c @@ -1506,15 +1506,24 @@ irc_inline (server *serv, char *buf, int len) word[0] = type; word_eol[1] = buf; /* keep the ":" for plugins */ - if (plugin_emit_server (sess, type, word, word_eol)) + + /* don't use || here, since it might short-circuit */ + if (plugin_emit_server (sess, type, word, word_eol) + + plugin_emit_server_attrs (sess, type, word, word_eol, + tags_data.timestamp)) goto xit; + word[1]++; word_eol[1] = buf + 1; /* but not for HexChat internally */ } else { word[0] = type = word[1]; - if (plugin_emit_server (sess, type, word, word_eol)) + + /* don't use || here, since it might short-circuit */ + if (plugin_emit_server (sess, type, word, word_eol) + + plugin_emit_server_attrs (sess, type, word, word_eol, + tags_data.timestamp)) goto xit; } diff --git a/src/common/text.c b/src/common/text.c index a0e860ce..f251283b 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -2086,7 +2086,9 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d, for (i = 5; i < PDIWORDS; i++) word[i] = "\000"; - if (plugin_emit_print (sess, word)) + /* don't use || here, since it might short-circuit */ + if (plugin_emit_print (sess, word) + + plugin_emit_print_attrs (sess, word, timestamp)) return; /* If a plugin's callback executes "/close", 'sess' may be invalid */ diff --git a/src/version-script b/src/version-script index a98651db..0e442389 100644 --- a/src/version-script +++ b/src/version-script @@ -2,7 +2,9 @@ EXPORTED { global: hexchat_hook_command; hexchat_hook_server; + hexchat_hook_server_attrs; hexchat_hook_print; + hexchat_hook_print_attrs; hexchat_hook_timer; hexchat_hook_fd; hexchat_unhook; -- cgit 1.4.1 From 5e240eb259c473dd5ef25a5d11ef5ad574470f3a Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 10 Jul 2013 00:42:34 +0100 Subject: Indentation fixes and code cleanup. --- src/common/plugin.c | 6 +++--- src/common/proto-irc.c | 24 ++++++++++++++++-------- src/common/text.c | 8 ++++++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/common/plugin.c b/src/common/plugin.c index ee7c7179..8e39f653 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -630,11 +630,11 @@ plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[]) int plugin_emit_server_attrs (session *sess, char *name, char *word[], char *word_eol[], - time_t server_time) + time_t server_time) { 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); } @@ -652,7 +652,7 @@ plugin_emit_print_attrs (session *sess, char *word[], time_t server_time) { 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); } diff --git a/src/common/proto-irc.c b/src/common/proto-irc.c index 07c2b696..128c0c85 100644 --- a/src/common/proto-irc.c +++ b/src/common/proto-irc.c @@ -1493,6 +1493,9 @@ irc_inline (server *serv, char *buf, int len) if (buf[0] == ':') { + int eat1; + int eat2; + /* find a context for this message */ if (is_channel (serv, word[3])) { @@ -1507,10 +1510,11 @@ irc_inline (server *serv, char *buf, int len) word[0] = type; word_eol[1] = buf; /* keep the ":" for plugins */ - /* don't use || here, since it might short-circuit */ - if (plugin_emit_server (sess, type, word, word_eol) - + plugin_emit_server_attrs (sess, type, word, word_eol, - tags_data.timestamp)) + eat1 = plugin_emit_server (sess, type, word, word_eol); + eat2 = plugin_emit_server_attrs (sess, type, word, word_eol, + tags_data.timestamp); + + if (eat1 || eat2) goto xit; word[1]++; @@ -1518,12 +1522,16 @@ irc_inline (server *serv, char *buf, int len) } else { + int eat1; + int eat2; + word[0] = type = word[1]; - /* don't use || here, since it might short-circuit */ - if (plugin_emit_server (sess, type, word, word_eol) - + plugin_emit_server_attrs (sess, type, word, word_eol, - tags_data.timestamp)) + eat1 = plugin_emit_server (sess, type, word, word_eol); + eat2 = plugin_emit_server_attrs (sess, type, word, word_eol, + tags_data.timestamp); + + if (eat1 || eat2) goto xit; } diff --git a/src/common/text.c b/src/common/text.c index f251283b..94744e86 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -2070,6 +2070,8 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d, int i; unsigned int stripcolor_args = (chanopt_is_set (prefs.hex_text_stripcolor_msg, sess->text_strip) ? 0xFFFFFFFF : 0); char tbuf[NICKLEN + 4]; + int eat1; + int eat2; if (prefs.hex_text_color_nicks && (index == XP_TE_CHANACTION || index == XP_TE_CHANMSG)) { @@ -2086,9 +2088,11 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d, for (i = 5; i < PDIWORDS; i++) word[i] = "\000"; + eat1 = plugin_emit_print (sess, word); + eat2 = plugin_emit_print_attrs (sess, word, timestamp); + /* don't use || here, since it might short-circuit */ - if (plugin_emit_print (sess, word) - + plugin_emit_print_attrs (sess, word, timestamp)) + if (eat1 || eat2) return; /* If a plugin's callback executes "/close", 'sess' may be invalid */ -- cgit 1.4.1 From e0fb3d537d86001a8ccc5cc1c90a0ecc4f6a8d92 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Fri, 12 Jul 2013 01:33:35 +0100 Subject: Added hexchat_emit_print_attrs() to plugin interface. --- src/common/hexchat-plugin.h | 6 ++++++ src/common/plugin.c | 34 +++++++++++++++++++++++++++++++--- src/common/plugin.h | 6 +++--- src/common/text.c | 5 +++-- src/common/text.h | 3 ++- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/common/hexchat-plugin.h b/src/common/hexchat-plugin.h index f5583e2a..db2630f7 100644 --- a/src/common/hexchat-plugin.h +++ b/src/common/hexchat-plugin.h @@ -180,6 +180,8 @@ struct _hexchat_plugin int (*callback) (char *word[], hexchat_event_attrs *attrs, void *user_data), void *userdata); + int (*hexchat_emit_print_attrs) (hexchat_plugin *ph, hexchat_event_attrs *attrs, + const char *event_name, ...); }; #endif @@ -330,6 +332,10 @@ int hexchat_emit_print (hexchat_plugin *ph, const char *event_name, ...); +int +hexchat_emit_print_attrs (hexchat_plugin *ph, hexchat_event_attrs *attrs, + const char *event_name, ...); + char * hexchat_gettext (hexchat_plugin *ph, const char *msgid); diff --git a/src/common/plugin.c b/src/common/plugin.c index 8e39f653..8fd6805b 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -295,9 +295,9 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func, pl->hexchat_pluginpref_list = hexchat_pluginpref_list; pl->hexchat_hook_server_attrs = hexchat_hook_server_attrs; pl->hexchat_hook_print_attrs = hexchat_hook_print_attrs; + pl->hexchat_emit_print_attrs = hexchat_emit_print_attrs; /* incase new plugins are loaded on older HexChat */ - pl->hexchat_dummy2 = hexchat_dummy; pl->hexchat_dummy1 = hexchat_dummy; /* run hexchat_plugin_init, if it returns 0, close the plugin */ @@ -1646,8 +1646,36 @@ hexchat_emit_print (hexchat_plugin *ph, const char *event_name, ...) break; } - i = text_emit_by_name ((char *)event_name, ph->context, argv[0], argv[1], - argv[2], argv[3]); + i = text_emit_by_name ((char *)event_name, ph->context, (time_t) 0, + argv[0], argv[1], argv[2], argv[3]); + va_end (args); + + return i; +} + +int +hexchat_emit_print_attrs (hexchat_plugin *ph, hexchat_event_attrs *attrs, + const char *event_name, ...) +{ + va_list args; + /* currently only 4 because no events use more than 4. + This can be easily expanded without breaking the API. */ + char *argv[4] = {NULL, NULL, NULL, NULL}; + int i = 0; + + va_start (args, event_name); + while (1) + { + argv[i] = va_arg (args, char *); + if (!argv[i]) + break; + i++; + if (i >= 4) + break; + } + + i = text_emit_by_name ((char *)event_name, ph->context, attrs->server_time_utc, + argv[0], argv[1], argv[2], argv[3]); va_end (args); return i; diff --git a/src/common/plugin.h b/src/common/plugin.h index 9af54426..3cb97866 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -144,10 +144,10 @@ struct _hexchat_plugin int (*callback) (char *word[], hexchat_event_attrs *attrs, void *user_data), void *userdata); + int (*hexchat_emit_print_attrs) (hexchat_plugin *ph, hexchat_event_attrs *attrs, + const char *event_name, ...); - /* If you add new functions here you should remove the corresponding number - * of dummy functions bellow. */ - void *(*hexchat_dummy2) (hexchat_plugin *ph); + /* If you add a new function here you should remove the dummy function bellow. */ void *(*hexchat_dummy1) (hexchat_plugin *ph); /* PRIVATE FIELDS! */ diff --git a/src/common/text.c b/src/common/text.c index 94744e86..2f4323a2 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -2164,14 +2164,15 @@ text_find_format_string (char *name) } int -text_emit_by_name (char *name, session *sess, char *a, char *b, char *c, char *d) +text_emit_by_name (char *name, session *sess, time_t timestamp, + char *a, char *b, char *c, char *d) { int i = 0; i = pevent_find (name, &i); if (i >= 0) { - text_emit (i, sess, a, b, c, d, 0); + text_emit (i, sess, a, b, c, d, timestamp); return 1; } diff --git a/src/common/text.h b/src/common/text.h index 5a51c894..a9fd9d4e 100644 --- a/src/common/text.h +++ b/src/common/text.h @@ -55,7 +55,8 @@ void pevent_make_pntevts (void); int text_color_of (char *name); void text_emit (int index, session *sess, char *a, char *b, char *c, char *d, time_t timestamp); -int text_emit_by_name (char *name, session *sess, char *a, char *b, char *c, char *d); +int text_emit_by_name (char *name, session *sess, time_t timestamp, + char *a, char *b, char *c, char *d); char *text_validate (char **text, int *len); int get_stamp_str (char *fmt, time_t tim, char **ret); void format_event (session *sess, int index, char **args, char *o, int sizeofo, unsigned int stripcolor_args); -- cgit 1.4.1 From 18eaccb8405076b9de0f83f38d44c610528c1a63 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Fri, 12 Jul 2013 22:15:17 +0100 Subject: Added functions to create/destroy event_attrs to plugin interface. Function names were chosen to keep consistency with the rest of the API. --- src/common/hexchat-plugin.h | 10 +++++++++- src/common/plugin.c | 27 +++++++++++++++++++++++---- src/common/plugin.h | 6 +++--- src/version-script | 3 +++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/common/hexchat-plugin.h b/src/common/hexchat-plugin.h index db2630f7..d706cf85 100644 --- a/src/common/hexchat-plugin.h +++ b/src/common/hexchat-plugin.h @@ -182,6 +182,9 @@ struct _hexchat_plugin void *userdata); int (*hexchat_emit_print_attrs) (hexchat_plugin *ph, hexchat_event_attrs *attrs, const char *event_name, ...); + hexchat_event_attrs *(*hexchat_event_attrs_create) (hexchat_plugin *ph); + void (*hexchat_event_attrs_free) (hexchat_plugin *ph, + hexchat_event_attrs *attrs); }; #endif @@ -194,6 +197,10 @@ hexchat_hook_command (hexchat_plugin *ph, const char *help_text, void *userdata); +hexchat_event_attrs *hexchat_event_attrs_create (hexchat_plugin *ph); + +void hexchat_event_attrs_free (hexchat_plugin *ph, hexchat_event_attrs *attrs); + hexchat_hook * hexchat_hook_server (hexchat_plugin *ph, const char *name, @@ -201,7 +208,6 @@ hexchat_hook_server (hexchat_plugin *ph, int (*callback) (char *word[], char *word_eol[], void *user_data), void *userdata); - hexchat_hook * hexchat_hook_server_attrs (hexchat_plugin *ph, const char *name, @@ -389,6 +395,8 @@ hexchat_pluginpref_list (hexchat_plugin *ph, #define HEXCHAT_PLUGIN_HANDLE (ph) #endif #define hexchat_hook_command ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_command) +#define hexchat_event_attrs_create ((HEXCHAT_PLUGIN_HANDLE)->hexchat_event_attrs_create) +#define hexchat_event_attrs_free ((HEXCHAT_PLUGIN_HANDLE)->hexchat_event_attrs_free) #define hexchat_hook_server ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_server) #define hexchat_hook_server_attrs ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_server_attrs) #define hexchat_hook_print ((HEXCHAT_PLUGIN_HANDLE)->hexchat_hook_print) diff --git a/src/common/plugin.c b/src/common/plugin.c index 8fd6805b..6edc9926 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -296,9 +296,8 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func, pl->hexchat_hook_server_attrs = hexchat_hook_server_attrs; pl->hexchat_hook_print_attrs = hexchat_hook_print_attrs; pl->hexchat_emit_print_attrs = hexchat_emit_print_attrs; - - /* incase new plugins are loaded on older HexChat */ - pl->hexchat_dummy1 = hexchat_dummy; + pl->hexchat_event_attrs_create = hexchat_event_attrs_create; + pl->hexchat_event_attrs_free = hexchat_event_attrs_free; /* run hexchat_plugin_init, if it returns 0, close the plugin */ if (((hexchat_init_func *)init_func) (pl, &pl->name, &pl->desc, &pl->version, arg) == 0) @@ -620,8 +619,28 @@ plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[]) return plugin_hook_run (sess, name, word, word_eol, NULL, HOOK_COMMAND); } -/* got a server PRIVMSG, NOTICE, numeric etc... */ +hexchat_event_attrs * +hexchat_event_attrs_create (hexchat_plugin *ph) +{ + hexchat_event_attrs *attrs; + + attrs = malloc (sizeof (*attrs)); + + if (attrs == NULL) + return NULL; + + attrs->server_time_utc = (time_t) 0; + return attrs; +} + +void +hexchat_event_attrs_free (hexchat_plugin *ph, hexchat_event_attrs *attrs) +{ + g_free (attrs); +} + +/* got a server PRIVMSG, NOTICE, numeric etc... */ int plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[]) { diff --git a/src/common/plugin.h b/src/common/plugin.h index 3cb97866..f75639e9 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -146,9 +146,9 @@ struct _hexchat_plugin void *userdata); int (*hexchat_emit_print_attrs) (hexchat_plugin *ph, hexchat_event_attrs *attrs, const char *event_name, ...); - - /* If you add a new function here you should remove the dummy function bellow. */ - void *(*hexchat_dummy1) (hexchat_plugin *ph); + hexchat_event_attrs *(*hexchat_event_attrs_create) (hexchat_plugin *ph); + void (*hexchat_event_attrs_free) (hexchat_plugin *ph, + hexchat_event_attrs *attrs); /* PRIVATE FIELDS! */ void *handle; /* from dlopen */ diff --git a/src/version-script b/src/version-script index 0e442389..a7ed1495 100644 --- a/src/version-script +++ b/src/version-script @@ -1,6 +1,8 @@ EXPORTED { global: hexchat_hook_command; + hexchat_event_attrs_create; + hexchat_event_attrs_free; hexchat_hook_server; hexchat_hook_server_attrs; hexchat_hook_print; @@ -27,6 +29,7 @@ EXPORTED { hexchat_plugingui_add; hexchat_plugingui_remove; hexchat_emit_print; + hexchat_emit_print_attrs; hexchat_list_time; hexchat_gettext; hexchat_send_modes; -- cgit 1.4.1 From 9978ebd8539f5150478b9227404bf2a810d825b9 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Fri, 12 Jul 2013 22:52:12 +0100 Subject: Removed outdated comment. --- src/common/text.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/text.c b/src/common/text.c index 2f4323a2..b825faba 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -2091,7 +2091,6 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d, eat1 = plugin_emit_print (sess, word); eat2 = plugin_emit_print_attrs (sess, word, timestamp); - /* don't use || here, since it might short-circuit */ if (eat1 || eat2) return; -- cgit 1.4.1 From ec6f5b011a440146401e6584d3f5881e2f554054 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 13 Jul 2013 05:33:16 +0100 Subject: g_free() should be used for g_malloc(). --- src/common/plugin.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/common/plugin.c b/src/common/plugin.c index 6edc9926..7d118b8b 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -624,10 +624,7 @@ hexchat_event_attrs_create (hexchat_plugin *ph) { hexchat_event_attrs *attrs; - attrs = malloc (sizeof (*attrs)); - - if (attrs == NULL) - return NULL; + attrs = g_malloc (sizeof (*attrs)); attrs->server_time_utc = (time_t) 0; -- cgit 1.4.1 From 35989660692d5550808eeec066d52043431484cc Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 13 Jul 2013 16:50:43 +0100 Subject: Forgot to add hexchat_emit_print_attrs() to the macros in hexchat-plugins.h. --- src/common/hexchat-plugin.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/hexchat-plugin.h b/src/common/hexchat-plugin.h index d706cf85..61597181 100644 --- a/src/common/hexchat-plugin.h +++ b/src/common/hexchat-plugin.h @@ -423,6 +423,7 @@ hexchat_pluginpref_list (hexchat_plugin *ph, #define hexchat_plugingui_add ((HEXCHAT_PLUGIN_HANDLE)->hexchat_plugingui_add) #define hexchat_plugingui_remove ((HEXCHAT_PLUGIN_HANDLE)->hexchat_plugingui_remove) #define hexchat_emit_print ((HEXCHAT_PLUGIN_HANDLE)->hexchat_emit_print) +#define hexchat_emit_print_attrs ((HEXCHAT_PLUGIN_HANDLE)->hexchat_emit_print_attrs) #define hexchat_list_time ((HEXCHAT_PLUGIN_HANDLE)->hexchat_list_time) #define hexchat_gettext ((HEXCHAT_PLUGIN_HANDLE)->hexchat_gettext) #define hexchat_send_modes ((HEXCHAT_PLUGIN_HANDLE)->hexchat_send_modes) -- cgit 1.4.1