diff options
Diffstat (limited to 'src/plugins/irc/irc-server.c')
-rw-r--r-- | src/plugins/irc/irc-server.c | 43 |
1 files changed, 43 insertions, 0 deletions
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 |