mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 22:36:38 +02:00
irc: replace calls to malloc by weechat_asprintf
This commit is contained in:
@@ -543,7 +543,6 @@ irc_bar_item_nick_modes (const void *pointer, void *data,
|
||||
{
|
||||
struct t_irc_server *server;
|
||||
char *buf;
|
||||
int length;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
@@ -559,14 +558,9 @@ irc_bar_item_nick_modes (const void *pointer, void *data,
|
||||
if (!server || !server->nick_modes || !server->nick_modes[0])
|
||||
return NULL;
|
||||
|
||||
length = 64 + strlen (server->nick_modes) + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
{
|
||||
snprintf (buf, length, "%s%s",
|
||||
IRC_COLOR_ITEM_NICK_MODES,
|
||||
server->nick_modes);
|
||||
}
|
||||
weechat_asprintf (&buf,
|
||||
"%s%s",
|
||||
IRC_COLOR_ITEM_NICK_MODES, server->nick_modes);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -1482,26 +1482,15 @@ irc_channel_rejoin (struct t_irc_server *server, struct t_irc_channel *channel,
|
||||
int manual_join, int noswitch)
|
||||
{
|
||||
char *join_string;
|
||||
int length;
|
||||
|
||||
if (channel->key)
|
||||
{
|
||||
length = strlen (channel->name) + 1 + strlen (channel->key) + 1;
|
||||
join_string = malloc (length);
|
||||
if (join_string)
|
||||
{
|
||||
snprintf (join_string, length, "%s %s",
|
||||
channel->name,
|
||||
channel->key);
|
||||
irc_command_join_server (server, join_string,
|
||||
manual_join, noswitch);
|
||||
free (join_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
irc_command_join_server (server, channel->name,
|
||||
manual_join, noswitch);
|
||||
}
|
||||
weechat_asprintf (&join_string, "%s %s", channel->name, channel->key);
|
||||
irc_command_join_server (server,
|
||||
(join_string) ? join_string : channel->name,
|
||||
manual_join,
|
||||
noswitch);
|
||||
free (join_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2717,13 +2717,8 @@ IRC_COMMAND_CALLBACK(ignore)
|
||||
}
|
||||
else
|
||||
{
|
||||
length = 1 + strlen (ptr_regex) + 1 + 1;
|
||||
regex2 = malloc (length);
|
||||
if (regex2)
|
||||
{
|
||||
snprintf (regex2, length, "^%s$", ptr_regex);
|
||||
if (weechat_asprintf (®ex2, "^%s$", ptr_regex) >= 0)
|
||||
ptr_regex = regex2;
|
||||
}
|
||||
}
|
||||
|
||||
ptr_ignore = irc_ignore_search (ptr_regex, server, channel);
|
||||
@@ -3272,7 +3267,6 @@ IRC_COMMAND_CALLBACK(kick)
|
||||
IRC_COMMAND_CALLBACK(kickban)
|
||||
{
|
||||
char *pos_channel, *pos_nick, *nick_only, *pos_comment, *pos, *mask;
|
||||
int length;
|
||||
|
||||
IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
|
||||
IRC_COMMAND_CHECK_SERVER("kickban", 1, 1);
|
||||
@@ -3331,13 +3325,11 @@ IRC_COMMAND_CALLBACK(kickban)
|
||||
/* set ban for nick(+host) on channel */
|
||||
if (strchr (pos_nick, '@'))
|
||||
{
|
||||
length = strlen (pos_nick) + 16 + 1;
|
||||
mask = malloc (length);
|
||||
if (mask)
|
||||
pos = strchr (pos_nick, '!');
|
||||
if (weechat_asprintf (&mask,
|
||||
"*!%s",
|
||||
(pos) ? pos + 1 : pos_nick) >= 0)
|
||||
{
|
||||
pos = strchr (pos_nick, '!');
|
||||
snprintf (mask, length, "*!%s",
|
||||
(pos) ? pos + 1 : pos_nick);
|
||||
irc_server_sendf (ptr_server,
|
||||
IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
|
||||
"MODE %s +b %s",
|
||||
@@ -6187,12 +6179,8 @@ IRC_COMMAND_CALLBACK(server)
|
||||
length = strlen (msg_no_quotes);
|
||||
if (length > 0)
|
||||
{
|
||||
/* allocate length + 2 (CR-LF) + 1 (final '\0') */
|
||||
message = malloc (length + 2 + 1);
|
||||
if (message)
|
||||
if (weechat_asprintf (&message, "%s\r\n", msg_no_quotes) >= 0)
|
||||
{
|
||||
strcpy (message, msg_no_quotes);
|
||||
strcat (message, "\r\n");
|
||||
irc_server_msgq_add_buffer (ptr_server, message);
|
||||
irc_server_msgq_flush ();
|
||||
free (message);
|
||||
|
||||
@@ -414,7 +414,6 @@ irc_completion_channel_nicks_hosts_cb (const void *pointer, void *data,
|
||||
{
|
||||
struct t_irc_nick *ptr_nick;
|
||||
char *buf;
|
||||
int length;
|
||||
|
||||
IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
|
||||
|
||||
@@ -437,13 +436,11 @@ irc_completion_channel_nicks_hosts_cb (const void *pointer, void *data,
|
||||
WEECHAT_LIST_POS_SORT);
|
||||
if (ptr_nick->host)
|
||||
{
|
||||
length = strlen (ptr_nick->name) + 1 +
|
||||
strlen (ptr_nick->host) + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
if (weechat_asprintf (&buf,
|
||||
"%s!%s",
|
||||
ptr_nick->name,
|
||||
ptr_nick->host) >= 0)
|
||||
{
|
||||
snprintf (buf, length, "%s!%s",
|
||||
ptr_nick->name, ptr_nick->host);
|
||||
weechat_completion_list_add (
|
||||
completion, buf, 0, WEECHAT_LIST_POS_SORT);
|
||||
free (buf);
|
||||
@@ -558,7 +555,6 @@ irc_completion_channel_topic_cb (const void *pointer, void *data,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
char *topic;
|
||||
int length;
|
||||
|
||||
IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
|
||||
|
||||
@@ -580,16 +576,15 @@ irc_completion_channel_topic_cb (const void *pointer, void *data,
|
||||
* instead of
|
||||
* /topic #test is a test channel
|
||||
*/
|
||||
length = strlen (ptr_channel->name) + strlen (ptr_channel->topic) + 16 + 1;
|
||||
topic = malloc (length);
|
||||
if (topic)
|
||||
{
|
||||
snprintf (topic, length, "%s %s",
|
||||
ptr_channel->name, ptr_channel->topic);
|
||||
}
|
||||
weechat_asprintf (&topic,
|
||||
"%s %s",
|
||||
ptr_channel->name,
|
||||
ptr_channel->topic);
|
||||
}
|
||||
else
|
||||
{
|
||||
topic = strdup (ptr_channel->topic);
|
||||
}
|
||||
|
||||
weechat_completion_list_add (completion,
|
||||
(topic) ? topic : ptr_channel->topic,
|
||||
|
||||
@@ -424,7 +424,7 @@ irc_ctcp_reply_to_nick (struct t_irc_protocol_ctxt *ctxt,
|
||||
const char *arguments)
|
||||
{
|
||||
struct t_arraylist *list_messages;
|
||||
int i, list_size, length;
|
||||
int i, list_size;
|
||||
char *dup_ctcp, *dup_ctcp_upper, *dup_args, *message;
|
||||
const char *ptr_message;
|
||||
|
||||
@@ -479,12 +479,11 @@ irc_ctcp_reply_to_nick (struct t_irc_protocol_ctxt *ctxt,
|
||||
if (!ptr_message)
|
||||
break;
|
||||
/* build arguments: '\001' + CTCP + ' ' + message + '\001' */
|
||||
length = 1 + strlen (dup_ctcp_upper) + 1 + strlen (ptr_message) + 1 + 1;
|
||||
message = malloc (length);
|
||||
if (message)
|
||||
if (weechat_asprintf (&message,
|
||||
"\001%s %s\001",
|
||||
dup_ctcp_upper,
|
||||
ptr_message) >= 0)
|
||||
{
|
||||
snprintf (message, length,
|
||||
"\001%s %s\001", dup_ctcp_upper, ptr_message);
|
||||
irc_ctcp_display_reply_to_nick (ctxt, ctxt->nick, message);
|
||||
free (message);
|
||||
}
|
||||
|
||||
@@ -53,13 +53,7 @@ irc_info_create_string_with_pointer (char **string, void *pointer)
|
||||
*string = NULL;
|
||||
}
|
||||
if (pointer)
|
||||
{
|
||||
*string = malloc (64);
|
||||
if (*string)
|
||||
{
|
||||
snprintf (*string, 64, "0x%lx", (unsigned long)pointer);
|
||||
}
|
||||
}
|
||||
weechat_asprintf (string, "0x%lx", (unsigned long)pointer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -943,23 +943,22 @@ irc_message_split_add (struct t_irc_message_split_context *context,
|
||||
|
||||
if (message)
|
||||
{
|
||||
length = ((tags) ? strlen (tags) : 0) + strlen (message) + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
snprintf (key, sizeof (key), "msg%d", context->number);
|
||||
if (weechat_asprintf (&buf,
|
||||
"%s%s",
|
||||
(tags) ? tags : "",
|
||||
message) >= 0)
|
||||
{
|
||||
snprintf (key, sizeof (key), "msg%d", context->number);
|
||||
snprintf (buf, length, "%s%s",
|
||||
(tags) ? tags : "",
|
||||
message);
|
||||
length = strlen (buf);
|
||||
weechat_hashtable_set (context->hashtable, key, buf);
|
||||
if (weechat_irc_plugin->debug >= 2)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
"irc_message_split_add >> %s='%s' (%d bytes)",
|
||||
key, buf, length - 1);
|
||||
key, buf, length);
|
||||
}
|
||||
free (buf);
|
||||
context->total_bytes += length;
|
||||
context->total_bytes += length + 1;
|
||||
}
|
||||
}
|
||||
if (arguments)
|
||||
|
||||
@@ -155,7 +155,7 @@ irc_mode_channel_update (struct t_irc_server *server,
|
||||
{
|
||||
char *pos_args, *str_modes, **argv, *pos, *ptr_arg;
|
||||
char *new_modes, *new_args, str_mode[2], *str_temp;
|
||||
int argc, current_arg, chanmode_found, length;
|
||||
int argc, current_arg, chanmode_found;
|
||||
|
||||
if (!channel->modes)
|
||||
channel->modes = strdup ("+");
|
||||
@@ -295,11 +295,8 @@ irc_mode_channel_update (struct t_irc_server *server,
|
||||
}
|
||||
if (new_args[0])
|
||||
{
|
||||
length = strlen (new_modes) + 1 + strlen (new_args) + 1;
|
||||
str_temp = malloc (length);
|
||||
if (str_temp)
|
||||
if (weechat_asprintf (&str_temp, "%s %s", new_modes, new_args) >= 0)
|
||||
{
|
||||
snprintf (str_temp, length, "%s %s", new_modes, new_args);
|
||||
free (channel->modes);
|
||||
channel->modes = str_temp;
|
||||
}
|
||||
|
||||
@@ -274,42 +274,28 @@ irc_notify_build_message_with_nicks (struct t_irc_server *server,
|
||||
const char *separator,
|
||||
int *num_nicks)
|
||||
{
|
||||
char *message, *message2;
|
||||
int length, total_length, length_separator;
|
||||
struct t_irc_notify *ptr_notify;
|
||||
char **message;
|
||||
|
||||
*num_nicks = 0;
|
||||
|
||||
length = strlen (irc_message) + 1;
|
||||
total_length = length;
|
||||
length_separator = strlen (separator);
|
||||
|
||||
message = malloc (length);
|
||||
message = weechat_string_dyn_alloc (256);
|
||||
if (!message)
|
||||
return NULL;
|
||||
snprintf (message, length, "%s", irc_message);
|
||||
|
||||
weechat_string_dyn_concat (message, irc_message, -1);
|
||||
|
||||
for (ptr_notify = server->notify_list; ptr_notify;
|
||||
ptr_notify = ptr_notify->next_notify)
|
||||
{
|
||||
length = strlen (ptr_notify->nick);
|
||||
total_length += length + length_separator;
|
||||
message2 = realloc (message, total_length);
|
||||
if (!message2)
|
||||
{
|
||||
free (message);
|
||||
message = NULL;
|
||||
break;
|
||||
}
|
||||
message = message2;
|
||||
if (*num_nicks > 0)
|
||||
strcat (message, separator);
|
||||
strcat (message, ptr_notify->nick);
|
||||
weechat_string_dyn_concat (message, separator, -1);
|
||||
weechat_string_dyn_concat (message, ptr_notify->nick, -1);
|
||||
|
||||
(*num_nicks)++;
|
||||
}
|
||||
|
||||
return message;
|
||||
return weechat_string_dyn_free (message, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -646,21 +632,15 @@ irc_notify_send_signal (struct t_irc_notify *notify,
|
||||
const char *away_message)
|
||||
{
|
||||
char signal[128], *data;
|
||||
int length;
|
||||
|
||||
snprintf (signal, sizeof (signal), "irc_notify_%s", type);
|
||||
|
||||
length = strlen (notify->server->name) + 1 + strlen (notify->nick) + 1
|
||||
+ ((away_message) ? strlen (away_message) : 0) + 1;
|
||||
data = malloc (length);
|
||||
if (data)
|
||||
{
|
||||
snprintf (data, length, "%s,%s%s%s",
|
||||
notify->server->name,
|
||||
notify->nick,
|
||||
(away_message && away_message[0]) ? "," : "",
|
||||
(away_message && away_message[0]) ? away_message : "");
|
||||
}
|
||||
weechat_asprintf (&data,
|
||||
"%s,%s%s%s",
|
||||
notify->server->name,
|
||||
notify->nick,
|
||||
(away_message && away_message[0]) ? "," : "",
|
||||
(away_message && away_message[0]) ? away_message : "");
|
||||
|
||||
(void) weechat_hook_signal_send (signal, WEECHAT_HOOK_SIGNAL_STRING, data);
|
||||
|
||||
|
||||
@@ -5998,7 +5998,6 @@ IRC_PROTOCOL_CALLBACK(352)
|
||||
{
|
||||
char *str_host, *str_hopcount, *str_realname;
|
||||
const char *pos;
|
||||
int length;
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_irc_nick *ptr_nick;
|
||||
|
||||
@@ -6037,11 +6036,11 @@ IRC_PROTOCOL_CALLBACK(352)
|
||||
/* update host in nick */
|
||||
if (ptr_nick)
|
||||
{
|
||||
length = strlen (ctxt->params[2]) + 1 + strlen (ctxt->params[3]) + 1;
|
||||
str_host = malloc (length);
|
||||
if (str_host)
|
||||
if (weechat_asprintf (&str_host,
|
||||
"%s@%s",
|
||||
ctxt->params[2],
|
||||
ctxt->params[3]) >= 0)
|
||||
{
|
||||
snprintf (str_host, length, "%s@%s", ctxt->params[2], ctxt->params[3]);
|
||||
irc_nick_set_host (ptr_nick, str_host);
|
||||
free (str_host);
|
||||
}
|
||||
@@ -6267,7 +6266,6 @@ IRC_PROTOCOL_CALLBACK(353)
|
||||
IRC_PROTOCOL_CALLBACK(354)
|
||||
{
|
||||
char *str_params, *str_host;
|
||||
int length;
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_irc_nick *ptr_nick;
|
||||
|
||||
@@ -6311,11 +6309,11 @@ IRC_PROTOCOL_CALLBACK(354)
|
||||
/* update host in nick */
|
||||
if (ptr_nick)
|
||||
{
|
||||
length = strlen (ctxt->params[2]) + 1 + strlen (ctxt->params[3]) + 1;
|
||||
str_host = malloc (length);
|
||||
if (str_host)
|
||||
if (weechat_asprintf (&str_host,
|
||||
"%s@%s",
|
||||
ctxt->params[2],
|
||||
ctxt->params[3]) >= 0)
|
||||
{
|
||||
snprintf (str_host, length, "%s@%s", ctxt->params[2], ctxt->params[3]);
|
||||
irc_nick_set_host (ptr_nick, str_host);
|
||||
free (str_host);
|
||||
}
|
||||
|
||||
+41
-33
@@ -59,31 +59,33 @@ irc_sasl_mechanism_plain (const char *sasl_username, const char *sasl_password)
|
||||
if (!sasl_username || !sasl_password)
|
||||
return NULL;
|
||||
|
||||
answer_base64 = NULL;
|
||||
length_username = strlen (sasl_username);
|
||||
length = ((length_username + 1) * 2) + strlen (sasl_password) + 1;
|
||||
string = malloc (length);
|
||||
if (string)
|
||||
if (weechat_asprintf (&string,
|
||||
"%s|%s|%s",
|
||||
sasl_username,
|
||||
sasl_username,
|
||||
sasl_password) < 0)
|
||||
{
|
||||
snprintf (string, length, "%s|%s|%s",
|
||||
sasl_username, sasl_username, sasl_password);
|
||||
string[length_username] = '\0';
|
||||
string[(length_username * 2) + 1] = '\0';
|
||||
|
||||
answer_base64 = malloc (length * 4);
|
||||
if (answer_base64)
|
||||
{
|
||||
if (weechat_string_base_encode ("64", string, length - 1,
|
||||
answer_base64) < 0)
|
||||
{
|
||||
free (answer_base64);
|
||||
answer_base64 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free (string);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
length = strlen (string);
|
||||
|
||||
length_username = strlen (sasl_username);
|
||||
string[length_username] = '\0';
|
||||
string[(length_username * 2) + 1] = '\0';
|
||||
|
||||
answer_base64 = malloc ((length * 4) + 1);
|
||||
if (answer_base64)
|
||||
{
|
||||
if (weechat_string_base_encode ("64", string, length, answer_base64) < 0)
|
||||
{
|
||||
free (answer_base64);
|
||||
answer_base64 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
free (string);
|
||||
|
||||
return answer_base64;
|
||||
}
|
||||
|
||||
@@ -158,11 +160,11 @@ irc_sasl_mechanism_scram (struct t_irc_server *server,
|
||||
if (!username2)
|
||||
goto memory_error;
|
||||
length = 5 + strlen (username2) + 3 + sizeof (nonce_client_base64) - 1;
|
||||
string = malloc (length + 1);
|
||||
if (string)
|
||||
if (weechat_asprintf (&string,
|
||||
"n,,n=%s,r=%s",
|
||||
username2,
|
||||
nonce_client_base64) >= 0)
|
||||
{
|
||||
snprintf (string, length + 1, "n,,n=%s,r=%s",
|
||||
username2, nonce_client_base64);
|
||||
free (server->sasl_scram_client_first);
|
||||
server->sasl_scram_client_first = strdup (string + 3);
|
||||
}
|
||||
@@ -366,12 +368,13 @@ irc_sasl_mechanism_scram (struct t_irc_server *server,
|
||||
goto base64_encode_error;
|
||||
/* final message: auth_no_proof + "," + proof */
|
||||
length = strlen (auth_no_proof) + 3 + strlen (client_proof_base64);
|
||||
string = malloc (length + 1);
|
||||
rc = snprintf (string, length + 1, "%s,p=%s",
|
||||
auth_no_proof,
|
||||
client_proof_base64);
|
||||
if ((rc < 0) || (rc >= length + 1))
|
||||
if (weechat_asprintf (&string,
|
||||
"%s,p=%s",
|
||||
auth_no_proof,
|
||||
client_proof_base64) < 0)
|
||||
{
|
||||
goto memory_error;
|
||||
}
|
||||
}
|
||||
}
|
||||
goto end;
|
||||
@@ -526,8 +529,13 @@ irc_sasl_mechanism_ecdsa_nist256p_challenge (struct t_irc_server *server,
|
||||
string = malloc (length + 1);
|
||||
if (string)
|
||||
{
|
||||
snprintf (string, length + 1, "%s|%s", sasl_username, sasl_username);
|
||||
string[length_username] = '\0';
|
||||
if (weechat_asprintf (&string,
|
||||
"%s|%s",
|
||||
sasl_username,
|
||||
sasl_username) >= 0)
|
||||
{
|
||||
string[length_username] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
+58
-101
@@ -1707,8 +1707,8 @@ struct t_irc_server *
|
||||
irc_server_alloc (const char *name)
|
||||
{
|
||||
struct t_irc_server *new_server;
|
||||
int i, length;
|
||||
char *option_name;
|
||||
int i;
|
||||
|
||||
/* check if another server exists with this name */
|
||||
if (irc_server_search (name))
|
||||
@@ -1880,17 +1880,13 @@ irc_server_alloc (const char *name)
|
||||
}
|
||||
for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++)
|
||||
{
|
||||
length = strlen (new_server->name) + 1 +
|
||||
strlen (irc_server_options[i][0]) +
|
||||
512 + /* inherited option name (irc.server_default.xxx) */
|
||||
1;
|
||||
option_name = malloc (length);
|
||||
if (option_name)
|
||||
if (weechat_asprintf (
|
||||
&option_name,
|
||||
"%s.%s << irc.server_default.%s",
|
||||
new_server->name,
|
||||
irc_server_options[i][0],
|
||||
irc_server_options[i][0]) >= 0)
|
||||
{
|
||||
snprintf (option_name, length, "%s.%s << irc.server_default.%s",
|
||||
new_server->name,
|
||||
irc_server_options[i][0],
|
||||
irc_server_options[i][0]);
|
||||
new_server->options[i] = irc_config_server_new_option (
|
||||
irc_config_file,
|
||||
irc_config_section_server,
|
||||
@@ -1940,7 +1936,7 @@ irc_server_alloc_with_url (const char *irc_url)
|
||||
char *pos_address, *pos_port, *pos_channel, *pos;
|
||||
char *server_address, *server_nicks, *server_autojoin;
|
||||
char default_port[16];
|
||||
int ipv6, tls, length;
|
||||
int ipv6, tls;
|
||||
struct t_irc_server *ptr_server;
|
||||
|
||||
if (!irc_url || !irc_url[0])
|
||||
@@ -2062,15 +2058,12 @@ irc_server_alloc_with_url (const char *irc_url)
|
||||
ptr_server->temp_server = 1;
|
||||
if (pos_address && pos_address[0])
|
||||
{
|
||||
length = strlen (pos_address) + 1 +
|
||||
((pos_port) ? strlen (pos_port) : 16) + 1;
|
||||
server_address = malloc (length);
|
||||
if (server_address)
|
||||
if (weechat_asprintf (
|
||||
&server_address,
|
||||
"%s/%s",
|
||||
pos_address,
|
||||
(pos_port && pos_port[0]) ? pos_port : default_port) >= 0)
|
||||
{
|
||||
snprintf (server_address, length,
|
||||
"%s/%s",
|
||||
pos_address,
|
||||
(pos_port && pos_port[0]) ? pos_port : default_port);
|
||||
weechat_config_option_set (
|
||||
ptr_server->options[IRC_SERVER_OPTION_ADDRESSES],
|
||||
server_address,
|
||||
@@ -2086,13 +2079,11 @@ irc_server_alloc_with_url (const char *irc_url)
|
||||
1);
|
||||
if (pos_nick && pos_nick[0])
|
||||
{
|
||||
length = ((strlen (pos_nick) + 2) * 5) + 1;
|
||||
server_nicks = malloc (length);
|
||||
if (server_nicks)
|
||||
if (weechat_asprintf (
|
||||
&server_nicks,
|
||||
"%s,%s2,%s3,%s4,%s5",
|
||||
pos_nick, pos_nick, pos_nick, pos_nick, pos_nick) >= 0)
|
||||
{
|
||||
snprintf (server_nicks, length,
|
||||
"%s,%s2,%s3,%s4,%s5",
|
||||
pos_nick, pos_nick, pos_nick, pos_nick, pos_nick);
|
||||
weechat_config_option_set (
|
||||
ptr_server->options[IRC_SERVER_OPTION_NICKS],
|
||||
server_nicks,
|
||||
@@ -2117,14 +2108,7 @@ irc_server_alloc_with_url (const char *irc_url)
|
||||
if (irc_channel_is_channel (ptr_server, pos_channel))
|
||||
server_autojoin = strdup (pos_channel);
|
||||
else
|
||||
{
|
||||
server_autojoin = malloc (strlen (pos_channel) + 2);
|
||||
if (server_autojoin)
|
||||
{
|
||||
strcpy (server_autojoin, "#");
|
||||
strcat (server_autojoin, pos_channel);
|
||||
}
|
||||
}
|
||||
weechat_asprintf (&server_autojoin, "#%s", pos_channel);
|
||||
if (server_autojoin)
|
||||
{
|
||||
weechat_config_option_set (
|
||||
@@ -2460,7 +2444,7 @@ irc_server_copy (struct t_irc_server *server, const char *new_name)
|
||||
struct t_infolist *infolist;
|
||||
char *mask, *pos;
|
||||
const char *option_name;
|
||||
int length, index_option;
|
||||
int index_option;
|
||||
|
||||
/* check if another server exists with this name */
|
||||
if (irc_server_search (new_name))
|
||||
@@ -2475,11 +2459,8 @@ irc_server_copy (struct t_irc_server *server, const char *new_name)
|
||||
new_server->fake_server = server->fake_server;
|
||||
|
||||
/* duplicate options */
|
||||
length = 32 + strlen (server->name) + 1;
|
||||
mask = malloc (length);
|
||||
if (!mask)
|
||||
if (weechat_asprintf (&mask, "irc.server.%s.*", server->name) < 0)
|
||||
return 0;
|
||||
snprintf (mask, length, "irc.server.%s.*", server->name);
|
||||
infolist = weechat_infolist_get ("option", NULL, mask);
|
||||
free (mask);
|
||||
if (infolist)
|
||||
@@ -2521,7 +2502,6 @@ irc_server_copy (struct t_irc_server *server, const char *new_name)
|
||||
int
|
||||
irc_server_rename (struct t_irc_server *server, const char *new_name)
|
||||
{
|
||||
int length;
|
||||
char *mask, *pos_option, *new_option_name, charset_modifier[1024];
|
||||
char *buffer_name;
|
||||
const char *option_name;
|
||||
@@ -2534,11 +2514,8 @@ irc_server_rename (struct t_irc_server *server, const char *new_name)
|
||||
return 0;
|
||||
|
||||
/* rename options */
|
||||
length = 32 + strlen (server->name) + 1;
|
||||
mask = malloc (length);
|
||||
if (!mask)
|
||||
if (weechat_asprintf (&mask, "irc.server.%s.*", server->name) < 0)
|
||||
return 0;
|
||||
snprintf (mask, length, "irc.server.%s.*", server->name);
|
||||
infolist = weechat_infolist_get ("option", NULL, mask);
|
||||
free (mask);
|
||||
if (infolist)
|
||||
@@ -2556,12 +2533,11 @@ irc_server_rename (struct t_irc_server *server, const char *new_name)
|
||||
if (pos_option)
|
||||
{
|
||||
pos_option++;
|
||||
length = strlen (new_name) + 1 + strlen (pos_option) + 1;
|
||||
new_option_name = malloc (length);
|
||||
if (new_option_name)
|
||||
if (weechat_asprintf (&new_option_name,
|
||||
"%s.%s",
|
||||
new_name,
|
||||
pos_option) >= 0)
|
||||
{
|
||||
snprintf (new_option_name, length,
|
||||
"%s.%s", new_name, pos_option);
|
||||
weechat_config_option_rename (ptr_option, new_option_name);
|
||||
free (new_option_name);
|
||||
}
|
||||
@@ -2677,40 +2653,37 @@ irc_server_send_signal (struct t_irc_server *server, const char *signal,
|
||||
const char *command, const char *full_message,
|
||||
const char *tags)
|
||||
{
|
||||
int rc, length;
|
||||
int rc;
|
||||
char *str_signal, *full_message_tags;
|
||||
|
||||
rc = WEECHAT_RC_OK;
|
||||
|
||||
length = strlen (server->name) + 1 + strlen (signal) + 1
|
||||
+ strlen (command) + 1;
|
||||
str_signal = malloc (length);
|
||||
if (str_signal)
|
||||
if (weechat_asprintf (&str_signal,
|
||||
"%s,%s_%s",
|
||||
server->name, signal, command) < 0)
|
||||
{
|
||||
snprintf (str_signal, length,
|
||||
"%s,%s_%s", server->name, signal, command);
|
||||
if (tags)
|
||||
{
|
||||
length = strlen (tags) + 1 + strlen (full_message) + 1;
|
||||
full_message_tags = malloc (length);
|
||||
if (full_message_tags)
|
||||
{
|
||||
snprintf (full_message_tags, length,
|
||||
"%s;%s", tags, full_message);
|
||||
rc = weechat_hook_signal_send (str_signal,
|
||||
WEECHAT_HOOK_SIGNAL_STRING,
|
||||
(void *)full_message_tags);
|
||||
free (full_message_tags);
|
||||
}
|
||||
}
|
||||
else
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (tags)
|
||||
{
|
||||
if (weechat_asprintf (&full_message_tags,
|
||||
"%s;%s", tags, full_message) >= 0)
|
||||
{
|
||||
rc = weechat_hook_signal_send (str_signal,
|
||||
WEECHAT_HOOK_SIGNAL_STRING,
|
||||
(void *)full_message);
|
||||
(void *)full_message_tags);
|
||||
free (full_message_tags);
|
||||
}
|
||||
free (str_signal);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = weechat_hook_signal_send (str_signal,
|
||||
WEECHAT_HOOK_SIGNAL_STRING,
|
||||
(void *)full_message);
|
||||
}
|
||||
|
||||
free (str_signal);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -2803,7 +2776,6 @@ irc_server_set_send_default_tags (const char *tags)
|
||||
char *
|
||||
irc_server_get_tags_to_send (const char *tags)
|
||||
{
|
||||
int length;
|
||||
char *buf;
|
||||
|
||||
if (!tags && !irc_server_send_default_tags)
|
||||
@@ -2816,10 +2788,7 @@ irc_server_get_tags_to_send (const char *tags)
|
||||
return strdup (tags);
|
||||
|
||||
/* concatenate tags and irc_server_send_default_tags */
|
||||
length = strlen (tags) + 1 + strlen (irc_server_send_default_tags) + 1;
|
||||
buf = malloc (length);
|
||||
if (buf)
|
||||
snprintf (buf, length, "%s,%s", tags, irc_server_send_default_tags);
|
||||
weechat_asprintf (&buf, "%s,%s", tags, irc_server_send_default_tags);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -3396,19 +3365,15 @@ irc_server_msgq_add_msg (struct t_irc_server *server, const char *msg)
|
||||
message->server = server;
|
||||
if (server->unterminated_message)
|
||||
{
|
||||
message->data = malloc (strlen (server->unterminated_message) +
|
||||
strlen (msg) + 1);
|
||||
if (!message->data)
|
||||
if (weechat_asprintf (&message->data,
|
||||
"%s%s",
|
||||
server->unterminated_message,
|
||||
msg) < 0)
|
||||
{
|
||||
weechat_printf (server->buffer,
|
||||
_("%s%s: not enough memory for received message"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy (message->data, server->unterminated_message);
|
||||
strcat (message->data, msg);
|
||||
}
|
||||
free (server->unterminated_message);
|
||||
server->unterminated_message = NULL;
|
||||
}
|
||||
@@ -4753,22 +4718,18 @@ void
|
||||
irc_server_set_buffer_title (struct t_irc_server *server)
|
||||
{
|
||||
char *title;
|
||||
int length;
|
||||
|
||||
if (server && server->buffer)
|
||||
{
|
||||
if (server->is_connected)
|
||||
{
|
||||
length = 16 +
|
||||
((server->current_address) ? strlen (server->current_address) : 16) +
|
||||
16 + ((server->current_ip) ? strlen (server->current_ip) : 16) + 1;
|
||||
title = malloc (length);
|
||||
if (title)
|
||||
if (weechat_asprintf (
|
||||
&title,
|
||||
"IRC: %s/%d (%s)",
|
||||
server->current_address,
|
||||
server->current_port,
|
||||
(server->current_ip) ? server->current_ip : "") >= 0)
|
||||
{
|
||||
snprintf (title, length, "IRC: %s/%d (%s)",
|
||||
server->current_address,
|
||||
server->current_port,
|
||||
(server->current_ip) ? server->current_ip : "");
|
||||
weechat_buffer_set (server->buffer, "title", title);
|
||||
free (title);
|
||||
}
|
||||
@@ -5878,7 +5839,6 @@ irc_server_execute_command (struct t_irc_server *server)
|
||||
{
|
||||
char **commands, **ptr_command, *command2, *command3, *slash_command;
|
||||
const char *ptr_server_command;
|
||||
int length;
|
||||
|
||||
ptr_server_command = IRC_SERVER_OPTION_STRING(server,
|
||||
IRC_SERVER_OPTION_COMMAND);
|
||||
@@ -5904,11 +5864,8 @@ irc_server_execute_command (struct t_irc_server *server)
|
||||
}
|
||||
else
|
||||
{
|
||||
length = 1 + strlen (command3) + 1;
|
||||
slash_command = malloc (length);
|
||||
if (slash_command)
|
||||
if (weechat_asprintf (&slash_command, "/%s", command3) >= 0)
|
||||
{
|
||||
snprintf (slash_command, length, "/%s", command3);
|
||||
weechat_command (server->buffer, slash_command);
|
||||
free (slash_command);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user