summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/irc-command.c57
-rw-r--r--src/plugins/irc/irc-ctcp.c41
-rw-r--r--src/plugins/irc/irc-input.c36
-rw-r--r--src/plugins/irc/irc-server.c75
-rw-r--r--src/plugins/irc/irc-server.h8
5 files changed, 106 insertions, 111 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index c8c7ea61d..8cc4e1c97 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -1104,31 +1104,27 @@ irc_command_me_channel (struct t_irc_server *server,
struct t_irc_channel *channel,
const char *arguments)
{
- struct t_hashtable *hashtable;
- int number;
- char hash_key[32];
- const char *str_args;
+ struct t_arraylist *list_messages;
+ int i, list_size;
- hashtable = irc_server_sendf (
+ list_messages = irc_server_sendf (
server,
- IRC_SERVER_SEND_OUTQ_PRIO_HIGH | IRC_SERVER_SEND_RETURN_HASHTABLE,
+ IRC_SERVER_SEND_OUTQ_PRIO_HIGH | IRC_SERVER_SEND_RETURN_LIST,
NULL,
"PRIVMSG %s :\01ACTION %s\01",
channel->name,
(arguments && arguments[0]) ? arguments : "");
- if (hashtable)
+ if (list_messages)
{
- number = 1;
- while (1)
+ list_size = weechat_arraylist_size (list_messages);
+ for (i = 0; i < list_size; i++)
{
- snprintf (hash_key, sizeof (hash_key), "args%d", number);
- str_args = weechat_hashtable_get (hashtable, hash_key);
- if (!str_args)
- break;
- irc_command_me_channel_display (server, channel, str_args);
- number++;
+ irc_command_me_channel_display (
+ server,
+ channel,
+ (const char *)weechat_arraylist_get (list_messages, i));
}
- weechat_hashtable_free (hashtable);
+ weechat_arraylist_free (list_messages);
}
}
@@ -3931,10 +3927,11 @@ IRC_COMMAND_CALLBACK(nick)
IRC_COMMAND_CALLBACK(notice)
{
- char *string, hash_key[32], *str_args;
- int arg_target, arg_text, number, is_channel;
+ char *string;
+ const char *ptr_message;
+ int i, arg_target, arg_text, is_channel, list_size;
struct t_irc_channel *ptr_channel;
- struct t_hashtable *hashtable;
+ struct t_arraylist *list_messages;
IRC_BUFFER_GET_SERVER(buffer);
@@ -3967,23 +3964,20 @@ IRC_COMMAND_CALLBACK(notice)
if (ptr_channel)
is_channel = 1;
}
- hashtable = irc_server_sendf (
+ list_messages = irc_server_sendf (
ptr_server,
- IRC_SERVER_SEND_OUTQ_PRIO_HIGH | IRC_SERVER_SEND_RETURN_HASHTABLE,
+ IRC_SERVER_SEND_OUTQ_PRIO_HIGH | IRC_SERVER_SEND_RETURN_LIST,
NULL,
"NOTICE %s :%s",
argv[arg_target], argv_eol[arg_text]);
- if (hashtable)
+ if (list_messages)
{
- number = 1;
- while (1)
+ list_size = weechat_arraylist_size (list_messages);
+ for (i = 0; i < list_size; i++)
{
- snprintf (hash_key, sizeof (hash_key), "args%d", number);
- str_args = weechat_hashtable_get (hashtable, hash_key);
- if (!str_args)
- break;
+ ptr_message = (const char *)weechat_arraylist_get (list_messages, i);
string = irc_color_decode (
- str_args,
+ ptr_message,
weechat_config_boolean (irc_config_network_colors_send));
weechat_printf_date_tags (
irc_msgbuffer_get_target_buffer (
@@ -4000,12 +3994,11 @@ IRC_COMMAND_CALLBACK(notice)
(is_channel) ? IRC_COLOR_CHAT_CHANNEL : irc_nick_color_for_msg (ptr_server, 0, NULL, argv[arg_target]),
argv[arg_target],
IRC_COLOR_RESET,
- (string) ? string : str_args);
+ (string) ? string : ptr_message);
if (string)
free (string);
- number++;
}
- weechat_hashtable_free (hashtable);
+ weechat_arraylist_free (list_messages);
}
return WEECHAT_RC_OK;
diff --git a/src/plugins/irc/irc-ctcp.c b/src/plugins/irc/irc-ctcp.c
index 28a96d714..2bc8fa2e7 100644
--- a/src/plugins/irc/irc-ctcp.c
+++ b/src/plugins/irc/irc-ctcp.c
@@ -283,15 +283,15 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
const char *ctcp,
const char *arguments)
{
- struct t_hashtable *hashtable;
- int number;
- char hash_key[32], *str_args_color, *dup_ctcp, *dup_ctcp_upper, *dup_args;
- const char *str_args;
+ struct t_arraylist *list_messages;
+ int i, number, list_size;
+ char *msg_color, *dup_ctcp, *dup_ctcp_upper, *dup_args;
+ const char *ptr_message;
dup_ctcp = NULL;
dup_ctcp_upper = NULL;
dup_args = NULL;
- hashtable = NULL;
+ list_messages = NULL;
/*
* replace any "\01" by a space to prevent any firewall attack via
@@ -316,29 +316,28 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
goto end;
}
- hashtable = irc_server_sendf (
+ list_messages = irc_server_sendf (
server,
- IRC_SERVER_SEND_OUTQ_PRIO_LOW | IRC_SERVER_SEND_RETURN_HASHTABLE,
+ IRC_SERVER_SEND_OUTQ_PRIO_LOW | IRC_SERVER_SEND_RETURN_LIST,
NULL,
"NOTICE %s :\01%s%s%s\01",
nick,
dup_ctcp_upper,
(dup_args) ? " " : "",
(dup_args) ? dup_args : "");
- if (!hashtable)
+ if (!list_messages)
goto end;
if (weechat_config_boolean (irc_config_look_display_ctcp_reply))
{
- number = 1;
- while (1)
+ list_size = weechat_arraylist_size (list_messages);
+ for (i = 0; i < list_size; i++)
{
- snprintf (hash_key, sizeof (hash_key), "args%d", number);
- str_args = weechat_hashtable_get (hashtable, hash_key);
- if (!str_args)
+ ptr_message = (const char *)weechat_arraylist_get (list_messages, i);
+ if (!ptr_message)
break;
- str_args_color = irc_color_decode (str_args, 1);
- if (!str_args_color)
+ msg_color = irc_color_decode (ptr_message, 1);
+ if (!msg_color)
break;
weechat_printf_date_tags (
irc_msgbuffer_get_target_buffer (
@@ -359,10 +358,10 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
IRC_COLOR_RESET,
IRC_COLOR_CHAT_CHANNEL,
dup_ctcp_upper,
- (str_args_color[0]) ? IRC_COLOR_RESET : "",
- (str_args_color[0]) ? " " : "",
- str_args_color);
- free (str_args_color);
+ (msg_color[0]) ? IRC_COLOR_RESET : "",
+ (msg_color[0]) ? " " : "",
+ msg_color);
+ free (msg_color);
number++;
}
}
@@ -374,8 +373,8 @@ end:
free (dup_ctcp_upper);
if (dup_args)
free (dup_args);
- if (hashtable)
- weechat_hashtable_free (hashtable);
+ if (list_messages)
+ weechat_arraylist_free (list_messages);
}
/*
diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c
index 9dce7c594..225499fef 100644
--- a/src/plugins/irc/irc-input.c
+++ b/src/plugins/irc/irc-input.c
@@ -51,6 +51,9 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, int action,
char *pos, *text2, *text_decoded, str_tags[256], *str_color;
const char *ptr_text;
+ if (!buffer || !text)
+ return;
+
/* if message is an action, force "action" to 1 and extract message */
if (strncmp (text, "\01ACTION ", 8) == 0)
{
@@ -155,9 +158,8 @@ void
irc_input_send_user_message (struct t_gui_buffer *buffer, int flags,
const char *tags, char *message)
{
- int number, action;
- char hash_key[32], *str_args;
- struct t_hashtable *hashtable;
+ int i, action, list_size;
+ struct t_arraylist *list_messages;
IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
@@ -171,25 +173,23 @@ irc_input_send_user_message (struct t_gui_buffer *buffer, int flags,
weechat_prefix ("error"), IRC_PLUGIN_NAME);
return;
}
- hashtable = irc_server_sendf (ptr_server,
- flags | IRC_SERVER_SEND_RETURN_HASHTABLE,
- tags,
- "PRIVMSG %s :%s",
- ptr_channel->name, message);
- if (hashtable)
+ list_messages = irc_server_sendf (ptr_server,
+ flags | IRC_SERVER_SEND_RETURN_LIST,
+ tags,
+ "PRIVMSG %s :%s",
+ ptr_channel->name, message);
+ if (list_messages)
{
action = (strncmp (message, "\01ACTION ", 8) == 0);
- number = 1;
- while (1)
+ list_size = weechat_arraylist_size (list_messages);
+ for (i = 0; i < list_size; i++)
{
- snprintf (hash_key, sizeof (hash_key), "args%d", number);
- str_args = weechat_hashtable_get (hashtable, hash_key);
- if (!str_args)
- break;
- irc_input_user_message_display (buffer, action, str_args);
- number++;
+ irc_input_user_message_display (
+ buffer,
+ action,
+ (const char *)weechat_arraylist_get (list_messages, i));
}
- weechat_hashtable_free (hashtable);
+ weechat_arraylist_free (list_messages);
}
}
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 68b1e7bb2..50e45f6ea 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -3058,24 +3058,41 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags,
}
/*
+ * Callback used to free strings in list of messages returned by
+ * function irc_server_sendf().
+ */
+
+void
+irc_server_arraylist_free_string_cb (void *data, struct t_arraylist *arraylist,
+ void *pointer)
+{
+ /* make C compiler happy */
+ (void) data;
+ (void) arraylist;
+
+ free (pointer);
+}
+
+/*
* Sends a message to IRC server.
*
- * If flags contains "IRC_SERVER_SEND_RETURN_HASHTABLE", then a hashtable with
- * split of message is returned (see function irc_message_split() in
- * irc-message.c)
+ * If flags contains "IRC_SERVER_SEND_RETURN_LIST", then an arraylist with
+ * the list of messages to display is returned
+ * (see function irc_message_split() in irc-message.c).
*
- * Note: hashtable must be freed after use.
+ * Note: arraylist must be freed after use.
*/
-struct t_hashtable *
+struct t_arraylist *
irc_server_sendf (struct t_irc_server *server, int flags, const char *tags,
const char *format, ...)
{
- char hash_key[32], value[32], *nick, *command, *channel, *new_msg;
+ char hash_key[32], *nick, *command, *channel, *new_msg;
char str_modifier[128];
const char *str_message, *str_args, *ptr_msg;
- int number, ret_number;
- struct t_hashtable *hashtable, *ret_hashtable;
+ int number;
+ struct t_hashtable *hashtable;
+ struct t_arraylist *list_messages;
if (!server)
return NULL;
@@ -3084,14 +3101,16 @@ irc_server_sendf (struct t_irc_server *server, int flags, const char *tags,
if (!vbuffer)
return NULL;
- ret_hashtable = NULL;
- ret_number = 1;
- if (flags & IRC_SERVER_SEND_RETURN_HASHTABLE)
+ if (flags & IRC_SERVER_SEND_RETURN_LIST)
{
- ret_hashtable = weechat_hashtable_new (32,
- WEECHAT_HASHTABLE_STRING,
- WEECHAT_HASHTABLE_STRING,
- NULL, NULL);
+ list_messages = weechat_arraylist_new (
+ 4, 0, 1,
+ NULL, NULL,
+ &irc_server_arraylist_free_string_cb, NULL);
+ }
+ else
+ {
+ list_messages = NULL;
}
/* run modifier "irc_out1_xxx" (like "irc_out_xxx", but before split) */
@@ -3151,35 +3170,19 @@ irc_server_sendf (struct t_irc_server *server, int flags, const char *tags,
str_message = weechat_hashtable_get (hashtable, hash_key);
if (!str_message)
break;
- snprintf (hash_key, sizeof (hash_key), "args%d", number);
- str_args = weechat_hashtable_get (hashtable, hash_key);
-
if (!irc_server_send_one_msg (server, flags, str_message,
nick, command, channel, tags))
break;
- if (ret_hashtable)
+ if (list_messages)
{
- snprintf (hash_key, sizeof (hash_key),
- "msg%d", ret_number);
- weechat_hashtable_set (ret_hashtable,
- hash_key, str_message);
+ snprintf (hash_key, sizeof (hash_key), "args%d", number);
+ str_args = weechat_hashtable_get (hashtable, hash_key);
if (str_args)
- {
- snprintf (hash_key, sizeof (hash_key),
- "args%d", ret_number);
- weechat_hashtable_set (ret_hashtable,
- hash_key, str_args);
- }
- ret_number++;
+ weechat_arraylist_add (list_messages, strdup (str_args));
}
number++;
}
- if (ret_hashtable)
- {
- snprintf (value, sizeof (value), "%d", ret_number - 1);
- weechat_hashtable_set (ret_hashtable, "count", value);
- }
weechat_hashtable_free (hashtable);
}
}
@@ -3194,7 +3197,7 @@ irc_server_sendf (struct t_irc_server *server, int flags, const char *tags,
free (new_msg);
free (vbuffer);
- return ret_hashtable;
+ return list_messages;
}
/*
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index a674c96a9..f672a5288 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -129,9 +129,9 @@ enum t_irc_server_option
#define IRC_SERVER_NUM_OUTQUEUES_PRIO 2
/* flags for irc_server_sendf() */
-#define IRC_SERVER_SEND_OUTQ_PRIO_HIGH (1 << 0)
-#define IRC_SERVER_SEND_OUTQ_PRIO_LOW (1 << 1)
-#define IRC_SERVER_SEND_RETURN_HASHTABLE (1 << 2)
+#define IRC_SERVER_SEND_OUTQ_PRIO_HIGH (1 << 0)
+#define IRC_SERVER_SEND_OUTQ_PRIO_LOW (1 << 1)
+#define IRC_SERVER_SEND_RETURN_LIST (1 << 2)
/* version strings */
#define IRC_SERVER_VERSION_CAP "302"
@@ -387,7 +387,7 @@ extern int irc_server_send_signal (struct t_irc_server *server,
const char *full_message,
const char *tags);
extern void irc_server_set_send_default_tags (const char *tags);
-extern struct t_hashtable *irc_server_sendf (struct t_irc_server *server,
+extern struct t_arraylist *irc_server_sendf (struct t_irc_server *server,
int flags,
const char *tags,
const char *format, ...);