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.)
This commit is contained in:
Diogo Sousa 2013-07-09 20:21:16 +01:00
parent 1544a5d6cb
commit 798db7368a
3 changed files with 112 additions and 12 deletions

View File

@ -46,6 +46,7 @@ extern "C" {
typedef struct _hexchat_plugin hexchat_plugin; typedef struct _hexchat_plugin hexchat_plugin;
typedef struct _hexchat_list hexchat_list; typedef struct _hexchat_list hexchat_list;
typedef struct _hexchat_hook hexchat_hook; typedef struct _hexchat_hook hexchat_hook;
typedef struct _hexchat_event_attrs hexchat_event_attrs;
#ifndef PLUGIN_C #ifndef PLUGIN_C
typedef struct _hexchat_context hexchat_context; typedef struct _hexchat_context hexchat_context;
#endif #endif
@ -164,6 +165,18 @@ struct _hexchat_plugin
const char *var); const char *var);
int (*hexchat_pluginpref_list) (hexchat_plugin *ph, int (*hexchat_pluginpref_list) (hexchat_plugin *ph,
char *dest); 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 #endif
@ -183,6 +196,15 @@ hexchat_hook_server (hexchat_plugin *ph,
int (*callback) (char *word[], char *word_eol[], void *user_data), int (*callback) (char *word[], char *word_eol[], void *user_data),
void *userdata); 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 *
hexchat_hook_print (hexchat_plugin *ph, hexchat_hook_print (hexchat_plugin *ph,
const char *name, const char *name,
@ -190,6 +212,14 @@ hexchat_hook_print (hexchat_plugin *ph,
int (*callback) (char *word[], void *user_data), int (*callback) (char *word[], void *user_data),
void *userdata); 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 *
hexchat_hook_timer (hexchat_plugin *ph, hexchat_hook_timer (hexchat_plugin *ph,
int timeout, int timeout,

View File

@ -74,6 +74,11 @@ struct _hexchat_hook
int pri; /* fd */ /* priority / fd for HOOK_FD only */ 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 struct _hexchat_list
{ {
int type; /* 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_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_serv_cb) (char *word[], char *word_eol[], void *user_data);
typedef int (hexchat_print_cb) (char *word[], 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_fd_cb) (int fd, int flags, void *user_data);
typedef int (hexchat_timer_cb) (void *user_data); typedef int (hexchat_timer_cb) (void *user_data);
typedef int (hexchat_init_func) (hexchat_plugin *, char **, char **, char **, char *); typedef int (hexchat_init_func) (hexchat_plugin *, char **, char **, char **, char *);
@ -102,12 +109,14 @@ enum
enum enum
{ {
HOOK_COMMAND, /* /command */ HOOK_COMMAND, /* /command */
HOOK_SERVER, /* PRIVMSG, NOTICE, numerics */ HOOK_SERVER, /* PRIVMSG, NOTICE, numerics */
HOOK_PRINT, /* All print events */ HOOK_SERVER_ATTRS, /* same as above, with attributes */
HOOK_TIMER, /* timeouts */ HOOK_PRINT, /* All print events */
HOOK_FD, /* sockets & fds */ HOOK_PRINT_ATTRS, /* same as above, with attributes */
HOOK_DELETED /* marked for deletion */ HOOK_TIMER, /* timeouts */
HOOK_FD, /* sockets & fds */
HOOK_DELETED /* marked for deletion */
}; };
GSList *plugin_list = NULL; /* export for plugingui.c */ 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_get_int = hexchat_pluginpref_get_int;
pl->hexchat_pluginpref_delete = hexchat_pluginpref_delete; pl->hexchat_pluginpref_delete = hexchat_pluginpref_delete;
pl->hexchat_pluginpref_list = hexchat_pluginpref_list; 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 */ /* incase new plugins are loaded on older HexChat */
pl->hexchat_dummy4 = hexchat_dummy; 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 */ /* check for plugin hooks and run them */
static int 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; GSList *list, *next;
hexchat_hook *hook; hexchat_hook *hook;
@ -562,9 +574,15 @@ plugin_hook_run (session *sess, char *name, char *word[], char *word_eol[], int
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);
break; break;
case HOOK_PRINT_ATTRS:
ret = ((hexchat_print_attrs_cb *)hook->callback) (word, attrs, hook->userdata);
break;
case HOOK_SERVER: case HOOK_SERVER:
ret = ((hexchat_serv_cb *)hook->callback) (word, word_eol, hook->userdata); ret = ((hexchat_serv_cb *)hook->callback) (word, word_eol, hook->userdata);
break; break;
case HOOK_SERVER_ATTRS:
ret = ((hexchat_serv_attrs_cb *)hook->callback) (word, word_eol, attrs, hook->userdata);
break;
default: /*case HOOK_PRINT:*/ default: /*case HOOK_PRINT:*/
ret = ((hexchat_print_cb *)hook->callback) (word, hook->userdata); ret = ((hexchat_print_cb *)hook->callback) (word, hook->userdata);
break; break;
@ -606,7 +624,7 @@ xit:
int int
plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[]) 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... */ /* got a server PRIVMSG, NOTICE, numeric etc... */
@ -614,7 +632,18 @@ plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[])
int int
plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[]) 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 */ /* 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 int
plugin_emit_print (session *sess, char *word[]) 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 int
@ -635,7 +674,7 @@ plugin_emit_dummy_print (session *sess, char *name)
for (i = 1; i < 32; i++) for (i = 1; i < 32; i++)
word[i] = "\000"; 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 int
@ -663,7 +702,7 @@ plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval,
for (i = 5; i < PDIWORDS; i++) for (i = 5; i < PDIWORDS; i++)
word[i] = "\000"; 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 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); 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 *
hexchat_hook_print (hexchat_plugin *ph, const char *name, int pri, hexchat_hook_print (hexchat_plugin *ph, const char *name, int pri,
hexchat_print_cb *callb, void *userdata) 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); 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 *
hexchat_hook_timer (hexchat_plugin *ph, int timeout, hexchat_timer_cb *callb, hexchat_hook_timer (hexchat_plugin *ph, int timeout, hexchat_timer_cb *callb,
void *userdata) void *userdata)

View File

@ -132,6 +132,18 @@ struct _hexchat_plugin
const char *var); const char *var);
int (*hexchat_pluginpref_list) (hexchat_plugin *ph, int (*hexchat_pluginpref_list) (hexchat_plugin *ph,
char *dest); 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_dummy4) (hexchat_plugin *ph);
void *(*hexchat_dummy3) (hexchat_plugin *ph); void *(*hexchat_dummy3) (hexchat_plugin *ph);
void *(*hexchat_dummy2) (hexchat_plugin *ph); void *(*hexchat_dummy2) (hexchat_plugin *ph);
@ -156,7 +168,10 @@ 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_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 (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_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);