diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-11-21 13:06:37 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-11-21 13:06:37 +0100 |
commit | c2fda185d8170eb1e449b42d03d14ff77a0cad42 (patch) | |
tree | 61c24e1a7cd0a9f73b203851f77eb10d064f3f81 /src/plugins | |
parent | 428e160f026fe4225d9d77296386d8a799fe4a12 (diff) | |
download | weechat-c2fda185d8170eb1e449b42d03d14ff77a0cad42.zip |
Move some functions from irc-server.c and irc-protocol.c to irc-message.c
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/plugins/irc/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-info.c | 7 | ||||
-rw-r--r-- | src/plugins/irc/irc-message.c | 329 | ||||
-rw-r--r-- | src/plugins/irc/irc-message.h | 33 | ||||
-rw-r--r-- | src/plugins/irc/irc-notify.c | 9 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 164 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 180 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 4 |
10 files changed, 396 insertions, 334 deletions
diff --git a/src/plugins/irc/CMakeLists.txt b/src/plugins/irc/CMakeLists.txt index 98e21d45d..58774f4b5 100644 --- a/src/plugins/irc/CMakeLists.txt +++ b/src/plugins/irc/CMakeLists.txt @@ -32,6 +32,7 @@ irc-display.c irc-display.h irc-ignore.c irc-ignore.h irc-info.c irc-info.h irc-input.c irc-input.h +irc-message.c irc-message.h irc-mode.c irc-mode.h irc-msgbuffer.c irc-msgbuffer.h irc-nick.c irc-nick.h diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am index bd287713c..7ea340206 100644 --- a/src/plugins/irc/Makefile.am +++ b/src/plugins/irc/Makefile.am @@ -51,6 +51,8 @@ irc_la_SOURCES = irc.c \ irc-info.h \ irc-input.c \ irc-input.h \ + irc-message.c \ + irc-message.h \ irc-mode.c \ irc-mode.h \ irc-msgbuffer.c \ diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 8fb518b4b..db788d5c2 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -30,6 +30,7 @@ #include "irc-channel.h" #include "irc-config.h" #include "irc-ignore.h" +#include "irc-message.h" #include "irc-nick.h" #include "irc-notify.h" #include "irc-protocol.h" @@ -97,7 +98,7 @@ irc_info_get_info_cb (void *data, const char *info_name, } else if (weechat_strcasecmp (info_name, "irc_nick_from_host") == 0) { - return irc_protocol_get_nick_from_host (arguments); + return irc_message_get_nick_from_host (arguments); } else if (weechat_strcasecmp (info_name, "irc_nick_color") == 0) { @@ -149,7 +150,7 @@ irc_info_get_info_cb (void *data, const char *info_name, { free (channel); channel = NULL; - nick = irc_protocol_get_nick_from_host (host); + nick = irc_message_get_nick_from_host (host); if (nick) channel = strdup (nick); @@ -252,7 +253,7 @@ irc_info_get_info_hashtable_cb (void *data, const char *info_name, "message"); if (message) { - value = irc_server_parse_message_to_hashtable (message); + value = irc_message_parse_to_hashtable (message); return value; } } diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c new file mode 100644 index 000000000..8ec623509 --- /dev/null +++ b/src/plugins/irc/irc-message.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2003-2010 Sebastien Helleu <flashcode@flashtux.org> + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. + */ + +/* + * irc-message.c: functions for IRC messages + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "../weechat-plugin.h" +#include "irc.h" +#include "irc-server.h" +#include "irc-channel.h" + + +/* + * irc_message_parse: parse IRC message and return pointer to host, command, + * channel, target nick and arguments (if any) + */ + +void +irc_message_parse (const char *message, char **nick, char **host, + char **command, char **channel, char **arguments) +{ + const char *pos, *pos2, *pos3, *pos4, *pos5; + + if (nick) + *nick = NULL; + if (host) + *host = NULL; + if (command) + *command = NULL; + if (channel) + *channel = NULL; + if (arguments) + *arguments = NULL; + + if (!message) + return; + + /* + * we will use this message as example: + * :FlashCode!n=FlashCod@host.com PRIVMSG #channel :hello! + */ + if (message[0] == ':') + { + pos2 = strchr (message, '!'); + pos = strchr (message, ' '); + if (pos2 && (!pos || pos > pos2)) + { + if (nick) + *nick = weechat_strndup (message + 1, pos2 - (message + 1)); + } + else if (pos) + { + if (nick) + *nick = weechat_strndup (message + 1, pos - (message + 1)); + } + if (pos) + { + if (host) + *host = weechat_strndup (message + 1, pos - (message + 1)); + pos++; + } + else + pos = message; + } + else + pos = message; + + /* pos is pointer on PRIVMSG #channel :hello! */ + if (pos && pos[0]) + { + while (pos[0] == ' ') + { + pos++; + } + pos2 = strchr (pos, ' '); + if (pos2) + { + /* pos2 is pointer on #channel :hello! */ + if (command) + *command = weechat_strndup (pos, pos2 - pos); + pos2++; + while (pos2[0] == ' ') + { + pos2++; + } + if (arguments) + *arguments = strdup (pos2); + if (pos2[0] != ':') + { + if (irc_channel_is_channel (pos2)) + { + pos3 = strchr (pos2, ' '); + if (channel) + { + if (pos3) + *channel = weechat_strndup (pos2, pos3 - pos2); + else + *channel = strdup (pos2); + } + } + else + { + pos3 = strchr (pos2, ' '); + if (nick && !*nick) + { + if (pos3) + *nick = weechat_strndup (pos2, pos3 - pos2); + else + *nick = strdup (pos2); + } + if (pos3) + { + pos4 = pos3; + pos3++; + while (pos3[0] == ' ') + { + pos3++; + } + if (irc_channel_is_channel (pos3)) + { + pos5 = strchr (pos3, ' '); + if (channel) + { + if (pos5) + *channel = weechat_strndup (pos3, pos5 - pos3); + else + *channel = strdup (pos3); + } + } + else if (channel && !*channel) + { + *channel = weechat_strndup (pos2, pos4 - pos2); + } + } + } + } + } + else + { + if (command) + *command = strdup (pos); + } + } +} + +/* + * irc_message_parse_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_message_parse_to_hashtable (const char *message) +{ + char *nick, *host, *command, *channel, *arguments; + char empty_str[1] = { '\0' }; + struct t_hashtable *hashtable; + + irc_message_parse (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) ? nick : empty_str); + weechat_hashtable_set (hashtable, "host", (host) ? host : empty_str); + weechat_hashtable_set (hashtable, "command", (command) ? command : empty_str); + weechat_hashtable_set (hashtable, "channel", (channel) ? channel : empty_str); + weechat_hashtable_set (hashtable, "arguments", (arguments) ? arguments : empty_str); + + return hashtable; +} + +/* + * irc_message_get_nick_from_host: get nick from host in an IRC message + */ + +const char * +irc_message_get_nick_from_host (const char *host) +{ + static char nick[128]; + char host2[128], *pos_space, *pos; + const char *ptr_host; + + if (!host) + return NULL; + + nick[0] = '\0'; + if (host) + { + ptr_host = host; + pos_space = strchr (host, ' '); + if (pos_space) + { + if (pos_space - host < (int)sizeof (host2)) + { + strncpy (host2, host, pos_space - host); + host2[pos_space - host] = '\0'; + } + else + snprintf (host2, sizeof (host2), "%s", host); + ptr_host = host2; + } + + if (ptr_host[0] == ':') + ptr_host++; + + pos = strchr (ptr_host, '!'); + if (pos && (pos - ptr_host < (int)sizeof (nick))) + { + strncpy (nick, ptr_host, pos - ptr_host); + nick[pos - ptr_host] = '\0'; + } + else + { + snprintf (nick, sizeof (nick), "%s", ptr_host); + } + } + + return nick; +} + +/* + * irc_message_get_address_from_host: get address from host in an IRC message + */ + +const char * +irc_message_get_address_from_host (const char *host) +{ + static char address[256]; + char host2[256], *pos_space, *pos; + const char *ptr_host; + + address[0] = '\0'; + if (host) + { + ptr_host = host; + pos_space = strchr (host, ' '); + if (pos_space) + { + if (pos_space - host < (int)sizeof (host2)) + { + strncpy (host2, host, pos_space - host); + host2[pos_space - host] = '\0'; + } + else + snprintf (host2, sizeof (host2), "%s", host); + ptr_host = host2; + } + + if (ptr_host[0] == ':') + ptr_host++; + pos = strchr (ptr_host, '!'); + if (pos) + snprintf (address, sizeof (address), "%s", pos + 1); + else + snprintf (address, sizeof (address), "%s", ptr_host); + } + + return address; +} + +/* + * irc_message_replace_vars: replace special IRC vars ($nick, $channel, + * $server) in a string + * Note: result has to be free() after use + */ + +char * +irc_message_replace_vars (struct t_irc_server *server, + struct t_irc_channel *channel, const char *string) +{ + char *var_nick, *var_channel, *var_server; + char empty_string[1] = { '\0' }; + char *res, *temp; + + var_nick = (server && server->nick) ? server->nick : empty_string; + var_channel = (channel) ? channel->name : empty_string; + var_server = (server) ? server->name : empty_string; + + /* replace nick */ + temp = weechat_string_replace (string, "$nick", var_nick); + if (!temp) + return NULL; + res = temp; + + /* replace channel */ + temp = weechat_string_replace (res, "$channel", var_channel); + free (res); + if (!temp) + return NULL; + res = temp; + + /* replace server */ + temp = weechat_string_replace (res, "$server", var_server); + free (res); + if (!temp) + return NULL; + res = temp; + + /* return result */ + return res; +} diff --git a/src/plugins/irc/irc-message.h b/src/plugins/irc/irc-message.h new file mode 100644 index 000000000..19dd06361 --- /dev/null +++ b/src/plugins/irc/irc-message.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2003-2010 Sebastien Helleu <flashcode@flashtux.org> + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __WEECHAT_IRC_MESSAGE_H +#define __WEECHAT_IRC_MESSAGE_H 1 + +extern void irc_message_parse (const char *message, char **nick, char **host, + char **command, char **channel, + char **arguments); +extern struct t_hashtable *irc_message_parse_to_hashtable (const char *message); +extern const char *irc_message_get_nick_from_host (const char *host); +extern const char *irc_message_get_address_from_host (const char *host); +extern char *irc_message_replace_vars (struct t_irc_server *server, + struct t_irc_channel *channel, + const char *string); + +#endif /* __WEECHAT_IRC_MESSAGE_H */ diff --git a/src/plugins/irc/irc-notify.c b/src/plugins/irc/irc-notify.c index 97947bfed..8c11e6985 100644 --- a/src/plugins/irc/irc-notify.c +++ b/src/plugins/irc/irc-notify.c @@ -30,6 +30,7 @@ #include "irc-notify.h" #include "irc-color.h" #include "irc-config.h" +#include "irc-message.h" #include "irc-redirect.h" #include "irc-server.h" @@ -596,8 +597,8 @@ irc_notify_hsignal_cb (void *data, const char *signal, } for (i = 0; i < num_messages; i++) { - irc_server_parse_message (messages[i], NULL, NULL, NULL, NULL, - &arguments); + irc_message_parse (messages[i], NULL, NULL, NULL, NULL, + &arguments); if (arguments) { pos = strchr (arguments, ' '); @@ -672,8 +673,8 @@ irc_notify_hsignal_cb (void *data, const char *signal, { for (i = 0; i < num_messages; i++) { - irc_server_parse_message (messages[0], NULL, NULL, - &irc_cmd, NULL, &arguments); + irc_message_parse (messages[0], NULL, NULL, &irc_cmd, NULL, + &arguments); if (irc_cmd && arguments) { if (strcmp (irc_cmd, "401") == 0) diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index c07dd82f8..dce3c3ba3 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -44,6 +44,7 @@ #include "irc-config.h" #include "irc-ctcp.h" #include "irc-ignore.h" +#include "irc-message.h" #include "irc-mode.h" #include "irc-msgbuffer.h" #include "irc-nick.h" @@ -68,95 +69,6 @@ irc_protocol_is_numeric_command (const char *str) } /* - * irc_protocol_get_nick_from_host: get nick from host in an IRC message - */ - -const char * -irc_protocol_get_nick_from_host (const char *host) -{ - static char nick[128]; - char host2[128], *pos_space, *pos; - const char *ptr_host; - - if (!host) - return NULL; - - nick[0] = '\0'; - if (host) - { - ptr_host = host; - pos_space = strchr (host, ' '); - if (pos_space) - { - if (pos_space - host < (int)sizeof (host2)) - { - strncpy (host2, host, pos_space - host); - host2[pos_space - host] = '\0'; - } - else - snprintf (host2, sizeof (host2), "%s", host); - ptr_host = host2; - } - - if (ptr_host[0] == ':') - ptr_host++; - - pos = strchr (ptr_host, '!'); - if (pos && (pos - ptr_host < (int)sizeof (nick))) - { - strncpy (nick, ptr_host, pos - ptr_host); - nick[pos - ptr_host] = '\0'; - } - else - { - snprintf (nick, sizeof (nick), "%s", ptr_host); - } - } - - return nick; -} - -/* - * irc_protocol_get_address_from_host: get address from host in an IRC message - */ - -const char * -irc_protocol_get_address_from_host (const char *host) -{ - static char address[256]; - char host2[256], *pos_space, *pos; - const char *ptr_host; - - address[0] = '\0'; - if (host) - { - ptr_host = host; - pos_space = strchr (host, ' '); - if (pos_space) - { - if (pos_space - host < (int)sizeof (host2)) - { - strncpy (host2, host, pos_space - host); - host2[pos_space - host] = '\0'; - } - else - snprintf (host2, sizeof (host2), "%s", host); - ptr_host = host2; - } - - if (ptr_host[0] == ':') - ptr_host++; - pos = strchr (ptr_host, '!'); - if (pos) - snprintf (address, sizeof (address), "%s", pos + 1); - else - snprintf (address, sizeof (address), "%s", ptr_host); - } - - return address; -} - -/* * irc_protocol_log_level_for_command: get log level for IRC command */ @@ -222,48 +134,6 @@ irc_protocol_tags (const char *command, const char *tags, const char *nick) } /* - * irc_protocol_replace_vars: replace special IRC vars ($nick, $channel, - * $server) in a string - * Note: result has to be free() after use - */ - -char * -irc_protocol_replace_vars (struct t_irc_server *server, - struct t_irc_channel *channel, const char *string) -{ - char *var_nick, *var_channel, *var_server; - char empty_string[1] = { '\0' }; - char *res, *temp; - - var_nick = (server && server->nick) ? server->nick : empty_string; - var_channel = (channel) ? channel->name : empty_string; - var_server = (server) ? server->name : empty_string; - - /* replace nick */ - temp = weechat_string_replace (string, "$nick", var_nick); - if (!temp) - return NULL; - res = temp; - - /* replace channel */ - temp = weechat_string_replace (res, "$channel", var_channel); - free (res); - if (!temp) - return NULL; - res = temp; - - /* replace server */ - temp = weechat_string_replace (res, "$server", var_server); - free (res); - if (!temp) - return NULL; - res = temp; - - /* return result */ - return res; -} - -/* * irc_protocol_cb_authenticate: 'authenticate' message received */ @@ -1955,8 +1825,8 @@ IRC_PROTOCOL_CALLBACK(001) { for (ptr_cmd = commands; *ptr_cmd; ptr_cmd++) { - vars_replaced = irc_protocol_replace_vars (server, NULL, - *ptr_cmd); + vars_replaced = irc_message_replace_vars (server, NULL, + *ptr_cmd); weechat_command (server->buffer, (vars_replaced) ? vars_replaced : *ptr_cmd); if (vars_replaced) @@ -2956,8 +2826,8 @@ IRC_PROTOCOL_CALLBACK(333) IRC_PROTOCOL_MIN_ARGS(5); - topic_nick = (argc > 5) ? irc_protocol_get_nick_from_host (argv[4]) : NULL; - topic_address = (argc > 5) ? irc_protocol_get_address_from_host (argv[4]) : NULL; + topic_nick = (argc > 5) ? irc_message_get_nick_from_host (argv[4]) : NULL; + topic_address = (argc > 5) ? irc_message_get_address_from_host (argv[4]) : NULL; if (topic_nick && topic_address && strcmp (topic_nick, topic_address) == 0) topic_address = NULL; @@ -3194,10 +3064,10 @@ IRC_PROTOCOL_CALLBACK(346) argv[4], IRC_COLOR_CHAT, IRC_COLOR_CHAT_NICK, - irc_protocol_get_nick_from_host (argv[5]), + irc_message_get_nick_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT_HOST, - irc_protocol_get_address_from_host (argv[5]), + irc_message_get_address_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT, weechat_util_get_time_string (&datetime)); @@ -3217,10 +3087,10 @@ IRC_PROTOCOL_CALLBACK(346) argv[4], IRC_COLOR_CHAT, IRC_COLOR_CHAT_NICK, - irc_protocol_get_nick_from_host (argv[5]), + irc_message_get_nick_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT_HOST, - irc_protocol_get_address_from_host (argv[5]), + irc_message_get_address_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS); } @@ -3304,10 +3174,10 @@ IRC_PROTOCOL_CALLBACK(348) argv[4], IRC_COLOR_CHAT, IRC_COLOR_CHAT_NICK, - irc_protocol_get_nick_from_host (argv[5]), + irc_message_get_nick_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT_HOST, - irc_protocol_get_address_from_host (argv[5]), + irc_message_get_address_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT, weechat_util_get_time_string (&datetime)); @@ -3765,10 +3635,10 @@ IRC_PROTOCOL_CALLBACK(367) argv[4], IRC_COLOR_CHAT, IRC_COLOR_CHAT_NICK, - irc_protocol_get_nick_from_host (argv[5]), + irc_message_get_nick_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT_HOST, - irc_protocol_get_address_from_host (argv[5]), + irc_message_get_address_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT, weechat_util_get_time_string (&datetime)); @@ -3788,10 +3658,10 @@ IRC_PROTOCOL_CALLBACK(367) argv[4], IRC_COLOR_CHAT, IRC_COLOR_CHAT_NICK, - irc_protocol_get_nick_from_host (argv[5]), + irc_message_get_nick_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_CHAT_HOST, - irc_protocol_get_address_from_host (argv[5]), + irc_message_get_address_from_host (argv[5]), IRC_COLOR_CHAT_DELIMITERS); } @@ -4308,8 +4178,8 @@ irc_protocol_recv_command (struct t_irc_server *server, host1 = NULL; if (irc_message && (irc_message[0] == ':')) { - nick1 = irc_protocol_get_nick_from_host (irc_message); - address1 = irc_protocol_get_address_from_host (irc_message); + nick1 = irc_message_get_nick_from_host (irc_message); + address1 = irc_message_get_address_from_host (irc_message); host1 = irc_message + 1; } nick = (nick1) ? strdup (nick1) : NULL; diff --git a/src/plugins/irc/irc-protocol.h b/src/plugins/irc/irc-protocol.h index 1d705c0f3..ee122ab56 100644 --- a/src/plugins/irc/irc-protocol.h +++ b/src/plugins/irc/irc-protocol.h @@ -77,7 +77,6 @@ struct t_irc_protocol_msg t_irc_recv_func *recv_function; /* function called when msg is received */ }; -extern const char *irc_protocol_get_nick_from_host (const char *host); extern const char *irc_protocol_tags (const char *command, const char *tags, const char *nick); extern void irc_protocol_recv_command (struct t_irc_server *server, diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index f846ca8fd..86c18868e 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -49,6 +49,7 @@ #include "irc-command.h" #include "irc-config.h" #include "irc-input.h" +#include "irc-message.h" #include "irc-nick.h" #include "irc-notify.h" #include "irc-protocol.h" @@ -1521,175 +1522,6 @@ irc_server_outqueue_send (struct t_irc_server *server) } /* - * irc_server_parse_message: parse IRC message and return pointer to - * host, command, channel, target nick and arguments - * (if any) - */ - -void -irc_server_parse_message (const char *message, char **nick, char **host, - char **command, char **channel, char **arguments) -{ - const char *pos, *pos2, *pos3, *pos4, *pos5; - - if (nick) - *nick = NULL; - if (host) - *host = NULL; - if (command) - *command = NULL; - if (channel) - *channel = NULL; - if (arguments) - *arguments = NULL; - - if (!message) - return; - - /* - * we will use this message as example: - * :FlashCode!n=FlashCod@host.com PRIVMSG #channel :hello! - */ - if (message[0] == ':') - { - pos2 = strchr (message, '!'); - pos = strchr (message, ' '); - if (pos2 && (!pos || pos > pos2)) - { - if (nick) - *nick = weechat_strndup (message + 1, pos2 - (message + 1)); - } - else if (pos) - { - if (nick) - *nick = weechat_strndup (message + 1, pos - (message + 1)); - } - if (pos) - { - if (host) - *host = weechat_strndup (message + 1, pos - (message + 1)); - pos++; - } - else - pos = message; - } - else - pos = message; - - /* pos is pointer on PRIVMSG #channel :hello! */ - if (pos && pos[0]) - { - while (pos[0] == ' ') - { - pos++; - } - pos2 = strchr (pos, ' '); - if (pos2) - { - /* pos2 is pointer on #channel :hello! */ - if (command) - *command = weechat_strndup (pos, pos2 - pos); - pos2++; - while (pos2[0] == ' ') - { - pos2++; - } - if (arguments) - *arguments = strdup (pos2); - if (pos2[0] != ':') - { - if (irc_channel_is_channel (pos2)) - { - pos3 = strchr (pos2, ' '); - if (channel) - { - if (pos3) - *channel = weechat_strndup (pos2, pos3 - pos2); - else - *channel = strdup (pos2); - } - } - else - { - pos3 = strchr (pos2, ' '); - if (nick && !*nick) - { - if (pos3) - *nick = weechat_strndup (pos2, pos3 - pos2); - else - *nick = strdup (pos2); - } - if (pos3) - { - pos4 = pos3; - pos3++; - while (pos3[0] == ' ') - { - pos3++; - } - if (irc_channel_is_channel (pos3)) - { - pos5 = strchr (pos3, ' '); - if (channel) - { - if (pos5) - *channel = weechat_strndup (pos3, pos5 - pos3); - else - *channel = strdup (pos3); - } - } - else if (channel && !*channel) - { - *channel = weechat_strndup (pos2, pos4 - pos2); - } - } - } - } - } - else - { - if (command) - *command = strdup (pos); - } - } -} - -/* - * 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) ? nick : empty_str); - weechat_hashtable_set (hashtable, "host", (host) ? host : empty_str); - weechat_hashtable_set (hashtable, "command", (command) ? command : empty_str); - weechat_hashtable_set (hashtable, "channel", (channel) ? channel : empty_str); - weechat_hashtable_set (hashtable, "arguments", (arguments) ? arguments : empty_str); - - return hashtable; -} - -/* * irc_server_send_one_msg: send one message to IRC server * if flag contains outqueue priority value, then * messages are in a queue and sent slowly (to be sure @@ -1716,7 +1548,7 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags, rc = 1; - irc_server_parse_message (message, &nick, NULL, &command, &channel, NULL); + irc_message_parse (message, &nick, NULL, &command, &channel, NULL); snprintf (str_modifier, sizeof (str_modifier), "irc_out_%s", (command) ? command : "unknown"); @@ -2074,8 +1906,7 @@ irc_server_msgq_flush () irc_raw_print (irc_recv_msgq->server, IRC_RAW_FLAG_RECV, ptr_data); - irc_server_parse_message (ptr_data, NULL, NULL, &command, - NULL, NULL); + irc_message_parse (ptr_data, NULL, NULL, &command, NULL, NULL); snprintf (str_modifier, sizeof (str_modifier), "irc_in_%s", (command) ? command : "unknown"); @@ -2111,9 +1942,8 @@ irc_server_msgq_flush () ptr_msg); } - irc_server_parse_message (ptr_msg, &nick, &host, - &command, &channel, - &arguments); + irc_message_parse (ptr_msg, &nick, &host, &command, + &channel, &arguments); /* convert charset for message */ if (channel) diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 23140ed85..ef9a9ca20 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -237,10 +237,6 @@ extern void irc_server_send_signal (struct t_irc_server *server, const char *signal, const char *command, const char *full_message, const char *tags); -extern void irc_server_parse_message (const char *message, char **nick, - char **host, char **command, - char **channel, char **arguments); -extern struct t_hashtable *irc_server_parse_message_to_hashtable (const char *message); extern void irc_server_set_send_default_tags (const char *tags); extern void irc_server_sendf (struct t_irc_server *server, int flags, const char *tags, const char *format, ...); |