summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-08-27 15:59:06 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-08-27 15:59:06 +0200
commit712623547f7e6fffc1bda625399ac54de87b6e2d (patch)
tree7353e6aec83c944eaa7b8af24694015b13f7715f /src/plugins/irc
parentbb42984f5d6101ddc750700768ed3faf27f31021 (diff)
downloadweechat-712623547f7e6fffc1bda625399ac54de87b6e2d.zip
Add new functions in plugin API (hashtable_get_string, hook_info_hashtable, info_get_hashtable), add IRC info_hashtable "irc_parse_message"
Note: tcl >= 8.5 is now required (for tcl plugin).
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-info.c81
-rw-r--r--src/plugins/irc/irc-server.c43
-rw-r--r--src/plugins/irc/irc-server.h1
3 files changed, 112 insertions, 13 deletions
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c
index 4f1602e1a..3a6c8849a 100644
--- a/src/plugins/irc/irc-info.c
+++ b/src/plugins/irc/irc-info.c
@@ -229,6 +229,38 @@ irc_info_get_info_cb (void *data, const char *info_name,
}
/*
+ * irc_info_get_info_hashtable_cb: callback called when IRC info_hashtable is
+ * asked
+ */
+
+struct t_hashtable *
+irc_info_get_info_hashtable_cb (void *data, const char *info_name,
+ struct t_hashtable *hashtable)
+{
+ const char *message;
+ struct t_hashtable *value;
+
+ /* make C compiler happy */
+ (void) data;
+
+ if (weechat_strcasecmp (info_name, "irc_parse_message") == 0)
+ {
+ if (hashtable)
+ {
+ message = (const char *)weechat_hashtable_get (hashtable,
+ "message");
+ if (message)
+ {
+ value = irc_server_parse_message_to_hashtable (message);
+ return value;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/*
* irc_info_get_infolist_cb: callback called when IRC infolist is asked
*/
@@ -448,48 +480,71 @@ void
irc_info_init ()
{
/* info hooks */
- weechat_hook_info ("irc_is_channel", N_("1 if string is a valid IRC channel name"),
+ weechat_hook_info ("irc_is_channel",
+ N_("1 if string is a valid IRC channel name"),
N_("channel name"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_is_nick", N_("1 if string is a valid IRC nick name"),
+ weechat_hook_info ("irc_is_nick",
+ N_("1 if string is a valid IRC nick name"),
N_("nickname"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_nick", N_("get current nick on a server"),
+ weechat_hook_info ("irc_nick",
+ N_("get current nick on a server"),
N_("server name"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_nick_from_host", N_("get nick from IRC host"),
+ weechat_hook_info ("irc_nick_from_host",
+ N_("get nick from IRC host"),
N_("IRC host (like `:nick!name@server.com`)"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_nick_color", N_("get nick color code"),
+ weechat_hook_info ("irc_nick_color",
+ N_("get nick color code"),
N_("nickname"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_nick_color_name", N_("get nick color name"),
+ weechat_hook_info ("irc_nick_color_name",
+ N_("get nick color name"),
N_("nickname"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_buffer", N_("get buffer pointer for an IRC server/channel/nick"),
+ weechat_hook_info ("irc_buffer",
+ N_("get buffer pointer for an IRC server/channel/nick"),
N_("server,channel,nick (channel and nicks are optional)"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_server_isupport", N_("1 if server supports this feature (from IRC message 005)"),
+ weechat_hook_info ("irc_server_isupport",
+ N_("1 if server supports this feature (from IRC message 005)"),
N_("server,feature"),
&irc_info_get_info_cb, NULL);
- weechat_hook_info ("irc_server_isupport_value", N_("value of feature, if supported by server (from IRC message 005)"),
+ weechat_hook_info ("irc_server_isupport_value",
+ N_("value of feature, if supported by server (from IRC message 005)"),
N_("server,feature"),
&irc_info_get_info_cb, NULL);
+ /* info_hashtable hooks */
+ weechat_hook_info_hashtable ("irc_parse_message",
+ N_("parse an IRC message"),
+ N_("\"message\": IRC message"),
+ /* TRANSLATORS: please do not translate key names (enclosed by quotes) */
+ N_("\"nick\": nick, \"host\": host, "
+ "\"command\": command, \"channel\": channel, "
+ "\"arguments\": arguments (includes channel)"),
+ &irc_info_get_info_hashtable_cb, NULL);
+
/* infolist hooks */
- weechat_hook_infolist ("irc_server", N_("list of IRC servers"),
+ weechat_hook_infolist ("irc_server",
+ N_("list of IRC servers"),
N_("server pointer (optional)"),
N_("server name (can start or end with \"*\" as wildcard) (optional)"),
&irc_info_get_infolist_cb, NULL);
- weechat_hook_infolist ("irc_channel", N_("list of channels for an IRC server"),
+ weechat_hook_infolist ("irc_channel",
+ N_("list of channels for an IRC server"),
N_("channel pointer (optional)"),
N_("server name"),
&irc_info_get_infolist_cb, NULL);
- weechat_hook_infolist ("irc_nick", N_("list of nicks for an IRC channel"),
+ weechat_hook_infolist ("irc_nick",
+ N_("list of nicks for an IRC channel"),
N_("nick pointer (optional)"),
N_("server,channel,nick (channel and nick are optional)"),
&irc_info_get_infolist_cb, NULL);
- weechat_hook_infolist ("irc_ignore", N_("list of IRC ignores"),
+ weechat_hook_infolist ("irc_ignore",
+ N_("list of IRC ignores"),
N_("ignore pointer (optional)"),
NULL,
&irc_info_get_infolist_cb, NULL);
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 75b117902..9c6322b31 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -1215,6 +1215,9 @@ irc_server_parse_message (const char *message, char **nick, char **host,
if (arguments)
*arguments = NULL;
+ if (!message)
+ return;
+
/*
* we will use this message as example:
* :FlashCode!n=FlashCod@host.com PRIVMSG #channel :hello!
@@ -1324,6 +1327,46 @@ irc_server_parse_message (const char *message, char **nick, char **host,
}
/*
+ * irc_server_parse_message_to_hashtable: parse IRC message and return hashtable
+ * with keys: nick, host, command,
+ * channel, arguments
+ * Note: hashtable has to be free()
+ * after use
+ */
+
+struct t_hashtable *
+irc_server_parse_message_to_hashtable (const char *message)
+{
+ char *nick, *host, *command, *channel, *arguments;
+ char empty_str[1] = { '\0' };
+ struct t_hashtable *hashtable;
+
+ irc_server_parse_message (message, &nick, &host, &command, &channel,
+ &arguments);
+
+ hashtable = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
+ if (!hashtable)
+ return NULL;
+
+ weechat_hashtable_set (hashtable, "nick",
+ (nick) ? (void *)nick : (void *)empty_str);
+ weechat_hashtable_set (hashtable, "host",
+ (host) ? (void *)host : (void *)empty_str);
+ weechat_hashtable_set (hashtable, "command",
+ (command) ? (void *)command : (void *)empty_str);
+ weechat_hashtable_set (hashtable, "channel",
+ (channel) ? (void *)channel : (void *)empty_str);
+ weechat_hashtable_set (hashtable, "arguments",
+ (arguments) ? (void *)arguments : (void *)empty_str);
+
+ return hashtable;
+}
+
+/*
* irc_server_send_one_msg: send one message to IRC server
* if queue_msg > 0, then messages are in a queue and
* sent slowly (to be sure there will not be any
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 8ca2615f8..02e6a8134 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -203,6 +203,7 @@ extern int irc_server_rename (struct t_irc_server *server, const char *new_name)
extern void irc_server_send_signal (struct t_irc_server *server,
const char *signal, const char *command,
const char *full_message);
+extern struct t_hashtable *irc_server_parse_message_to_hashtable (const char *message);
extern void irc_server_sendf (struct t_irc_server *server, int queue_msg,
const char *format, ...);
extern struct t_irc_server *irc_server_search (const char *server_name);