diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 1ce2f0d38..67306a8a5 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -2925,7 +2925,8 @@ void irc_command_join_server (struct t_irc_server *server, const char *arguments, int manual_join, int noswitch) { - char *new_args, **channels, **keys, *pos_space, *pos_keys, *pos_channel; + const char *pos_space, *pos_keys; + char *new_args, **channels, **keys, *pos_channel; char *channel_name_lower; int i, num_channels, num_keys, length; time_t time_now; diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index 05b3f19a3..fbfd62566 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -470,7 +470,7 @@ irc_completion_modelist_masks_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { - char *pos; + const char *pos; struct t_irc_modelist *ptr_modelist; struct t_irc_modelist_item *ptr_item; @@ -512,7 +512,8 @@ irc_completion_modelist_numbers_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, struct t_gui_completion *completion) { - char *pos, str_number[32]; + const char *pos; + char str_number[32]; struct t_irc_modelist *ptr_modelist; struct t_irc_modelist_item *ptr_item; diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index e823121a9..abbbea234 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -201,7 +201,8 @@ struct t_irc_server * irc_config_get_server_from_option_name (const char *name) { struct t_irc_server *ptr_server; - char *pos_option, *server_name; + const char *pos_option; + char *server_name; ptr_server = NULL; @@ -274,7 +275,7 @@ irc_config_compute_nick_colors (void) int irc_config_display_channel_modes_arguments (const char *modes) { - char *pos_space, *pos; + const char *pos_space, *pos; const char *ptr_mode; pos_space = strchr (modes, ' '); @@ -2811,7 +2812,8 @@ irc_config_server_read_cb (const void *pointer, void *data, { struct t_irc_server *ptr_server; int index_option, rc, i; - char *pos_option, *server_name; + const char *pos_option; + char *server_name; /* make C compiler happy */ (void) pointer; @@ -2940,9 +2942,9 @@ irc_config_update_cb (const void *pointer, void *data, int version_read, struct t_hashtable *data_read) { - const char *ptr_config, *ptr_section, *ptr_option, *ptr_value; + const char *ptr_config, *ptr_section, *ptr_option, *ptr_value, *pos_option; const char *option_autojoin_delay = "autojoin_delay"; - char *new_option, *pos_option, *new_value; + char *new_option, *pos_new_option, *new_value; int changes, length; /* make C compiler happy */ @@ -2997,11 +2999,11 @@ irc_config_update_cb (const void *pointer, void *data, new_option = strdup (ptr_option); if (new_option) { - pos_option = strrchr (new_option, '.'); - if (pos_option) + pos_new_option = strrchr (new_option, '.'); + if (pos_new_option) { - pos_option++; - memcpy (pos_option, "tls", 3); + pos_new_option++; + memcpy (pos_new_option, "tls", 3); weechat_printf ( NULL, _("IRC option renamed: \"irc.%s.%s\" => \"irc.%s.%s\""), diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index 3225577eb..325426aed 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -67,8 +67,8 @@ irc_info_info_irc_is_channel_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *server; - const char *pos_channel; + char *server; + const char *pos_channel, *pos_comma; struct t_irc_server *ptr_server; /* make C compiler happy */ @@ -106,8 +106,8 @@ irc_info_info_irc_is_nick_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *server; - const char *pos_nick; + char *server; + const char *pos_nick, *pos_comma; struct t_irc_server *ptr_server; /* make C compiler happy */ @@ -233,8 +233,8 @@ irc_info_info_irc_buffer_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *pos_comma2, *server, *channel, *host; - const char *nick; + char *server, *channel, *host; + const char *nick, *pos_comma, *pos_comma2; struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; @@ -332,8 +332,8 @@ irc_info_info_irc_server_isupport_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *server; - const char *isupport_value; + char *server; + const char *isupport_value, *pos_comma; struct t_irc_server *ptr_server; /* make C compiler happy */ @@ -373,8 +373,8 @@ irc_info_info_irc_server_isupport_value_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *server; - const char *isupport_value; + char *server; + const char *isupport_value, *pos_comma; struct t_irc_server *ptr_server; /* make C compiler happy */ @@ -414,7 +414,8 @@ irc_info_info_irc_server_cap_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *server; + char *server; + const char *pos_comma; int has_cap; struct t_irc_server *ptr_server; @@ -455,8 +456,8 @@ irc_info_info_irc_server_cap_value_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *server; - const char *cap_value; + char *server; + const char *cap_value, *pos_comma; struct t_irc_server *ptr_server; /* make C compiler happy */ @@ -496,8 +497,8 @@ irc_info_info_irc_is_message_ignored_cb (const void *pointer, void *data, const char *info_name, const char *arguments) { - char *pos_comma, *server; - const char *pos_message; + char *server; + const char *pos_message, *pos_comma; struct t_irc_server *ptr_server; /* make C compiler happy */ diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index 1761c1ee4..3270eea10 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -457,7 +457,7 @@ irc_input_send_cb (const void *pointer, void *data, const char *type_data, void *signal_data) { const char *ptr_string, *ptr_message; - char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4; + const char *pos_semicol1, *pos_semicol2, *pos_semicol3, *pos_semicol4; char *server, *channel, *options, *tags, *data_with_colors, **list_options; int i, num_options, flags, force_user_message; struct t_irc_server *ptr_server; diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index e0ac86955..3cc813619 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -707,8 +707,8 @@ 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; + char host2[128]; + const char *ptr_host, *pos_space, *pos; if (!host) return NULL; @@ -756,8 +756,8 @@ 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; + char host2[256]; + const char *ptr_host, *pos_space, *pos; if (!host) return NULL; @@ -1182,8 +1182,9 @@ irc_message_split_join (struct t_irc_message_split_context *context, { int channels_count, keys_count, length, length_no_channel; int length_to_add, index_channel; - char **channels, **keys, *pos, *str; + char **channels, **keys, *str; char msg_to_send[16384], keys_to_add[16384]; + const char *pos; max_length -= 2; /* by default: 512 - 2 = 510 bytes */ @@ -1510,7 +1511,7 @@ irc_message_split_privmsg_notice (struct t_irc_message_split_context *context, int irc_message_split_005 (struct t_irc_message_split_context *context, const char *tags, const char *host, const char *command, - const char *target, const char *arguments, + const char *target, char *arguments, int max_length) { char *pos, suffix[4096]; @@ -1570,7 +1571,8 @@ irc_message_split (struct t_irc_server *server, const char *message) { struct t_irc_message_split_context split_context; char **argv, **argv_eol, *tags, *host, *command, *arguments, target[4096]; - char *pos, monitor_action[3]; + char monitor_action[3]; + const char *pos; int split_ok, split_privmsg, argc, index_args, max_length_nick; int max_length_user, max_length_host, max_length_nick_user_host; int split_msg_max_length, multiline, multiline_max_bytes; diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c index 55ccd0889..e8c70075f 100644 --- a/src/plugins/irc/irc-mode.c +++ b/src/plugins/irc/irc-mode.c @@ -104,8 +104,8 @@ irc_mode_get_arguments_colors (const char *arguments) char irc_mode_get_chanmode_type (struct t_irc_server *server, char chanmode) { - char chanmode_type, *pos; - const char *chanmodes, *ptr_chanmodes; + char chanmode_type; + const char *chanmodes, *ptr_chanmodes, *pos; /* * assume it is type 'B' if mode is in prefix diff --git a/src/plugins/irc/irc-notify.c b/src/plugins/irc/irc-notify.c index c95567e3a..ddcd376e6 100644 --- a/src/plugins/irc/irc-notify.c +++ b/src/plugins/irc/irc-notify.c @@ -785,9 +785,8 @@ int irc_notify_hsignal_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable) { - const char *error, *server, *pattern, *command, *output; - char **messages, **nicks_sent, **nicks_recv, *irc_cmd, *arguments; - char *ptr_args, *pos; + const char *error, *server, *pattern, *command, *output, *ptr_args; + char **messages, **nicks_sent, **nicks_recv, *irc_cmd, *arguments, *pos; int i, j, num_messages, num_nicks_sent, num_nicks_recv, nick_was_sent; int away_message_updated, no_such_nick; struct t_irc_server *ptr_server; diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 698b5d476..3c3312375 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -2499,8 +2499,8 @@ IRC_PROTOCOL_CALLBACK(note) IRC_PROTOCOL_CALLBACK(notice) { - char *notice_args, *pos, end_char, *channel, str_tags[1024]; - const char *pos_target, *pos_args, *nick_address; + char *notice_args, end_char, *channel, str_tags[1024]; + const char *pos, *pos_target, *pos_args, *nick_address; struct t_irc_channel *ptr_channel; struct t_irc_nick *ptr_nick; int notify_private, is_channel, is_channel_orig, display_host; @@ -7921,12 +7921,11 @@ irc_protocol_recv_command (struct t_irc_server *server, int ignore_batch_tag) { int i, cmd_found, return_code, ignored; - char *pos_space, *tags; struct t_irc_channel *ptr_channel; t_irc_recv_func *cmd_recv_func; const char *ptr_msg_after_tags, *ptr_batch_ref, *ptr_tag_time; - const char *nick1, *address1, *host1; - char *host, *host_no_color; + const char *pos_space, *nick1, *address1, *host1; + char *tags, *host, *host_no_color, *pos_space_host; struct t_irc_protocol_ctxt ctxt; struct timeval tv; @@ -8198,9 +8197,9 @@ irc_protocol_recv_command (struct t_irc_server *server, host = (host1) ? strdup (host1) : NULL; if (host) { - pos_space = strchr (host, ' '); - if (pos_space) - pos_space[0] = '\0'; + pos_space_host = strchr (host, ' '); + if (pos_space_host) + pos_space_host[0] = '\0'; } host_no_color = (host) ? irc_color_decode (host, 0) : NULL; ctxt.host = (host) ? diff --git a/src/plugins/irc/irc-redirect.c b/src/plugins/irc/irc-redirect.c index 5c227185a..62409a35a 100644 --- a/src/plugins/irc/irc-redirect.c +++ b/src/plugins/irc/irc-redirect.c @@ -616,7 +616,7 @@ void irc_redirect_init_command (struct t_irc_redirect *redirect, const char *command) { - char *pos; + const char *pos; if (!redirect) return; diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 844c1939a..490a3135a 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -588,7 +588,7 @@ irc_server_sasl_enabled (struct t_irc_server *server) char * irc_server_get_name_without_port (const char *name) { - char *pos; + const char *pos; if (!name) return NULL; @@ -1134,7 +1134,7 @@ void irc_server_set_prefix_modes_chars (struct t_irc_server *server, const char *prefix) { - char *pos; + const char *pos; int i, old_length_chars, length_modes, length_chars; if (!server || !prefix) @@ -1379,8 +1379,7 @@ irc_server_get_prefix_chars (struct t_irc_server *server) int irc_server_get_prefix_mode_index (struct t_irc_server *server, char mode) { - const char *prefix_modes; - char *pos; + const char *prefix_modes, *pos; if (server) { @@ -1405,8 +1404,7 @@ int irc_server_get_prefix_char_index (struct t_irc_server *server, char prefix_char) { - const char *prefix_chars; - char *pos; + const char *prefix_chars, *pos; if (server) { @@ -2443,8 +2441,8 @@ irc_server_copy (struct t_irc_server *server, const char *new_name) { struct t_irc_server *new_server; struct t_infolist *infolist; - char *mask, *pos; - const char *option_name; + const char *option_name, *pos; + char *mask; int index_option; /* check if another server exists with this name */ @@ -2502,9 +2500,9 @@ 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) { - char *mask, *pos_option, *new_option_name, charset_modifier[1024]; + char *mask, *new_option_name, charset_modifier[1024]; char *buffer_name; - const char *option_name; + const char *option_name, *pos_option; struct t_infolist *infolist; struct t_config_option *ptr_option; struct t_irc_channel *ptr_channel; @@ -2999,8 +2997,8 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags, const char *tags) { static char buffer[4096]; - const char *ptr_msg, *ptr_chan_nick; - char *new_msg, *pos, *tags_to_send, *msg_encoded; + const char *ptr_chan_nick; + char *new_msg, *ptr_msg, *pos, *tags_to_send, *msg_encoded; char str_modifier[128], modifier_data[1024]; int first_message, queue_msg, pos_channel, pos_text, pos_encode; struct t_irc_redirect *ptr_redirect; @@ -3013,150 +3011,148 @@ irc_server_send_one_msg (struct t_irc_server *server, int flags, server->name, message); - /* no changes in new message */ - if (new_msg && (strcmp (message, new_msg) == 0)) - { - free (new_msg); - new_msg = NULL; - } - - /* message not dropped? */ - if (!new_msg || new_msg[0]) - { - first_message = 1; - ptr_msg = (new_msg) ? new_msg : message; - - msg_encoded = NULL; - irc_message_parse (server, - ptr_msg, - NULL, /* tags */ - NULL, /* message_without_tags */ - NULL, /* nick */ - NULL, /* user */ - NULL, /* host */ - NULL, /* command */ - NULL, /* channel */ - NULL, /* arguments */ - NULL, /* text */ - NULL, /* params */ - NULL, /* num_params */ - NULL, /* pos_command */ - NULL, /* pos_arguments */ - &pos_channel, - &pos_text); - switch (IRC_SERVER_OPTION_ENUM(server, - IRC_SERVER_OPTION_CHARSET_MESSAGE)) - { - case IRC_SERVER_CHARSET_MESSAGE_MESSAGE: - pos_encode = 0; - break; - case IRC_SERVER_CHARSET_MESSAGE_CHANNEL: - pos_encode = (pos_channel >= 0) ? pos_channel : pos_text; - break; - case IRC_SERVER_CHARSET_MESSAGE_TEXT: - pos_encode = pos_text; - break; - default: - pos_encode = 0; - break; - } - if (pos_encode >= 0) - { - ptr_chan_nick = (channel) ? channel : nick; - if (ptr_chan_nick) - { - snprintf (modifier_data, sizeof (modifier_data), - "%s.%s.%s", - weechat_plugin->name, - server->name, - ptr_chan_nick); - } - else - { - snprintf (modifier_data, sizeof (modifier_data), - "%s.%s", - weechat_plugin->name, - server->name); - } - - /* - * when UTF8ONLY is enabled, clients must not send non-UTF-8 data - * to the server; the charset encoding below is then done only if - * UTF8ONLY is *NOT* enabled - * (see: https://ircv3.net/specs/extensions/utf8-only) - */ - if (!server->utf8only) - { - msg_encoded = irc_message_convert_charset (ptr_msg, pos_encode, - "charset_encode", - modifier_data); - } - } - - if (msg_encoded) - ptr_msg = msg_encoded; - - while (ptr_msg && ptr_msg[0]) - { - pos = strchr (ptr_msg, '\n'); - if (pos) - pos[0] = '\0'; - - snprintf (buffer, sizeof (buffer), "%s\r\n", ptr_msg); - - if (flags & IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE) - queue_msg = 0; - else if (flags & IRC_SERVER_SEND_OUTQ_PRIO_HIGH) - queue_msg = 1; - else if (flags & IRC_SERVER_SEND_OUTQ_PRIO_LOW) - queue_msg = 2; - else - { - /* - * if connected to server (message 001 received), consider - * it's low priority (otherwise send immediately) - */ - queue_msg = (server->is_connected) ? 2 : 0; - } - - tags_to_send = irc_server_get_tags_to_send (tags); - - ptr_redirect = irc_redirect_search_available (server); - - /* queue message (do not send anything now) */ - irc_server_outqueue_add (server, - queue_msg, - command, - (new_msg && first_message) ? message : NULL, - buffer, - (new_msg) ? 1 : 0, - tags_to_send, - ptr_redirect); - - /* mark redirect as "used" */ - if (ptr_redirect) - ptr_redirect->assigned_to_command = 1; - - free (tags_to_send); - - if (pos) - { - pos[0] = '\n'; - ptr_msg = pos + 1; - } - else - ptr_msg = NULL; - - first_message = 0; - } - free (msg_encoded); - } - else + /* message dropped? */ + if (new_msg && !new_msg[0]) { irc_raw_print (server, IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED, _("(message dropped)")); + free (new_msg); + return; } + if (!new_msg) + new_msg = strdup (message); + if (!new_msg) + return; + + first_message = 1; + ptr_msg = new_msg; + + msg_encoded = NULL; + irc_message_parse (server, + ptr_msg, + NULL, /* tags */ + NULL, /* message_without_tags */ + NULL, /* nick */ + NULL, /* user */ + NULL, /* host */ + NULL, /* command */ + NULL, /* channel */ + NULL, /* arguments */ + NULL, /* text */ + NULL, /* params */ + NULL, /* num_params */ + NULL, /* pos_command */ + NULL, /* pos_arguments */ + &pos_channel, + &pos_text); + switch (IRC_SERVER_OPTION_ENUM(server, + IRC_SERVER_OPTION_CHARSET_MESSAGE)) + { + case IRC_SERVER_CHARSET_MESSAGE_MESSAGE: + pos_encode = 0; + break; + case IRC_SERVER_CHARSET_MESSAGE_CHANNEL: + pos_encode = (pos_channel >= 0) ? pos_channel : pos_text; + break; + case IRC_SERVER_CHARSET_MESSAGE_TEXT: + pos_encode = pos_text; + break; + default: + pos_encode = 0; + break; + } + if (pos_encode >= 0) + { + ptr_chan_nick = (channel) ? channel : nick; + if (ptr_chan_nick) + { + snprintf (modifier_data, sizeof (modifier_data), + "%s.%s.%s", + weechat_plugin->name, + server->name, + ptr_chan_nick); + } + else + { + snprintf (modifier_data, sizeof (modifier_data), + "%s.%s", + weechat_plugin->name, + server->name); + } + + /* + * when UTF8ONLY is enabled, clients must not send non-UTF-8 data + * to the server; the charset encoding below is then done only if + * UTF8ONLY is *NOT* enabled + * (see: https://ircv3.net/specs/extensions/utf8-only) + */ + if (!server->utf8only) + { + msg_encoded = irc_message_convert_charset (ptr_msg, pos_encode, + "charset_encode", + modifier_data); + } + } + + if (msg_encoded) + ptr_msg = msg_encoded; + + while (ptr_msg && ptr_msg[0]) + { + pos = strchr (ptr_msg, '\n'); + if (pos) + pos[0] = '\0'; + + snprintf (buffer, sizeof (buffer), "%s\r\n", ptr_msg); + + if (flags & IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE) + queue_msg = 0; + else if (flags & IRC_SERVER_SEND_OUTQ_PRIO_HIGH) + queue_msg = 1; + else if (flags & IRC_SERVER_SEND_OUTQ_PRIO_LOW) + queue_msg = 2; + else + { + /* + * if connected to server (message 001 received), consider + * it's low priority (otherwise send immediately) + */ + queue_msg = (server->is_connected) ? 2 : 0; + } + + tags_to_send = irc_server_get_tags_to_send (tags); + + ptr_redirect = irc_redirect_search_available (server); + + /* queue message (do not send anything now) */ + irc_server_outqueue_add (server, + queue_msg, + command, + (new_msg && first_message) ? message : NULL, + buffer, + (new_msg) ? 1 : 0, + tags_to_send, + ptr_redirect); + + /* mark redirect as "used" */ + if (ptr_redirect) + ptr_redirect->assigned_to_command = 1; + + free (tags_to_send); + + if (pos) + { + pos[0] = '\n'; + ptr_msg = pos + 1; + } + else + ptr_msg = NULL; + + first_message = 0; + } + free (msg_encoded); + free (new_msg); } @@ -3450,7 +3446,7 @@ irc_server_msgq_add_unterminated (struct t_irc_server *server, */ void -irc_server_msgq_add_buffer (struct t_irc_server *server, const char *buffer) +irc_server_msgq_add_buffer (struct t_irc_server *server, char *buffer) { char *pos_cr, *pos_lf; diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 9693c51a1..48e562a25 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -427,7 +427,7 @@ extern struct t_arraylist *irc_server_sendf (struct t_irc_server *server, const char *tags, const char *format, ...); extern void irc_server_msgq_add_buffer (struct t_irc_server *server, - const char *buffer); + char *buffer); extern void irc_server_msgq_flush (void); extern void irc_server_set_buffer_title (struct t_irc_server *server); extern struct t_gui_buffer *irc_server_create_buffer (struct t_irc_server *server);