[81e04e1] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
| 4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
| 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* Some glue to put the IRC and the IM stuff together. */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 23 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "bitlbee.h" |
---|
[17a6ee9] | 27 | #include "dcc.h" |
---|
[d860a8d] | 28 | |
---|
[e4816ea] | 29 | /* IM->IRC callbacks: Simple IM/buddy-related stuff. */ |
---|
[d860a8d] | 30 | |
---|
[81e04e1] | 31 | static const struct irc_user_funcs irc_user_im_funcs; |
---|
| 32 | |
---|
[5c7b45c] | 33 | static void bee_irc_imc_connected( struct im_connection *ic ) |
---|
| 34 | { |
---|
| 35 | irc_t *irc = (irc_t*) ic->bee->ui_data; |
---|
| 36 | |
---|
| 37 | irc_channel_auto_joins( irc, ic->acc ); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | static void bee_irc_imc_disconnected( struct im_connection *ic ) |
---|
| 41 | { |
---|
| 42 | /* Maybe try to send /QUITs here instead of later on. */ |
---|
| 43 | } |
---|
| 44 | |
---|
[81e04e1] | 45 | static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu ) |
---|
| 46 | { |
---|
| 47 | irc_user_t *iu; |
---|
[92c8d41] | 48 | irc_t *irc = (irc_t*) bee->ui_data; |
---|
[81e04e1] | 49 | char nick[MAX_NICK_LENGTH+1], *s; |
---|
| 50 | |
---|
| 51 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
[b1f818b] | 52 | strcpy( nick, nick_get( bu ) ); |
---|
[81e04e1] | 53 | |
---|
[92c8d41] | 54 | bu->ui_data = iu = irc_user_new( irc, nick ); |
---|
[d860a8d] | 55 | iu->bu = bu; |
---|
[81e04e1] | 56 | |
---|
[bb151f7] | 57 | if( set_getbool( &irc->b->set, "private" ) ) |
---|
| 58 | iu->last_channel = NULL; |
---|
| 59 | else |
---|
| 60 | iu->last_channel = irc_channel_with_user( irc, iu ); |
---|
| 61 | |
---|
[81e04e1] | 62 | if( ( s = strchr( bu->handle, '@' ) ) ) |
---|
| 63 | { |
---|
| 64 | iu->host = g_strdup( s + 1 ); |
---|
| 65 | iu->user = g_strndup( bu->handle, s - bu->handle ); |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | iu->user = g_strdup( bu->handle ); |
---|
[495d21b] | 70 | if( bu->ic->acc->server ) |
---|
| 71 | iu->host = g_strdup( bu->ic->acc->server ); |
---|
| 72 | else |
---|
| 73 | iu->host = g_strdup( bu->ic->acc->prpl->name ); |
---|
[81e04e1] | 74 | } |
---|
| 75 | |
---|
[495d21b] | 76 | while( ( s = strchr( iu->user, ' ' ) ) ) |
---|
| 77 | *s = '_'; |
---|
| 78 | |
---|
[ad404ab] | 79 | if( bu->flags & BEE_USER_LOCAL ) |
---|
| 80 | { |
---|
| 81 | char *s = set_getstr( &bee->set, "handle_unknown" ); |
---|
| 82 | |
---|
| 83 | if( strcmp( s, "add_private" ) == 0 ) |
---|
[92c8d41] | 84 | iu->last_channel = NULL; |
---|
[ad404ab] | 85 | else if( strcmp( s, "add_channel" ) == 0 ) |
---|
[92c8d41] | 86 | iu->last_channel = irc->default_channel; |
---|
[ad404ab] | 87 | } |
---|
| 88 | |
---|
[81e04e1] | 89 | iu->f = &irc_user_im_funcs; |
---|
| 90 | |
---|
| 91 | return TRUE; |
---|
| 92 | } |
---|
| 93 | |
---|
[d860a8d] | 94 | static gboolean bee_irc_user_free( bee_t *bee, bee_user_t *bu ) |
---|
| 95 | { |
---|
[eabc9d2] | 96 | return irc_user_free( bee->ui_data, (irc_user_t *) bu->ui_data ); |
---|
[d860a8d] | 97 | } |
---|
[81e04e1] | 98 | |
---|
[d860a8d] | 99 | static gboolean bee_irc_user_status( bee_t *bee, bee_user_t *bu, bee_user_t *old ) |
---|
| 100 | { |
---|
[231b08b] | 101 | irc_t *irc = bee->ui_data; |
---|
[003a12b] | 102 | irc_user_t *iu = bu->ui_data; |
---|
[231b08b] | 103 | |
---|
[eb50495] | 104 | /* Do this outside the if below since away state can change without |
---|
| 105 | the online state changing. */ |
---|
| 106 | iu->flags &= ~IRC_USER_AWAY; |
---|
| 107 | if( bu->flags & BEE_USER_AWAY || !( bu->flags & BEE_USER_ONLINE ) ) |
---|
| 108 | iu->flags |= IRC_USER_AWAY; |
---|
| 109 | |
---|
[231b08b] | 110 | if( ( bu->flags & BEE_USER_ONLINE ) != ( old->flags & BEE_USER_ONLINE ) ) |
---|
| 111 | { |
---|
| 112 | if( bu->flags & BEE_USER_ONLINE ) |
---|
[003a12b] | 113 | { |
---|
| 114 | if( g_hash_table_lookup( irc->watches, iu->key ) ) |
---|
| 115 | irc_send_num( irc, 600, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
| 116 | iu->host, (int) time( NULL ), "logged online" ); |
---|
| 117 | } |
---|
[231b08b] | 118 | else |
---|
[003a12b] | 119 | { |
---|
| 120 | if( g_hash_table_lookup( irc->watches, iu->key ) ) |
---|
| 121 | irc_send_num( irc, 601, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
| 122 | iu->host, (int) time( NULL ), "logged offline" ); |
---|
[0bd948e] | 123 | |
---|
| 124 | /* Send a QUIT since those will also show up in any |
---|
| 125 | query windows the user may have, plus it's only |
---|
| 126 | one QUIT instead of possibly many (in case of |
---|
| 127 | multiple control chans). If there's a channel that |
---|
| 128 | shows offline people, a JOIN will follow. */ |
---|
| 129 | if( set_getbool( &bee->set, "offline_user_quits" ) ) |
---|
| 130 | irc_user_quit( iu, "Leaving..." ); |
---|
[003a12b] | 131 | } |
---|
[231b08b] | 132 | } |
---|
| 133 | |
---|
[1c8e5f7] | 134 | /* Reset this one since the info may have changed. */ |
---|
| 135 | iu->away_reply_timeout = 0; |
---|
| 136 | |
---|
[13c1a9f] | 137 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 138 | |
---|
[d860a8d] | 139 | return TRUE; |
---|
| 140 | } |
---|
[81e04e1] | 141 | |
---|
[13c1a9f] | 142 | void bee_irc_channel_update( irc_t *irc, irc_channel_t *ic, irc_user_t *iu ) |
---|
| 143 | { |
---|
| 144 | GSList *l; |
---|
| 145 | |
---|
| 146 | if( ic == NULL ) |
---|
| 147 | { |
---|
| 148 | for( l = irc->channels; l; l = l->next ) |
---|
| 149 | { |
---|
| 150 | ic = l->data; |
---|
| 151 | /* TODO: Just add a type flag or so.. */ |
---|
[9052bc1] | 152 | if( ic->f == irc->default_channel->f && |
---|
| 153 | ( ic->flags & IRC_CHANNEL_JOINED ) ) |
---|
[13c1a9f] | 154 | bee_irc_channel_update( irc, ic, iu ); |
---|
| 155 | } |
---|
| 156 | return; |
---|
| 157 | } |
---|
| 158 | if( iu == NULL ) |
---|
| 159 | { |
---|
| 160 | for( l = irc->users; l; l = l->next ) |
---|
| 161 | { |
---|
| 162 | iu = l->data; |
---|
| 163 | if( iu->bu ) |
---|
| 164 | bee_irc_channel_update( irc, ic, l->data ); |
---|
| 165 | } |
---|
| 166 | return; |
---|
| 167 | } |
---|
| 168 | |
---|
[ac2717b] | 169 | if( !irc_channel_wants_user( ic, iu ) ) |
---|
[13c1a9f] | 170 | { |
---|
[006a84f] | 171 | irc_channel_del_user( ic, iu, IRC_CDU_PART, NULL ); |
---|
[13c1a9f] | 172 | } |
---|
| 173 | else |
---|
| 174 | { |
---|
[ac2717b] | 175 | struct irc_control_channel *icc = ic->data; |
---|
[94d5da9c] | 176 | int mode = 0; |
---|
[13c1a9f] | 177 | |
---|
[94d5da9c] | 178 | if( !( iu->bu->flags & BEE_USER_ONLINE ) ) |
---|
| 179 | mode = icc->modes[0]; |
---|
| 180 | else if( iu->bu->flags & BEE_USER_AWAY ) |
---|
| 181 | mode = icc->modes[1]; |
---|
[0e8b3e8] | 182 | else |
---|
[94d5da9c] | 183 | mode = icc->modes[2]; |
---|
| 184 | |
---|
| 185 | if( !mode ) |
---|
| 186 | irc_channel_del_user( ic, iu, IRC_CDU_PART, NULL ); |
---|
| 187 | else |
---|
| 188 | { |
---|
| 189 | irc_channel_add_user( ic, iu ); |
---|
| 190 | irc_channel_user_set_mode( ic, iu, mode ); |
---|
| 191 | } |
---|
[13c1a9f] | 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
[934db064] | 195 | static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg_, time_t sent_at ) |
---|
[f012a9f] | 196 | { |
---|
| 197 | irc_t *irc = bee->ui_data; |
---|
| 198 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 199 | char *dst, *prefix = NULL; |
---|
[21c87a7] | 200 | char *wrapped, *ts = NULL; |
---|
[2fe5eb9] | 201 | irc_channel_t *ic = NULL; |
---|
[934db064] | 202 | char *msg = g_strdup( msg_ ); |
---|
| 203 | GSList *l; |
---|
[21c87a7] | 204 | |
---|
| 205 | if( sent_at > 0 && set_getbool( &irc->b->set, "display_timestamps" ) ) |
---|
| 206 | ts = irc_format_timestamp( irc, sent_at ); |
---|
[f012a9f] | 207 | |
---|
[f7ca587] | 208 | /* Too similar to irc_usermsg()... */ |
---|
[92c8d41] | 209 | if( iu->last_channel ) |
---|
[f012a9f] | 210 | { |
---|
[2fe5eb9] | 211 | if( iu->last_channel->flags & IRC_CHANNEL_JOINED ) |
---|
| 212 | ic = iu->last_channel; |
---|
[bb151f7] | 213 | else |
---|
| 214 | ic = irc_channel_with_user( irc, iu ); |
---|
[2fe5eb9] | 215 | } |
---|
| 216 | |
---|
| 217 | if( ic ) |
---|
| 218 | { |
---|
| 219 | dst = ic->name; |
---|
[92c8d41] | 220 | prefix = g_strdup_printf( "%s%s%s", irc->user->nick, set_getstr( &bee->set, "to_char" ), ts ? : "" ); |
---|
[f012a9f] | 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
[92c8d41] | 224 | dst = irc->user->nick; |
---|
| 225 | prefix = ts; |
---|
| 226 | ts = NULL; |
---|
[f012a9f] | 227 | } |
---|
| 228 | |
---|
[934db064] | 229 | for( l = irc_plugins; l; l = l->next ) |
---|
| 230 | { |
---|
| 231 | irc_plugin_t *p = l->data; |
---|
| 232 | if( p->filter_msg_in ) |
---|
| 233 | { |
---|
| 234 | char *s = p->filter_msg_in( iu, msg, 0 ); |
---|
| 235 | if( s ) |
---|
| 236 | { |
---|
| 237 | if( s != msg ) |
---|
| 238 | g_free( msg ); |
---|
| 239 | msg = s; |
---|
| 240 | } |
---|
| 241 | else |
---|
| 242 | { |
---|
| 243 | /* Modules can swallow messages. */ |
---|
| 244 | return TRUE; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | if( ( g_strcasecmp( set_getstr( &bee->set, "strip_html" ), "always" ) == 0 ) || |
---|
| 250 | ( ( bu->ic->flags & OPT_DOES_HTML ) && set_getbool( &bee->set, "strip_html" ) ) ) |
---|
| 251 | { |
---|
| 252 | char *s = g_strdup( msg ); |
---|
| 253 | strip_html( s ); |
---|
| 254 | g_free( msg ); |
---|
| 255 | msg = s; |
---|
| 256 | } |
---|
| 257 | |
---|
[f012a9f] | 258 | wrapped = word_wrap( msg, 425 ); |
---|
| 259 | irc_send_msg( iu, "PRIVMSG", dst, wrapped, prefix ); |
---|
| 260 | |
---|
| 261 | g_free( wrapped ); |
---|
| 262 | g_free( prefix ); |
---|
[934db064] | 263 | g_free( msg ); |
---|
[21c87a7] | 264 | g_free( ts ); |
---|
[f012a9f] | 265 | |
---|
| 266 | return TRUE; |
---|
| 267 | } |
---|
| 268 | |
---|
[573dab0] | 269 | static gboolean bee_irc_user_typing( bee_t *bee, bee_user_t *bu, uint32_t flags ) |
---|
| 270 | { |
---|
| 271 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
| 272 | |
---|
| 273 | if( set_getbool( &bee->set, "typing_notice" ) ) |
---|
| 274 | irc_send_msg_f( (irc_user_t *) bu->ui_data, "PRIVMSG", irc->user->nick, |
---|
| 275 | "\001TYPING %d\001", ( flags >> 8 ) & 3 ); |
---|
| 276 | else |
---|
| 277 | return FALSE; |
---|
| 278 | |
---|
| 279 | return TRUE; |
---|
| 280 | } |
---|
| 281 | |
---|
[badd148] | 282 | static gboolean bee_irc_user_nick_update( irc_user_t *iu ); |
---|
[6ef9065] | 283 | |
---|
[1d39159] | 284 | static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu ) |
---|
| 285 | { |
---|
| 286 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 287 | char *s; |
---|
| 288 | |
---|
| 289 | if( iu->fullname != iu->nick ) |
---|
| 290 | g_free( iu->fullname ); |
---|
| 291 | iu->fullname = g_strdup( bu->fullname ); |
---|
| 292 | |
---|
| 293 | /* Strip newlines (unlikely, but IRC-unfriendly so they must go) |
---|
| 294 | TODO(wilmer): Do the same with away msgs again! */ |
---|
| 295 | for( s = iu->fullname; *s; s ++ ) |
---|
| 296 | if( isspace( *s ) ) *s = ' '; |
---|
| 297 | |
---|
| 298 | if( ( bu->ic->flags & OPT_LOGGED_IN ) && set_getbool( &bee->set, "display_namechanges" ) ) |
---|
| 299 | { |
---|
[fda55fa] | 300 | /* People don't like this /NOTICE. Meh, let's go back to the old one. |
---|
[1d39159] | 301 | char *msg = g_strdup_printf( "<< \002BitlBee\002 - Changed name to `%s' >>", iu->fullname ); |
---|
| 302 | irc_send_msg( iu, "NOTICE", irc->user->nick, msg, NULL ); |
---|
[fda55fa] | 303 | */ |
---|
| 304 | imcb_log( bu->ic, "User `%s' changed name to `%s'", iu->nick, iu->fullname ); |
---|
[1d39159] | 305 | } |
---|
| 306 | |
---|
[badd148] | 307 | bee_irc_user_nick_update( iu ); |
---|
[1d39159] | 308 | |
---|
| 309 | return TRUE; |
---|
| 310 | } |
---|
| 311 | |
---|
[6ef9065] | 312 | static gboolean bee_irc_user_nick_hint( bee_t *bee, bee_user_t *bu, const char *hint ) |
---|
| 313 | { |
---|
[badd148] | 314 | bee_irc_user_nick_update( (irc_user_t*) bu->ui_data ); |
---|
| 315 | |
---|
| 316 | return TRUE; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | static gboolean bee_irc_user_group( bee_t *bee, bee_user_t *bu ) |
---|
| 320 | { |
---|
| 321 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 322 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
[51a3d12] | 323 | bee_user_flags_t online; |
---|
| 324 | |
---|
| 325 | /* Take the user offline temporarily so we can change the nick (if necessary). */ |
---|
| 326 | if( ( online = bu->flags & BEE_USER_ONLINE ) ) |
---|
| 327 | bu->flags &= ~BEE_USER_ONLINE; |
---|
[badd148] | 328 | |
---|
| 329 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 330 | bee_irc_user_nick_update( iu ); |
---|
| 331 | |
---|
[51a3d12] | 332 | if( online ) |
---|
| 333 | { |
---|
| 334 | bu->flags |= online; |
---|
| 335 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 336 | } |
---|
| 337 | |
---|
[badd148] | 338 | return TRUE; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | static gboolean bee_irc_user_nick_update( irc_user_t *iu ) |
---|
| 342 | { |
---|
| 343 | bee_user_t *bu = iu->bu; |
---|
| 344 | char *newnick; |
---|
[6ef9065] | 345 | |
---|
| 346 | if( bu->flags & BEE_USER_ONLINE ) |
---|
| 347 | /* Ignore if the user is visible already. */ |
---|
| 348 | return TRUE; |
---|
| 349 | |
---|
[b1f818b] | 350 | if( nick_saved( bu ) ) |
---|
[6ef9065] | 351 | /* The user already assigned a nickname to this person. */ |
---|
| 352 | return TRUE; |
---|
| 353 | |
---|
[badd148] | 354 | newnick = nick_get( bu ); |
---|
[6ef9065] | 355 | |
---|
| 356 | if( strcmp( iu->nick, newnick ) != 0 ) |
---|
| 357 | { |
---|
[b1f818b] | 358 | nick_dedupe( bu, newnick ); |
---|
[6ef9065] | 359 | irc_user_set_nick( iu, newnick ); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | return TRUE; |
---|
| 363 | } |
---|
| 364 | |
---|
[a429907] | 365 | void bee_irc_user_nick_reset( irc_user_t *iu ) |
---|
| 366 | { |
---|
| 367 | bee_user_t *bu = iu->bu; |
---|
| 368 | bee_user_flags_t online; |
---|
| 369 | |
---|
| 370 | if( bu == FALSE ) |
---|
| 371 | return; |
---|
| 372 | |
---|
| 373 | /* In this case, pretend the user is offline. */ |
---|
| 374 | if( ( online = bu->flags & BEE_USER_ONLINE ) ) |
---|
| 375 | bu->flags &= ~BEE_USER_ONLINE; |
---|
| 376 | |
---|
| 377 | nick_del( bu ); |
---|
| 378 | bee_irc_user_nick_update( iu ); |
---|
| 379 | |
---|
| 380 | bu->flags |= online; |
---|
| 381 | } |
---|
| 382 | |
---|
[e4816ea] | 383 | /* IRC->IM calls */ |
---|
| 384 | |
---|
[619dd18] | 385 | static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); |
---|
| 386 | |
---|
[e4816ea] | 387 | static gboolean bee_irc_user_privmsg( irc_user_t *iu, const char *msg ) |
---|
| 388 | { |
---|
[1c8e5f7] | 389 | const char *away; |
---|
| 390 | |
---|
[619dd18] | 391 | if( iu->bu == NULL ) |
---|
[e4816ea] | 392 | return FALSE; |
---|
[1c8e5f7] | 393 | |
---|
| 394 | if( ( away = irc_user_get_away( iu ) ) && |
---|
| 395 | time( NULL ) >= iu->away_reply_timeout ) |
---|
| 396 | { |
---|
| 397 | irc_send_num( iu->irc, 301, "%s :%s", iu->nick, away ); |
---|
| 398 | iu->away_reply_timeout = time( NULL ) + |
---|
| 399 | set_getint( &iu->irc->b->set, "away_reply_timeout" ); |
---|
| 400 | } |
---|
| 401 | |
---|
[934db064] | 402 | if( iu->pastebuf == NULL ) |
---|
| 403 | iu->pastebuf = g_string_new( msg ); |
---|
| 404 | else |
---|
| 405 | { |
---|
| 406 | b_event_remove( iu->pastebuf_timer ); |
---|
| 407 | g_string_append_printf( iu->pastebuf, "\n%s", msg ); |
---|
| 408 | } |
---|
| 409 | |
---|
[1c8e5f7] | 410 | if( set_getbool( &iu->irc->b->set, "paste_buffer" ) ) |
---|
[619dd18] | 411 | { |
---|
| 412 | int delay; |
---|
| 413 | |
---|
| 414 | if( ( delay = set_getint( &iu->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) |
---|
| 415 | delay *= 1000; |
---|
| 416 | |
---|
| 417 | iu->pastebuf_timer = b_timeout_add( delay, bee_irc_user_privmsg_cb, iu ); |
---|
| 418 | |
---|
| 419 | return TRUE; |
---|
| 420 | } |
---|
| 421 | else |
---|
[934db064] | 422 | { |
---|
| 423 | bee_irc_user_privmsg_cb( iu, 0, 0 ); |
---|
| 424 | |
---|
| 425 | return TRUE; |
---|
| 426 | } |
---|
[619dd18] | 427 | } |
---|
| 428 | |
---|
| 429 | static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) |
---|
| 430 | { |
---|
| 431 | irc_user_t *iu = data; |
---|
[934db064] | 432 | char *msg = g_string_free( iu->pastebuf, FALSE ); |
---|
| 433 | GSList *l; |
---|
| 434 | |
---|
| 435 | for( l = irc_plugins; l; l = l->next ) |
---|
| 436 | { |
---|
| 437 | irc_plugin_t *p = l->data; |
---|
| 438 | if( p->filter_msg_out ) |
---|
| 439 | { |
---|
| 440 | char *s = p->filter_msg_out( iu, msg, 0 ); |
---|
| 441 | if( s ) |
---|
| 442 | { |
---|
| 443 | if( s != msg ) |
---|
| 444 | g_free( msg ); |
---|
| 445 | msg = s; |
---|
| 446 | } |
---|
| 447 | else |
---|
| 448 | { |
---|
| 449 | /* Modules can swallow messages. */ |
---|
| 450 | iu->pastebuf = NULL; |
---|
| 451 | g_free( msg ); |
---|
| 452 | return FALSE; |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | } |
---|
[619dd18] | 456 | |
---|
[934db064] | 457 | bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); |
---|
[619dd18] | 458 | |
---|
[934db064] | 459 | g_free( msg ); |
---|
| 460 | iu->pastebuf = NULL; |
---|
[619dd18] | 461 | iu->pastebuf_timer = 0; |
---|
| 462 | |
---|
| 463 | return FALSE; |
---|
[e4816ea] | 464 | } |
---|
| 465 | |
---|
| 466 | static gboolean bee_irc_user_ctcp( irc_user_t *iu, char *const *ctcp ) |
---|
| 467 | { |
---|
| 468 | if( ctcp[1] && g_strcasecmp( ctcp[0], "DCC" ) == 0 |
---|
| 469 | && g_strcasecmp( ctcp[1], "SEND" ) == 0 ) |
---|
| 470 | { |
---|
| 471 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request ) |
---|
| 472 | { |
---|
| 473 | file_transfer_t *ft = dcc_request( iu->bu->ic, ctcp ); |
---|
| 474 | if ( ft ) |
---|
| 475 | iu->bu->ic->acc->prpl->transfer_request( iu->bu->ic, ft, iu->bu->handle ); |
---|
| 476 | |
---|
| 477 | return TRUE; |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | else if( g_strcasecmp( ctcp[0], "TYPING" ) == 0 ) |
---|
| 481 | { |
---|
| 482 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->send_typing && ctcp[1] ) |
---|
| 483 | { |
---|
| 484 | int st = ctcp[1][0]; |
---|
| 485 | if( st >= '0' && st <= '2' ) |
---|
| 486 | { |
---|
| 487 | st <<= 8; |
---|
| 488 | iu->bu->ic->acc->prpl->send_typing( iu->bu->ic, iu->bu->handle, st ); |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | return TRUE; |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | return FALSE; |
---|
| 496 | } |
---|
| 497 | |
---|
| 498 | static const struct irc_user_funcs irc_user_im_funcs = { |
---|
| 499 | bee_irc_user_privmsg, |
---|
| 500 | bee_irc_user_ctcp, |
---|
| 501 | }; |
---|
| 502 | |
---|
[aea8b68] | 503 | |
---|
[e4816ea] | 504 | /* IM->IRC: Groupchats */ |
---|
[5a75d15] | 505 | const struct irc_channel_funcs irc_channel_im_chat_funcs; |
---|
[a87754b] | 506 | |
---|
| 507 | static gboolean bee_irc_chat_new( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 508 | { |
---|
| 509 | irc_t *irc = bee->ui_data; |
---|
| 510 | irc_channel_t *ic; |
---|
| 511 | char *topic; |
---|
[eb37735] | 512 | GSList *l; |
---|
[aea8b68] | 513 | int i; |
---|
| 514 | |
---|
[eb37735] | 515 | /* Try to find a channel that expects to receive a groupchat. |
---|
[52a2521] | 516 | This flag is set earlier in our current call trace. */ |
---|
[eb37735] | 517 | for( l = irc->channels; l; l = l->next ) |
---|
| 518 | { |
---|
| 519 | ic = l->data; |
---|
| 520 | if( ic->flags & IRC_CHANNEL_CHAT_PICKME ) |
---|
| 521 | break; |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | /* If we found none, just generate some stupid name. */ |
---|
| 525 | if( l == NULL ) for( i = 0; i <= 999; i ++ ) |
---|
[aea8b68] | 526 | { |
---|
| 527 | char name[16]; |
---|
[5a75d15] | 528 | sprintf( name, "#chat_%03d", i ); |
---|
[aea8b68] | 529 | if( ( ic = irc_channel_new( irc, name ) ) ) |
---|
| 530 | break; |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | if( ic == NULL ) |
---|
| 534 | return FALSE; |
---|
| 535 | |
---|
| 536 | c->ui_data = ic; |
---|
| 537 | ic->data = c; |
---|
| 538 | |
---|
| 539 | topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
| 540 | irc_channel_set_topic( ic, topic, irc->root ); |
---|
| 541 | g_free( topic ); |
---|
| 542 | |
---|
| 543 | return TRUE; |
---|
| 544 | } |
---|
| 545 | |
---|
[a87754b] | 546 | static gboolean bee_irc_chat_free( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 547 | { |
---|
| 548 | irc_channel_t *ic = c->ui_data; |
---|
| 549 | |
---|
[b1af3e8] | 550 | if( ic == NULL ) |
---|
| 551 | return FALSE; |
---|
| 552 | |
---|
[aea8b68] | 553 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 554 | irc_channel_printf( ic, "Cleaning up channel, bye!" ); |
---|
| 555 | |
---|
[5a75d15] | 556 | ic->data = NULL; |
---|
[006a84f] | 557 | irc_channel_del_user( ic, ic->irc->user, IRC_CDU_KICK, "Chatroom closed by server" ); |
---|
[aea8b68] | 558 | |
---|
| 559 | return TRUE; |
---|
| 560 | } |
---|
| 561 | |
---|
[a87754b] | 562 | static gboolean bee_irc_chat_log( bee_t *bee, struct groupchat *c, const char *text ) |
---|
[aea8b68] | 563 | { |
---|
[27e2c66] | 564 | irc_channel_t *ic = c->ui_data; |
---|
| 565 | |
---|
[b1af3e8] | 566 | if( ic == NULL ) |
---|
| 567 | return FALSE; |
---|
| 568 | |
---|
[27e2c66] | 569 | irc_channel_printf( ic, "%s", text ); |
---|
[b17ce85] | 570 | |
---|
| 571 | return TRUE; |
---|
[aea8b68] | 572 | } |
---|
| 573 | |
---|
[a87754b] | 574 | static gboolean bee_irc_chat_msg( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at ) |
---|
[aea8b68] | 575 | { |
---|
[27e2c66] | 576 | irc_t *irc = bee->ui_data; |
---|
| 577 | irc_user_t *iu = bu->ui_data; |
---|
| 578 | irc_channel_t *ic = c->ui_data; |
---|
| 579 | char *ts = NULL; |
---|
| 580 | |
---|
[b1af3e8] | 581 | if( ic == NULL ) |
---|
| 582 | return FALSE; |
---|
| 583 | |
---|
[27e2c66] | 584 | if( sent_at > 0 && set_getbool( &bee->set, "display_timestamps" ) ) |
---|
| 585 | ts = irc_format_timestamp( irc, sent_at ); |
---|
| 586 | |
---|
| 587 | irc_send_msg( iu, "PRIVMSG", ic->name, msg, ts ); |
---|
| 588 | g_free( ts ); |
---|
| 589 | |
---|
| 590 | return TRUE; |
---|
[aea8b68] | 591 | } |
---|
| 592 | |
---|
[a87754b] | 593 | static gboolean bee_irc_chat_add_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 594 | { |
---|
| 595 | irc_t *irc = bee->ui_data; |
---|
[b1af3e8] | 596 | irc_channel_t *ic = c->ui_data; |
---|
[aea8b68] | 597 | |
---|
[b1af3e8] | 598 | if( ic == NULL ) |
---|
| 599 | return FALSE; |
---|
| 600 | |
---|
| 601 | irc_channel_add_user( ic, bu == bee->user ? irc->user : bu->ui_data ); |
---|
[b17ce85] | 602 | |
---|
| 603 | return TRUE; |
---|
[aea8b68] | 604 | } |
---|
| 605 | |
---|
[a87754b] | 606 | static gboolean bee_irc_chat_remove_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 607 | { |
---|
[b17ce85] | 608 | irc_t *irc = bee->ui_data; |
---|
[b1af3e8] | 609 | irc_channel_t *ic = c->ui_data; |
---|
| 610 | |
---|
[d6657ce] | 611 | if( ic == NULL || bu == NULL ) |
---|
[b1af3e8] | 612 | return FALSE; |
---|
[b17ce85] | 613 | |
---|
[1c40aa7] | 614 | /* TODO: Possible bug here: If a module removes $user here instead of just |
---|
| 615 | using imcb_chat_free() and the channel was IRC_CHANNEL_TEMP, we get into |
---|
| 616 | a broken state around here. */ |
---|
[b1af3e8] | 617 | irc_channel_del_user( ic, bu == bee->user ? irc->user : bu->ui_data, IRC_CDU_PART, NULL ); |
---|
[b17ce85] | 618 | |
---|
| 619 | return TRUE; |
---|
[aea8b68] | 620 | } |
---|
| 621 | |
---|
[9e27f18] | 622 | static gboolean bee_irc_chat_topic( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu ) |
---|
| 623 | { |
---|
[b1af3e8] | 624 | irc_channel_t *ic = c->ui_data; |
---|
[9e27f18] | 625 | irc_t *irc = bee->ui_data; |
---|
| 626 | irc_user_t *iu; |
---|
| 627 | |
---|
[b1af3e8] | 628 | if( ic == NULL ) |
---|
| 629 | return FALSE; |
---|
| 630 | |
---|
[9e27f18] | 631 | if( bu == NULL ) |
---|
| 632 | iu = irc->root; |
---|
| 633 | else if( bu == bee->user ) |
---|
| 634 | iu = irc->user; |
---|
| 635 | else |
---|
| 636 | iu = bu->ui_data; |
---|
| 637 | |
---|
[b1af3e8] | 638 | irc_channel_set_topic( ic, new, iu ); |
---|
[9e27f18] | 639 | |
---|
| 640 | return TRUE; |
---|
| 641 | } |
---|
| 642 | |
---|
[d343eaa] | 643 | static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const char *name ) |
---|
| 644 | { |
---|
| 645 | irc_t *irc = bee->ui_data; |
---|
[52a2521] | 646 | irc_channel_t *ic = c->ui_data, *oic; |
---|
[d343eaa] | 647 | char stripped[MAX_NICK_LENGTH+1], *full_name; |
---|
| 648 | |
---|
[b1af3e8] | 649 | if( ic == NULL ) |
---|
| 650 | return FALSE; |
---|
| 651 | |
---|
[d343eaa] | 652 | /* Don't rename a channel if the user's in it already. */ |
---|
| 653 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 654 | return FALSE; |
---|
| 655 | |
---|
| 656 | strncpy( stripped, name, MAX_NICK_LENGTH ); |
---|
| 657 | stripped[MAX_NICK_LENGTH] = '\0'; |
---|
[134a02c] | 658 | irc_channel_name_strip( stripped ); |
---|
[d343eaa] | 659 | if( set_getbool( &bee->set, "lcnicks" ) ) |
---|
| 660 | nick_lc( stripped ); |
---|
| 661 | |
---|
[52a2521] | 662 | if( stripped[0] == '\0' ) |
---|
| 663 | return FALSE; |
---|
[d343eaa] | 664 | |
---|
[52a2521] | 665 | full_name = g_strdup_printf( "#%s", stripped ); |
---|
| 666 | if( ( oic = irc_channel_by_name( irc, full_name ) ) ) |
---|
[d343eaa] | 667 | { |
---|
[52a2521] | 668 | char *type, *chat_type; |
---|
| 669 | |
---|
| 670 | type = set_getstr( &oic->set, "type" ); |
---|
| 671 | chat_type = set_getstr( &oic->set, "chat_type" ); |
---|
| 672 | |
---|
| 673 | if( type && chat_type && oic->data == FALSE && |
---|
| 674 | strcmp( type, "chat" ) == 0 && |
---|
| 675 | strcmp( chat_type, "groupchat" ) == 0 ) |
---|
| 676 | { |
---|
| 677 | /* There's a channel with this name already, but it looks |
---|
| 678 | like it's not in use yet. Most likely the IRC client |
---|
| 679 | rejoined the channel after a reconnect. Remove it so |
---|
| 680 | we can reuse its name. */ |
---|
| 681 | irc_channel_free( oic ); |
---|
| 682 | } |
---|
| 683 | else |
---|
| 684 | { |
---|
| 685 | g_free( full_name ); |
---|
| 686 | return FALSE; |
---|
| 687 | } |
---|
[d343eaa] | 688 | } |
---|
| 689 | |
---|
[52a2521] | 690 | g_free( ic->name ); |
---|
| 691 | ic->name = full_name; |
---|
| 692 | |
---|
[d343eaa] | 693 | return TRUE; |
---|
| 694 | } |
---|
| 695 | |
---|
[1aa74f55] | 696 | static gboolean bee_irc_chat_invite( bee_t *bee, bee_user_t *bu, const char *name, const char *msg ) |
---|
| 697 | { |
---|
| 698 | char *channel, *s; |
---|
| 699 | irc_t *irc = bee->ui_data; |
---|
| 700 | irc_user_t *iu = bu->ui_data; |
---|
| 701 | irc_channel_t *chan; |
---|
| 702 | |
---|
| 703 | if( strchr( CTYPES, name[0] ) ) |
---|
| 704 | channel = g_strdup( name ); |
---|
| 705 | else |
---|
| 706 | channel = g_strdup_printf( "#%s", name ); |
---|
| 707 | |
---|
| 708 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 709 | *s = '\0'; |
---|
| 710 | |
---|
| 711 | if( strlen( channel ) > MAX_NICK_LENGTH ) |
---|
| 712 | { |
---|
| 713 | /* If the channel name is very long (like those insane GTalk |
---|
| 714 | UUID names), try if we can use the inviter's nick. */ |
---|
| 715 | s = g_strdup_printf( "#%s", iu->nick ); |
---|
| 716 | if( irc_channel_by_name( irc, s ) == NULL ) |
---|
| 717 | { |
---|
| 718 | g_free( channel ); |
---|
| 719 | channel = s; |
---|
| 720 | } |
---|
| 721 | } |
---|
| 722 | |
---|
| 723 | if( ( chan = irc_channel_new( irc, channel ) ) && |
---|
| 724 | set_setstr( &chan->set, "type", "chat" ) && |
---|
| 725 | set_setstr( &chan->set, "chat_type", "room" ) && |
---|
| 726 | set_setstr( &chan->set, "account", bu->ic->acc->tag ) && |
---|
| 727 | set_setstr( &chan->set, "room", (char*) name ) ) |
---|
| 728 | { |
---|
| 729 | /* I'm assuming that if the user didn't "chat add" the room |
---|
| 730 | himself but got invited, it's temporary, so make this a |
---|
| 731 | temporary mapping that is removed as soon as we /PART. */ |
---|
| 732 | chan->flags |= IRC_CHANNEL_TEMP; |
---|
| 733 | } |
---|
| 734 | else |
---|
| 735 | { |
---|
| 736 | irc_channel_free( chan ); |
---|
| 737 | chan = NULL; |
---|
| 738 | } |
---|
| 739 | g_free( channel ); |
---|
| 740 | |
---|
| 741 | irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "<< \002BitlBee\002 - Invitation to chatroom %s >>", name ); |
---|
| 742 | if( msg ) |
---|
| 743 | irc_send_msg( iu, "PRIVMSG", irc->user->nick, msg, NULL ); |
---|
| 744 | if( chan ) |
---|
| 745 | { |
---|
| 746 | irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "To join the room, just /join %s", chan->name ); |
---|
| 747 | irc_send_invite( iu, chan ); |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | return TRUE; |
---|
| 751 | } |
---|
| 752 | |
---|
[a87754b] | 753 | /* IRC->IM */ |
---|
[619dd18] | 754 | static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); |
---|
| 755 | |
---|
[a87754b] | 756 | static gboolean bee_irc_channel_chat_privmsg( irc_channel_t *ic, const char *msg ) |
---|
| 757 | { |
---|
| 758 | struct groupchat *c = ic->data; |
---|
[69b896b] | 759 | char *trans = NULL, *s; |
---|
[a87754b] | 760 | |
---|
[5a75d15] | 761 | if( c == NULL ) |
---|
| 762 | return FALSE; |
---|
[69b896b] | 763 | |
---|
| 764 | if( set_getbool( &ic->set, "translate_to_nicks" ) ) |
---|
| 765 | { |
---|
| 766 | char nick[MAX_NICK_LENGTH+1]; |
---|
| 767 | irc_user_t *iu; |
---|
| 768 | |
---|
| 769 | strncpy( nick, msg, MAX_NICK_LENGTH ); |
---|
| 770 | nick[MAX_NICK_LENGTH] = '\0'; |
---|
| 771 | if( ( s = strchr( nick, ':' ) ) || ( s = strchr( nick, ',' ) ) ) |
---|
| 772 | { |
---|
| 773 | *s = '\0'; |
---|
[4c737ebd] | 774 | if( ( iu = irc_user_by_name( ic->irc, nick ) ) && iu->bu && |
---|
[69b896b] | 775 | iu->bu->nick && irc_channel_has_user( ic, iu ) ) |
---|
| 776 | { |
---|
| 777 | trans = g_strconcat( iu->bu->nick, msg + ( s - nick ), NULL ); |
---|
| 778 | msg = trans; |
---|
| 779 | } |
---|
| 780 | } |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | if( set_getbool( &ic->irc->b->set, "paste_buffer" ) ) |
---|
[619dd18] | 784 | { |
---|
| 785 | int delay; |
---|
| 786 | |
---|
| 787 | if( ic->pastebuf == NULL ) |
---|
| 788 | ic->pastebuf = g_string_new( msg ); |
---|
| 789 | else |
---|
| 790 | { |
---|
| 791 | b_event_remove( ic->pastebuf_timer ); |
---|
| 792 | g_string_append_printf( ic->pastebuf, "\n%s", msg ); |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | if( ( delay = set_getint( &ic->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) |
---|
| 796 | delay *= 1000; |
---|
| 797 | |
---|
| 798 | ic->pastebuf_timer = b_timeout_add( delay, bee_irc_channel_chat_privmsg_cb, ic ); |
---|
| 799 | |
---|
[69b896b] | 800 | g_free( trans ); |
---|
[619dd18] | 801 | return TRUE; |
---|
| 802 | } |
---|
| 803 | else |
---|
| 804 | bee_chat_msg( ic->irc->b, c, msg, 0 ); |
---|
[a87754b] | 805 | |
---|
[69b896b] | 806 | g_free( trans ); |
---|
[a87754b] | 807 | return TRUE; |
---|
[5a75d15] | 808 | } |
---|
| 809 | |
---|
[619dd18] | 810 | static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) |
---|
| 811 | { |
---|
| 812 | irc_channel_t *ic = data; |
---|
| 813 | |
---|
[cc20520] | 814 | if( ic->data ) |
---|
| 815 | bee_chat_msg( ic->irc->b, ic->data, ic->pastebuf->str, 0 ); |
---|
[619dd18] | 816 | |
---|
| 817 | g_string_free( ic->pastebuf, TRUE ); |
---|
| 818 | ic->pastebuf = 0; |
---|
| 819 | ic->pastebuf_timer = 0; |
---|
| 820 | |
---|
| 821 | return FALSE; |
---|
| 822 | } |
---|
| 823 | |
---|
[5a75d15] | 824 | static gboolean bee_irc_channel_chat_join( irc_channel_t *ic ) |
---|
| 825 | { |
---|
| 826 | char *acc_s, *room; |
---|
| 827 | account_t *acc; |
---|
[a87754b] | 828 | |
---|
[5a75d15] | 829 | if( strcmp( set_getstr( &ic->set, "chat_type" ), "room" ) != 0 ) |
---|
| 830 | return TRUE; |
---|
| 831 | |
---|
| 832 | if( ( acc_s = set_getstr( &ic->set, "account" ) ) && |
---|
| 833 | ( room = set_getstr( &ic->set, "room" ) ) && |
---|
| 834 | ( acc = account_get( ic->irc->b, acc_s ) ) && |
---|
| 835 | acc->ic && acc->prpl->chat_join ) |
---|
| 836 | { |
---|
| 837 | char *nick; |
---|
| 838 | |
---|
| 839 | if( !( nick = set_getstr( &ic->set, "nick" ) ) ) |
---|
| 840 | nick = ic->irc->user->nick; |
---|
| 841 | |
---|
| 842 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
[03f3828] | 843 | acc->prpl->chat_join( acc->ic, room, nick, NULL, &ic->set ); |
---|
[5a75d15] | 844 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
| 845 | |
---|
| 846 | return FALSE; |
---|
| 847 | } |
---|
| 848 | else |
---|
| 849 | { |
---|
| 850 | irc_send_num( ic->irc, 403, "%s :Can't join channel, account offline?", ic->name ); |
---|
| 851 | return FALSE; |
---|
| 852 | } |
---|
[a87754b] | 853 | } |
---|
| 854 | |
---|
[bfb99ee] | 855 | static gboolean bee_irc_channel_chat_part( irc_channel_t *ic, const char *msg ) |
---|
| 856 | { |
---|
| 857 | struct groupchat *c = ic->data; |
---|
| 858 | |
---|
[5a75d15] | 859 | if( c && c->ic->acc->prpl->chat_leave ) |
---|
[bfb99ee] | 860 | c->ic->acc->prpl->chat_leave( c ); |
---|
| 861 | |
---|
[cc20520] | 862 | ic->data = NULL; |
---|
| 863 | |
---|
[bfb99ee] | 864 | return TRUE; |
---|
| 865 | } |
---|
| 866 | |
---|
[9e27f18] | 867 | static gboolean bee_irc_channel_chat_topic( irc_channel_t *ic, const char *new ) |
---|
| 868 | { |
---|
[4469e7e] | 869 | struct groupchat *c = ic->data; |
---|
[5a75d15] | 870 | |
---|
| 871 | if( c == NULL ) |
---|
| 872 | return FALSE; |
---|
[4469e7e] | 873 | |
---|
| 874 | if( c->ic->acc->prpl->chat_topic == NULL ) |
---|
| 875 | irc_send_num( ic->irc, 482, "%s :IM network does not support channel topics", ic->name ); |
---|
| 876 | else |
---|
| 877 | { |
---|
[5a75d15] | 878 | /* TODO: Need more const goodness here, sigh */ |
---|
| 879 | char *topic = g_strdup( new ); |
---|
[4469e7e] | 880 | c->ic->acc->prpl->chat_topic( c, topic ); |
---|
[5a75d15] | 881 | g_free( topic ); |
---|
[4469e7e] | 882 | } |
---|
| 883 | |
---|
[41e0c00] | 884 | /* Whatever happened, the IM module should ack the topic change. */ |
---|
[4469e7e] | 885 | return FALSE; |
---|
[9e27f18] | 886 | } |
---|
| 887 | |
---|
[66b9e36a] | 888 | static gboolean bee_irc_channel_chat_invite( irc_channel_t *ic, irc_user_t *iu ) |
---|
| 889 | { |
---|
| 890 | struct groupchat *c = ic->data; |
---|
[5a75d15] | 891 | bee_user_t *bu = iu->bu; |
---|
| 892 | |
---|
| 893 | if( bu == NULL ) |
---|
| 894 | return FALSE; |
---|
[66b9e36a] | 895 | |
---|
[5a75d15] | 896 | if( c ) |
---|
| 897 | { |
---|
| 898 | if( iu->bu->ic != c->ic ) |
---|
| 899 | irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name ); |
---|
| 900 | else if( c->ic->acc->prpl->chat_invite ) |
---|
| 901 | c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL ); |
---|
| 902 | else |
---|
| 903 | irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); |
---|
| 904 | } |
---|
| 905 | else if( bu->ic->acc->prpl->chat_with && |
---|
| 906 | strcmp( set_getstr( &ic->set, "chat_type" ), "groupchat" ) == 0 ) |
---|
| 907 | { |
---|
| 908 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
| 909 | iu->bu->ic->acc->prpl->chat_with( bu->ic, bu->handle ); |
---|
| 910 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
| 911 | } |
---|
[66b9e36a] | 912 | else |
---|
[5a75d15] | 913 | { |
---|
[66b9e36a] | 914 | irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); |
---|
[5a75d15] | 915 | } |
---|
[66b9e36a] | 916 | |
---|
| 917 | return TRUE; |
---|
| 918 | } |
---|
| 919 | |
---|
[5a75d15] | 920 | static char *set_eval_room_account( set_t *set, char *value ); |
---|
[1c40aa7] | 921 | static char *set_eval_chat_type( set_t *set, char *value ); |
---|
[5a75d15] | 922 | |
---|
| 923 | static gboolean bee_irc_channel_init( irc_channel_t *ic ) |
---|
| 924 | { |
---|
| 925 | set_add( &ic->set, "account", NULL, set_eval_room_account, ic ); |
---|
[1c40aa7] | 926 | set_add( &ic->set, "chat_type", "groupchat", set_eval_chat_type, ic ); |
---|
[5a75d15] | 927 | set_add( &ic->set, "nick", NULL, NULL, ic ); |
---|
| 928 | set_add( &ic->set, "room", NULL, NULL, ic ); |
---|
[69b896b] | 929 | set_add( &ic->set, "translate_to_nicks", "true", set_eval_bool, ic ); |
---|
[5a75d15] | 930 | |
---|
[1c40aa7] | 931 | /* chat_type == groupchat */ |
---|
| 932 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
| 933 | |
---|
[5a75d15] | 934 | return TRUE; |
---|
| 935 | } |
---|
| 936 | |
---|
| 937 | static char *set_eval_room_account( set_t *set, char *value ) |
---|
| 938 | { |
---|
| 939 | struct irc_channel *ic = set->data; |
---|
[03f3828] | 940 | account_t *acc, *oa; |
---|
[5a75d15] | 941 | |
---|
| 942 | if( !( acc = account_get( ic->irc->b, value ) ) ) |
---|
| 943 | return SET_INVALID; |
---|
| 944 | else if( !acc->prpl->chat_join ) |
---|
| 945 | { |
---|
| 946 | irc_usermsg( ic->irc, "Named chatrooms not supported on that account." ); |
---|
| 947 | return SET_INVALID; |
---|
| 948 | } |
---|
| 949 | |
---|
[03f3828] | 950 | if( set->value && ( oa = account_get( ic->irc->b, set->value ) ) && |
---|
| 951 | oa->prpl->chat_free_settings ) |
---|
| 952 | oa->prpl->chat_free_settings( oa, &ic->set ); |
---|
| 953 | |
---|
| 954 | if( acc->prpl->chat_add_settings ) |
---|
| 955 | acc->prpl->chat_add_settings( acc, &ic->set ); |
---|
| 956 | |
---|
[e135cd09] | 957 | return g_strdup( acc->tag ); |
---|
[5a75d15] | 958 | } |
---|
| 959 | |
---|
[1c40aa7] | 960 | static char *set_eval_chat_type( set_t *set, char *value ) |
---|
| 961 | { |
---|
| 962 | struct irc_channel *ic = set->data; |
---|
| 963 | |
---|
| 964 | if( strcmp( value, "groupchat" ) == 0 ) |
---|
| 965 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
| 966 | else if( strcmp( value, "room" ) == 0 ) |
---|
| 967 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
| 968 | else |
---|
| 969 | return NULL; |
---|
| 970 | |
---|
| 971 | return value; |
---|
| 972 | } |
---|
| 973 | |
---|
[5a75d15] | 974 | static gboolean bee_irc_channel_free( irc_channel_t *ic ) |
---|
| 975 | { |
---|
[b1af3e8] | 976 | struct groupchat *c = ic->data; |
---|
| 977 | |
---|
[5a75d15] | 978 | set_del( &ic->set, "account" ); |
---|
| 979 | set_del( &ic->set, "chat_type" ); |
---|
| 980 | set_del( &ic->set, "nick" ); |
---|
| 981 | set_del( &ic->set, "room" ); |
---|
[69b896b] | 982 | set_del( &ic->set, "translate_to_nicks" ); |
---|
[5a75d15] | 983 | |
---|
[1c40aa7] | 984 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
| 985 | |
---|
[b1af3e8] | 986 | /* That one still points at this channel. Don't. */ |
---|
| 987 | if( c ) |
---|
| 988 | c->ui_data = NULL; |
---|
| 989 | |
---|
[5a75d15] | 990 | return TRUE; |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | const struct irc_channel_funcs irc_channel_im_chat_funcs = { |
---|
[a87754b] | 994 | bee_irc_channel_chat_privmsg, |
---|
[5a75d15] | 995 | bee_irc_channel_chat_join, |
---|
[bfb99ee] | 996 | bee_irc_channel_chat_part, |
---|
[9e27f18] | 997 | bee_irc_channel_chat_topic, |
---|
[66b9e36a] | 998 | bee_irc_channel_chat_invite, |
---|
[5a75d15] | 999 | |
---|
| 1000 | bee_irc_channel_init, |
---|
| 1001 | bee_irc_channel_free, |
---|
[a87754b] | 1002 | }; |
---|
| 1003 | |
---|
[aea8b68] | 1004 | |
---|
[e4816ea] | 1005 | /* IM->IRC: File transfers */ |
---|
[17a6ee9] | 1006 | static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size ) |
---|
| 1007 | { |
---|
| 1008 | return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size ); |
---|
| 1009 | } |
---|
| 1010 | |
---|
[a87754b] | 1011 | static gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 1012 | { |
---|
| 1013 | return dccs_recv_start( ft ); |
---|
| 1014 | } |
---|
| 1015 | |
---|
[a87754b] | 1016 | static void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 1017 | { |
---|
| 1018 | return dcc_close( ft ); |
---|
| 1019 | } |
---|
| 1020 | |
---|
[a87754b] | 1021 | static void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file ) |
---|
[17a6ee9] | 1022 | { |
---|
| 1023 | dcc_file_transfer_t *df = file->priv; |
---|
| 1024 | |
---|
| 1025 | if( file->bytes_transferred >= file->file_size ) |
---|
| 1026 | dcc_finish( file ); |
---|
| 1027 | else |
---|
| 1028 | df->proto_finished = TRUE; |
---|
| 1029 | } |
---|
| 1030 | |
---|
[d860a8d] | 1031 | const struct bee_ui_funcs irc_ui_funcs = { |
---|
[5c7b45c] | 1032 | bee_irc_imc_connected, |
---|
| 1033 | bee_irc_imc_disconnected, |
---|
| 1034 | |
---|
[81e04e1] | 1035 | bee_irc_user_new, |
---|
[d860a8d] | 1036 | bee_irc_user_free, |
---|
[1d39159] | 1037 | bee_irc_user_fullname, |
---|
[6ef9065] | 1038 | bee_irc_user_nick_hint, |
---|
[7e83e8e4] | 1039 | bee_irc_user_group, |
---|
[d860a8d] | 1040 | bee_irc_user_status, |
---|
[f012a9f] | 1041 | bee_irc_user_msg, |
---|
[573dab0] | 1042 | bee_irc_user_typing, |
---|
[17a6ee9] | 1043 | |
---|
[aea8b68] | 1044 | bee_irc_chat_new, |
---|
| 1045 | bee_irc_chat_free, |
---|
[27e2c66] | 1046 | bee_irc_chat_log, |
---|
| 1047 | bee_irc_chat_msg, |
---|
[aea8b68] | 1048 | bee_irc_chat_add_user, |
---|
[b17ce85] | 1049 | bee_irc_chat_remove_user, |
---|
[9e27f18] | 1050 | bee_irc_chat_topic, |
---|
[d343eaa] | 1051 | bee_irc_chat_name_hint, |
---|
[1aa74f55] | 1052 | bee_irc_chat_invite, |
---|
[aea8b68] | 1053 | |
---|
[17a6ee9] | 1054 | bee_irc_ft_in_start, |
---|
| 1055 | bee_irc_ft_out_start, |
---|
| 1056 | bee_irc_ft_close, |
---|
| 1057 | bee_irc_ft_finished, |
---|
[81e04e1] | 1058 | }; |
---|