| File: | irc/core/irc-channels.c |
| Location: | line 155, column 3 |
| Description: | Value stored to 'cmdlen' is never read |
| 1 | /* |
| 2 | irc-channels.c : irssi |
| 3 | |
| 4 | Copyright (C) 1999-2000 Timo Sirainen |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License along |
| 17 | with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include "module.h" |
| 22 | #include "signals.h" |
| 23 | #include "misc.h" |
| 24 | #include "levels.h" |
| 25 | #include "channels-setup.h" |
| 26 | |
| 27 | #include "bans.h" |
| 28 | #include "modes.h" |
| 29 | #include "mode-lists.h" |
| 30 | #include "irc-servers.h" |
| 31 | #include "irc-channels.h" |
| 32 | #include "irc-nicklist.h" |
| 33 | #include "channel-rejoin.h" |
| 34 | |
| 35 | void channels_query_init(void); |
| 36 | void channels_query_deinit(void); |
| 37 | |
| 38 | void channel_events_init(void); |
| 39 | void channel_events_deinit(void); |
| 40 | |
| 41 | void irc_channels_setup_init(void); |
| 42 | void irc_channels_setup_deinit(void); |
| 43 | |
| 44 | void massjoin_init(void); |
| 45 | void massjoin_deinit(void); |
| 46 | |
| 47 | IRC_CHANNEL_REC *irc_channel_create(IRC_SERVER_REC *server, const char *name, |
| 48 | const char *visible_name, int automatic) |
| 49 | { |
| 50 | IRC_CHANNEL_REC *rec; |
| 51 | |
| 52 | g_return_val_if_fail(server == NULL || IS_IRC_SERVER(server), NULL)do{ if (server == ((void *)0) || (((IRC_SERVER_REC *) chat_protocol_check_cast (((SERVER_REC *) module_check_cast(server, __builtin_offsetof (SERVER_REC, type), "SERVER")), __builtin_offsetof(IRC_SERVER_REC , chat_type), "IRC")) ? (!(0)) : (0))) { } else { g_return_if_fail_warning (((gchar*) 0), __PRETTY_FUNCTION__, "server == NULL || IS_IRC_SERVER(server)" ); return (((void *)0)); }; }while (0); |
| 53 | g_return_val_if_fail(name != NULL, NULL)do{ if (name != ((void *)0)) { } else { g_return_if_fail_warning (((gchar*) 0), __PRETTY_FUNCTION__, "name != NULL"); return ( ((void *)0)); }; }while (0); |
| 54 | |
| 55 | rec = g_new0(IRC_CHANNEL_REC, 1)((IRC_CHANNEL_REC *) g_malloc0 (((gsize) sizeof (IRC_CHANNEL_REC )) * ((gsize) (1)))); |
| 56 | if (*name == '+') rec->no_modes = TRUE(!(0)); |
| 57 | |
| 58 | channel_init((CHANNEL_REC *) rec, (SERVER_REC *) server, |
| 59 | name, visible_name, automatic); |
| 60 | return rec; |
| 61 | } |
| 62 | |
| 63 | #define get_join_key(key)(((key) == ((void *)0) || *(key) == '\0') ? "x" : (key)) \ |
| 64 | (((key) == NULL((void *)0) || *(key) == '\0') ? "x" : (key)) |
| 65 | |
| 66 | static void irc_channels_join(IRC_SERVER_REC *server, const char *data, |
| 67 | int automatic) |
| 68 | { |
| 69 | CHANNEL_SETUP_REC *schannel; |
| 70 | IRC_CHANNEL_REC *chanrec; |
| 71 | GString *outchans, *outkeys; |
| 72 | char *channels, *keys, *key, *space; |
| 73 | char **chanlist, **keylist, **tmp, **tmpkey, **tmpstr, *channel, *channame; |
| 74 | void *free_arg; |
| 75 | int use_keys, cmdlen; |
| 76 | |
| 77 | g_return_if_fail(data != NULL)do{ if (data != ((void *)0)) { } else { g_return_if_fail_warning (((gchar*) 0), __PRETTY_FUNCTION__, "data != NULL"); return; }; }while (0); |
| 78 | g_return_if_fail(IS_IRC_SERVER(server) && server->connected)do{ if ((((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *) module_check_cast(server, __builtin_offsetof(SERVER_REC, type ), "SERVER")), __builtin_offsetof(IRC_SERVER_REC, chat_type), "IRC")) ? (!(0)) : (0)) && server->connected) { } else { g_return_if_fail_warning (((gchar*) 0), __PRETTY_FUNCTION__ , "IS_IRC_SERVER(server) && server->connected"); return ; }; }while (0); |
| 79 | if (*data == '\0') return; |
| 80 | |
| 81 | if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST0x00002000, |
| 82 | &channels, &keys)) |
| 83 | return; |
| 84 | |
| 85 | /* keys shouldn't contain space */ |
| 86 | space = strchr(keys, ' '); |
| 87 | if (space != NULL((void *)0)) { |
| 88 | *space = '\0'; |
| 89 | } |
| 90 | |
| 91 | chanlist = g_strsplit(channels, ",", -1); |
| 92 | keylist = g_strsplit(keys, ",", -1); |
| 93 | |
| 94 | outchans = g_string_new(NULL((void *)0)); |
| 95 | outkeys = g_string_new(NULL((void *)0)); |
| 96 | |
| 97 | use_keys = *keys != '\0'; |
| 98 | tmpkey = keylist; |
| 99 | tmp = chanlist; |
| 100 | for (;; tmp++) { |
| 101 | if (*tmp != NULL((void *)0)) { |
| 102 | channel = ischannel(**tmp)((**tmp) == '#' || (**tmp) == '&' || (**tmp) == '!' || (* *tmp) == '+') ? g_strdup(*tmp) : |
| 103 | g_strdup_printf("#%s", *tmp); |
| 104 | |
| 105 | chanrec = irc_channel_find(server, channel)((IRC_CHANNEL_REC *) chat_protocol_check_cast(((CHANNEL_REC * ) module_check_cast_module(channel_find(((SERVER_REC *) module_check_cast (server, __builtin_offsetof(SERVER_REC, type), "SERVER")), channel ), __builtin_offsetof(CHANNEL_REC, type), "WINDOW ITEM TYPE", "CHANNEL")), __builtin_offsetof(IRC_CHANNEL_REC, chat_type), "IRC")); |
| 106 | if (chanrec == NULL((void *)0)) { |
| 107 | schannel = channel_setup_find(channel, server->connrec->chatnet); |
| 108 | |
| 109 | g_string_append_printf(outchans, "%s,", channel); |
| 110 | if (*tmpkey != NULL((void *)0) && **tmpkey != '\0') |
| 111 | key = *tmpkey; |
| 112 | else if (schannel != NULL((void *)0) && schannel->password != NULL((void *)0)) { |
| 113 | /* get password from setup record */ |
| 114 | use_keys = TRUE(!(0)); |
| 115 | key = schannel->password; |
| 116 | } else key = NULL((void *)0); |
| 117 | |
| 118 | g_string_append_printf(outkeys, "%s,", get_join_key(key)(((key) == ((void *)0) || *(key) == '\0') ? "x" : (key))); |
| 119 | channame = channel + (channel[0] == '!' && |
| 120 | channel[1] == '!'); |
| 121 | chanrec = irc_channel_create(server, channame, NULL((void *)0), |
| 122 | automatic); |
| 123 | if (key != NULL((void *)0)) chanrec->key = g_strdup(key); |
| 124 | } |
| 125 | g_free(channel); |
| 126 | |
| 127 | if (*tmpkey != NULL((void *)0)) |
| 128 | tmpkey++; |
| 129 | |
| 130 | tmpstr = tmp; |
| 131 | tmpstr++; |
| 132 | cmdlen = outchans->len-1; |
| 133 | |
| 134 | if (use_keys) |
| 135 | cmdlen += outkeys->len; |
| 136 | if (*tmpstr != NULL((void *)0)) |
| 137 | cmdlen += ischannel(**tmpstr)((**tmpstr) == '#' || (**tmpstr) == '&' || (**tmpstr) == '!' || (**tmpstr) == '+') ? strlen(*tmpstr) : |
| 138 | strlen(*tmpstr)+1; |
| 139 | if (*tmpkey != NULL((void *)0)) |
| 140 | cmdlen += strlen(*tmpkey); |
| 141 | |
| 142 | /* don't try to send too long lines |
| 143 | make sure it's not longer than 510 |
| 144 | so 510 - strlen("JOIN ") = 505 */ |
| 145 | if (cmdlen < 505) |
| 146 | continue; |
| 147 | } |
| 148 | if (outchans->len > 0) { |
| 149 | g_string_truncate(outchans, outchans->len-1); |
| 150 | g_string_truncate(outkeys, outkeys->len-1); |
| 151 | irc_send_cmdv(IRC_SERVER(server)((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *) module_check_cast (server, __builtin_offsetof(SERVER_REC, type), "SERVER")), __builtin_offsetof (IRC_SERVER_REC, chat_type), "IRC")), |
| 152 | use_keys ? "JOIN %s %s" : "JOIN %s", |
| 153 | outchans->str, outkeys->str); |
| 154 | } |
| 155 | cmdlen = 0; |
Value stored to 'cmdlen' is never read | |
| 156 | g_string_truncate(outchans,0); |
| 157 | g_string_truncate(outkeys,0); |
| 158 | if (*tmp == NULL((void *)0) || tmp[1] == NULL((void *)0)) |
| 159 | break; |
| 160 | } |
| 161 | g_string_free(outchans, TRUE(!(0))); |
| 162 | g_string_free(outkeys, TRUE(!(0))); |
| 163 | |
| 164 | g_strfreev(chanlist); |
| 165 | g_strfreev(keylist); |
| 166 | |
| 167 | cmd_params_free(free_arg); |
| 168 | } |
| 169 | |
| 170 | /* function for finding IRC channels - adds support for !channels */ |
| 171 | static CHANNEL_REC *irc_channel_find_server(SERVER_REC *server, |
| 172 | const char *channel) |
| 173 | { |
| 174 | GSList *tmp; |
| 175 | |
| 176 | for (tmp = server->channels; tmp != NULL((void *)0); tmp = tmp->next) { |
| 177 | CHANNEL_REC *rec = tmp->data; |
| 178 | |
| 179 | if (rec->chat_type != server->chat_type) |
| 180 | continue; |
| 181 | |
| 182 | /* check both !ABCDEchannel and !channel */ |
| 183 | if (IRC_SERVER(server)((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *) module_check_cast (server, __builtin_offsetof(SERVER_REC, type), "SERVER")), __builtin_offsetof (IRC_SERVER_REC, chat_type), "IRC"))->nick_comp_func(channel, rec->name) == 0) |
| 184 | return rec; |
| 185 | |
| 186 | if (IRC_SERVER(server)((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *) module_check_cast (server, __builtin_offsetof(SERVER_REC, type), "SERVER")), __builtin_offsetof (IRC_SERVER_REC, chat_type), "IRC"))->nick_comp_func(channel, rec->visible_name) == 0) |
| 187 | return rec; |
| 188 | } |
| 189 | |
| 190 | return NULL((void *)0); |
| 191 | } |
| 192 | |
| 193 | static void sig_server_connected(SERVER_REC *server) |
| 194 | { |
| 195 | if (!IS_IRC_SERVER(server)(((IRC_SERVER_REC *) chat_protocol_check_cast(((SERVER_REC *) module_check_cast(server, __builtin_offsetof(SERVER_REC, type ), "SERVER")), __builtin_offsetof(IRC_SERVER_REC, chat_type), "IRC")) ? (!(0)) : (0))) |
| 196 | return; |
| 197 | |
| 198 | server->channel_find_func = irc_channel_find_server; |
| 199 | server->channels_join = (void (*) (SERVER_REC *, const char *, int)) |
| 200 | irc_channels_join; |
| 201 | } |
| 202 | |
| 203 | static char *irc_get_join_data(CHANNEL_REC *channel) |
| 204 | { |
| 205 | IRC_CHANNEL_REC *irc_channel = (IRC_CHANNEL_REC *) channel; |
| 206 | |
| 207 | return irc_channel->key == NULL((void *)0) ? g_strdup(irc_channel->name) : |
| 208 | g_strconcat(irc_channel->name, " ", irc_channel->key, NULL((void *)0)); |
| 209 | } |
| 210 | |
| 211 | static void sig_channel_created(IRC_CHANNEL_REC *channel) |
| 212 | { |
| 213 | if (IS_IRC_CHANNEL(channel)(((IRC_CHANNEL_REC *) chat_protocol_check_cast(((CHANNEL_REC * ) module_check_cast_module(channel, __builtin_offsetof(CHANNEL_REC , type), "WINDOW ITEM TYPE", "CHANNEL")), __builtin_offsetof( IRC_CHANNEL_REC, chat_type), "IRC")) ? (!(0)) : (0))) |
| 214 | channel->get_join_data = irc_get_join_data; |
| 215 | } |
| 216 | |
| 217 | static void sig_channel_destroyed(IRC_CHANNEL_REC *channel) |
| 218 | { |
| 219 | if (!IS_IRC_CHANNEL(channel)(((IRC_CHANNEL_REC *) chat_protocol_check_cast(((CHANNEL_REC * ) module_check_cast_module(channel, __builtin_offsetof(CHANNEL_REC , type), "WINDOW ITEM TYPE", "CHANNEL")), __builtin_offsetof( IRC_CHANNEL_REC, chat_type), "IRC")) ? (!(0)) : (0))) |
| 220 | return; |
| 221 | |
| 222 | if (!channel->server->disconnected && !channel->left && !channel->kicked) { |
| 223 | /* destroying channel record without actually |
| 224 | having left the channel yet */ |
| 225 | signal_emit("command part", 3, "", channel->server, channel); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | void irc_channels_init(void) |
| 230 | { |
| 231 | signal_add_first("server connected", (SIGNAL_FUNC) sig_server_connected)signal_add_full("irc/core", -100, ("server connected"), (SIGNAL_FUNC ) ((SIGNAL_FUNC) sig_server_connected), ((void *)0)); |
| 232 | signal_add("channel created", (SIGNAL_FUNC) sig_channel_created)signal_add_full("irc/core", 0, ("channel created"), (SIGNAL_FUNC ) ((SIGNAL_FUNC) sig_channel_created), ((void *)0)); |
| 233 | signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed)signal_add_full("irc/core", 0, ("channel destroyed"), (SIGNAL_FUNC ) ((SIGNAL_FUNC) sig_channel_destroyed), ((void *)0)); |
| 234 | |
| 235 | channel_events_init(); |
| 236 | channel_rejoin_init(); /* after channel_events_init() */ |
| 237 | channels_query_init(); |
| 238 | irc_channels_setup_init(); |
| 239 | |
| 240 | bans_init(); |
| 241 | modes_init(); |
| 242 | mode_lists_init(); |
| 243 | massjoin_init(); |
| 244 | irc_nicklist_init(); |
| 245 | } |
| 246 | |
| 247 | void irc_channels_deinit(void) |
| 248 | { |
| 249 | signal_remove("server connected", (SIGNAL_FUNC) sig_server_connected)signal_remove_full(("server connected"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_server_connected), ((void *)0)); |
| 250 | signal_remove("channel created", (SIGNAL_FUNC) sig_channel_created)signal_remove_full(("channel created"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_channel_created), ((void *)0)); |
| 251 | signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed)signal_remove_full(("channel destroyed"), (SIGNAL_FUNC) ((SIGNAL_FUNC ) sig_channel_destroyed), ((void *)0)); |
| 252 | |
| 253 | channel_events_deinit(); |
| 254 | channel_rejoin_deinit(); |
| 255 | channels_query_deinit(); |
| 256 | irc_channels_setup_deinit(); |
| 257 | |
| 258 | bans_deinit(); |
| 259 | modes_deinit(); |
| 260 | mode_lists_deinit(); |
| 261 | massjoin_deinit(); |
| 262 | irc_nicklist_deinit(); |
| 263 | } |