[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 | |
---|
[d88c92a] | 282 | static gboolean bee_irc_user_action_response( bee_t *bee, bee_user_t *bu, const char *action, char * const args[], void *data ) |
---|
| 283 | { |
---|
| 284 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
| 285 | GString *msg = g_string_new( "\001" ); |
---|
| 286 | |
---|
| 287 | g_string_append( msg, action ); |
---|
| 288 | while( *args ) |
---|
| 289 | { |
---|
| 290 | if( strchr( *args, ' ' ) ) |
---|
| 291 | g_string_append_printf( msg, " \"%s\"", *args ); |
---|
| 292 | else |
---|
| 293 | g_string_append_printf( msg, " %s", *args ); |
---|
| 294 | args ++; |
---|
| 295 | } |
---|
| 296 | g_string_append_c( msg, '\001' ); |
---|
| 297 | |
---|
| 298 | irc_send_msg( (irc_user_t *) bu->ui_data, "NOTICE", irc->user->nick, msg->str, NULL ); |
---|
| 299 | |
---|
| 300 | return TRUE; |
---|
| 301 | } |
---|
| 302 | |
---|
[badd148] | 303 | static gboolean bee_irc_user_nick_update( irc_user_t *iu ); |
---|
[6ef9065] | 304 | |
---|
[1d39159] | 305 | static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu ) |
---|
| 306 | { |
---|
| 307 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 308 | char *s; |
---|
| 309 | |
---|
| 310 | if( iu->fullname != iu->nick ) |
---|
| 311 | g_free( iu->fullname ); |
---|
| 312 | iu->fullname = g_strdup( bu->fullname ); |
---|
| 313 | |
---|
| 314 | /* Strip newlines (unlikely, but IRC-unfriendly so they must go) |
---|
| 315 | TODO(wilmer): Do the same with away msgs again! */ |
---|
| 316 | for( s = iu->fullname; *s; s ++ ) |
---|
| 317 | if( isspace( *s ) ) *s = ' '; |
---|
| 318 | |
---|
| 319 | if( ( bu->ic->flags & OPT_LOGGED_IN ) && set_getbool( &bee->set, "display_namechanges" ) ) |
---|
| 320 | { |
---|
[fda55fa] | 321 | /* People don't like this /NOTICE. Meh, let's go back to the old one. |
---|
[1d39159] | 322 | char *msg = g_strdup_printf( "<< \002BitlBee\002 - Changed name to `%s' >>", iu->fullname ); |
---|
| 323 | irc_send_msg( iu, "NOTICE", irc->user->nick, msg, NULL ); |
---|
[fda55fa] | 324 | */ |
---|
| 325 | imcb_log( bu->ic, "User `%s' changed name to `%s'", iu->nick, iu->fullname ); |
---|
[1d39159] | 326 | } |
---|
| 327 | |
---|
[badd148] | 328 | bee_irc_user_nick_update( iu ); |
---|
[1d39159] | 329 | |
---|
| 330 | return TRUE; |
---|
| 331 | } |
---|
| 332 | |
---|
[6ef9065] | 333 | static gboolean bee_irc_user_nick_hint( bee_t *bee, bee_user_t *bu, const char *hint ) |
---|
| 334 | { |
---|
[badd148] | 335 | bee_irc_user_nick_update( (irc_user_t*) bu->ui_data ); |
---|
| 336 | |
---|
| 337 | return TRUE; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | static gboolean bee_irc_user_group( bee_t *bee, bee_user_t *bu ) |
---|
| 341 | { |
---|
| 342 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 343 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
[51a3d12] | 344 | bee_user_flags_t online; |
---|
| 345 | |
---|
| 346 | /* Take the user offline temporarily so we can change the nick (if necessary). */ |
---|
| 347 | if( ( online = bu->flags & BEE_USER_ONLINE ) ) |
---|
| 348 | bu->flags &= ~BEE_USER_ONLINE; |
---|
[badd148] | 349 | |
---|
| 350 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 351 | bee_irc_user_nick_update( iu ); |
---|
| 352 | |
---|
[51a3d12] | 353 | if( online ) |
---|
| 354 | { |
---|
| 355 | bu->flags |= online; |
---|
| 356 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 357 | } |
---|
| 358 | |
---|
[badd148] | 359 | return TRUE; |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | static gboolean bee_irc_user_nick_update( irc_user_t *iu ) |
---|
| 363 | { |
---|
| 364 | bee_user_t *bu = iu->bu; |
---|
| 365 | char *newnick; |
---|
[6ef9065] | 366 | |
---|
| 367 | if( bu->flags & BEE_USER_ONLINE ) |
---|
| 368 | /* Ignore if the user is visible already. */ |
---|
| 369 | return TRUE; |
---|
| 370 | |
---|
[b1f818b] | 371 | if( nick_saved( bu ) ) |
---|
[6ef9065] | 372 | /* The user already assigned a nickname to this person. */ |
---|
| 373 | return TRUE; |
---|
| 374 | |
---|
[badd148] | 375 | newnick = nick_get( bu ); |
---|
[6ef9065] | 376 | |
---|
| 377 | if( strcmp( iu->nick, newnick ) != 0 ) |
---|
| 378 | { |
---|
[b1f818b] | 379 | nick_dedupe( bu, newnick ); |
---|
[6ef9065] | 380 | irc_user_set_nick( iu, newnick ); |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | return TRUE; |
---|
| 384 | } |
---|
| 385 | |
---|
[a429907] | 386 | void bee_irc_user_nick_reset( irc_user_t *iu ) |
---|
| 387 | { |
---|
| 388 | bee_user_t *bu = iu->bu; |
---|
| 389 | bee_user_flags_t online; |
---|
| 390 | |
---|
| 391 | if( bu == FALSE ) |
---|
| 392 | return; |
---|
| 393 | |
---|
| 394 | /* In this case, pretend the user is offline. */ |
---|
| 395 | if( ( online = bu->flags & BEE_USER_ONLINE ) ) |
---|
| 396 | bu->flags &= ~BEE_USER_ONLINE; |
---|
| 397 | |
---|
| 398 | nick_del( bu ); |
---|
| 399 | bee_irc_user_nick_update( iu ); |
---|
| 400 | |
---|
| 401 | bu->flags |= online; |
---|
| 402 | } |
---|
| 403 | |
---|
[e4816ea] | 404 | /* IRC->IM calls */ |
---|
| 405 | |
---|
[619dd18] | 406 | static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); |
---|
| 407 | |
---|
[e4816ea] | 408 | static gboolean bee_irc_user_privmsg( irc_user_t *iu, const char *msg ) |
---|
| 409 | { |
---|
[1c8e5f7] | 410 | const char *away; |
---|
| 411 | |
---|
[619dd18] | 412 | if( iu->bu == NULL ) |
---|
[e4816ea] | 413 | return FALSE; |
---|
[1c8e5f7] | 414 | |
---|
| 415 | if( ( away = irc_user_get_away( iu ) ) && |
---|
| 416 | time( NULL ) >= iu->away_reply_timeout ) |
---|
| 417 | { |
---|
| 418 | irc_send_num( iu->irc, 301, "%s :%s", iu->nick, away ); |
---|
| 419 | iu->away_reply_timeout = time( NULL ) + |
---|
| 420 | set_getint( &iu->irc->b->set, "away_reply_timeout" ); |
---|
| 421 | } |
---|
| 422 | |
---|
[934db064] | 423 | if( iu->pastebuf == NULL ) |
---|
| 424 | iu->pastebuf = g_string_new( msg ); |
---|
| 425 | else |
---|
| 426 | { |
---|
| 427 | b_event_remove( iu->pastebuf_timer ); |
---|
| 428 | g_string_append_printf( iu->pastebuf, "\n%s", msg ); |
---|
| 429 | } |
---|
| 430 | |
---|
[1c8e5f7] | 431 | if( set_getbool( &iu->irc->b->set, "paste_buffer" ) ) |
---|
[619dd18] | 432 | { |
---|
| 433 | int delay; |
---|
| 434 | |
---|
| 435 | if( ( delay = set_getint( &iu->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) |
---|
| 436 | delay *= 1000; |
---|
| 437 | |
---|
| 438 | iu->pastebuf_timer = b_timeout_add( delay, bee_irc_user_privmsg_cb, iu ); |
---|
| 439 | |
---|
| 440 | return TRUE; |
---|
| 441 | } |
---|
| 442 | else |
---|
[934db064] | 443 | { |
---|
| 444 | bee_irc_user_privmsg_cb( iu, 0, 0 ); |
---|
| 445 | |
---|
| 446 | return TRUE; |
---|
| 447 | } |
---|
[619dd18] | 448 | } |
---|
| 449 | |
---|
| 450 | static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) |
---|
| 451 | { |
---|
| 452 | irc_user_t *iu = data; |
---|
[934db064] | 453 | char *msg = g_string_free( iu->pastebuf, FALSE ); |
---|
| 454 | GSList *l; |
---|
| 455 | |
---|
| 456 | for( l = irc_plugins; l; l = l->next ) |
---|
| 457 | { |
---|
| 458 | irc_plugin_t *p = l->data; |
---|
| 459 | if( p->filter_msg_out ) |
---|
| 460 | { |
---|
| 461 | char *s = p->filter_msg_out( iu, msg, 0 ); |
---|
| 462 | if( s ) |
---|
| 463 | { |
---|
| 464 | if( s != msg ) |
---|
| 465 | g_free( msg ); |
---|
| 466 | msg = s; |
---|
| 467 | } |
---|
| 468 | else |
---|
| 469 | { |
---|
| 470 | /* Modules can swallow messages. */ |
---|
| 471 | iu->pastebuf = NULL; |
---|
| 472 | g_free( msg ); |
---|
| 473 | return FALSE; |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | } |
---|
[619dd18] | 477 | |
---|
[934db064] | 478 | bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); |
---|
[619dd18] | 479 | |
---|
[934db064] | 480 | g_free( msg ); |
---|
| 481 | iu->pastebuf = NULL; |
---|
[619dd18] | 482 | iu->pastebuf_timer = 0; |
---|
| 483 | |
---|
| 484 | return FALSE; |
---|
[e4816ea] | 485 | } |
---|
| 486 | |
---|
| 487 | static gboolean bee_irc_user_ctcp( irc_user_t *iu, char *const *ctcp ) |
---|
| 488 | { |
---|
| 489 | if( ctcp[1] && g_strcasecmp( ctcp[0], "DCC" ) == 0 |
---|
| 490 | && g_strcasecmp( ctcp[1], "SEND" ) == 0 ) |
---|
| 491 | { |
---|
| 492 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request ) |
---|
| 493 | { |
---|
| 494 | file_transfer_t *ft = dcc_request( iu->bu->ic, ctcp ); |
---|
| 495 | if ( ft ) |
---|
| 496 | iu->bu->ic->acc->prpl->transfer_request( iu->bu->ic, ft, iu->bu->handle ); |
---|
| 497 | |
---|
| 498 | return TRUE; |
---|
| 499 | } |
---|
| 500 | } |
---|
| 501 | else if( g_strcasecmp( ctcp[0], "TYPING" ) == 0 ) |
---|
| 502 | { |
---|
| 503 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->send_typing && ctcp[1] ) |
---|
| 504 | { |
---|
| 505 | int st = ctcp[1][0]; |
---|
| 506 | if( st >= '0' && st <= '2' ) |
---|
| 507 | { |
---|
| 508 | st <<= 8; |
---|
| 509 | iu->bu->ic->acc->prpl->send_typing( iu->bu->ic, iu->bu->handle, st ); |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | return TRUE; |
---|
| 513 | } |
---|
| 514 | } |
---|
[a97a336] | 515 | else if( g_strcasecmp( ctcp[0], "HELP" ) == 0 && iu->bu ) |
---|
| 516 | { |
---|
| 517 | GString *supp = g_string_new( "Supported CTCPs:" ); |
---|
| 518 | GList *l; |
---|
| 519 | |
---|
| 520 | if( iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request ) |
---|
| 521 | g_string_append( supp, " DCC SEND," ); |
---|
| 522 | if( iu->bu->ic && iu->bu->ic->acc->prpl->send_typing ) |
---|
| 523 | g_string_append( supp, " TYPING," ); |
---|
| 524 | if( iu->bu->ic->acc->prpl->buddy_action_list ) |
---|
| 525 | for( l = iu->bu->ic->acc->prpl->buddy_action_list( iu->bu ); l; l = l->next ) |
---|
| 526 | { |
---|
| 527 | struct buddy_action *ba = l->data; |
---|
| 528 | g_string_append_printf( supp, " %s (%s),", |
---|
| 529 | ba->name, ba->description ); |
---|
| 530 | } |
---|
| 531 | g_string_truncate( supp, supp->len - 1 ); |
---|
| 532 | irc_send_msg_f( iu, "NOTICE", iu->irc->user->nick, "\001HELP %s\001", supp->str ); |
---|
| 533 | g_string_free( supp, TRUE ); |
---|
| 534 | } |
---|
[d88c92a] | 535 | else if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->buddy_action ) |
---|
| 536 | { |
---|
| 537 | iu->bu->ic->acc->prpl->buddy_action( iu->bu, ctcp[0], ctcp + 1, NULL ); |
---|
| 538 | } |
---|
[e4816ea] | 539 | |
---|
| 540 | return FALSE; |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | static const struct irc_user_funcs irc_user_im_funcs = { |
---|
| 544 | bee_irc_user_privmsg, |
---|
| 545 | bee_irc_user_ctcp, |
---|
| 546 | }; |
---|
| 547 | |
---|
[aea8b68] | 548 | |
---|
[e4816ea] | 549 | /* IM->IRC: Groupchats */ |
---|
[5a75d15] | 550 | const struct irc_channel_funcs irc_channel_im_chat_funcs; |
---|
[a87754b] | 551 | |
---|
| 552 | static gboolean bee_irc_chat_new( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 553 | { |
---|
| 554 | irc_t *irc = bee->ui_data; |
---|
| 555 | irc_channel_t *ic; |
---|
| 556 | char *topic; |
---|
[eb37735] | 557 | GSList *l; |
---|
[aea8b68] | 558 | int i; |
---|
| 559 | |
---|
[eb37735] | 560 | /* Try to find a channel that expects to receive a groupchat. |
---|
[52a2521] | 561 | This flag is set earlier in our current call trace. */ |
---|
[eb37735] | 562 | for( l = irc->channels; l; l = l->next ) |
---|
| 563 | { |
---|
| 564 | ic = l->data; |
---|
| 565 | if( ic->flags & IRC_CHANNEL_CHAT_PICKME ) |
---|
| 566 | break; |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | /* If we found none, just generate some stupid name. */ |
---|
| 570 | if( l == NULL ) for( i = 0; i <= 999; i ++ ) |
---|
[aea8b68] | 571 | { |
---|
| 572 | char name[16]; |
---|
[5a75d15] | 573 | sprintf( name, "#chat_%03d", i ); |
---|
[aea8b68] | 574 | if( ( ic = irc_channel_new( irc, name ) ) ) |
---|
| 575 | break; |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | if( ic == NULL ) |
---|
| 579 | return FALSE; |
---|
| 580 | |
---|
| 581 | c->ui_data = ic; |
---|
| 582 | ic->data = c; |
---|
| 583 | |
---|
| 584 | topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
| 585 | irc_channel_set_topic( ic, topic, irc->root ); |
---|
| 586 | g_free( topic ); |
---|
| 587 | |
---|
| 588 | return TRUE; |
---|
| 589 | } |
---|
| 590 | |
---|
[a87754b] | 591 | static gboolean bee_irc_chat_free( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 592 | { |
---|
| 593 | irc_channel_t *ic = c->ui_data; |
---|
| 594 | |
---|
[b1af3e8] | 595 | if( ic == NULL ) |
---|
| 596 | return FALSE; |
---|
| 597 | |
---|
[aea8b68] | 598 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 599 | irc_channel_printf( ic, "Cleaning up channel, bye!" ); |
---|
| 600 | |
---|
[5a75d15] | 601 | ic->data = NULL; |
---|
[006a84f] | 602 | irc_channel_del_user( ic, ic->irc->user, IRC_CDU_KICK, "Chatroom closed by server" ); |
---|
[aea8b68] | 603 | |
---|
| 604 | return TRUE; |
---|
| 605 | } |
---|
| 606 | |
---|
[a87754b] | 607 | static gboolean bee_irc_chat_log( bee_t *bee, struct groupchat *c, const char *text ) |
---|
[aea8b68] | 608 | { |
---|
[27e2c66] | 609 | irc_channel_t *ic = c->ui_data; |
---|
| 610 | |
---|
[b1af3e8] | 611 | if( ic == NULL ) |
---|
| 612 | return FALSE; |
---|
| 613 | |
---|
[27e2c66] | 614 | irc_channel_printf( ic, "%s", text ); |
---|
[b17ce85] | 615 | |
---|
| 616 | return TRUE; |
---|
[aea8b68] | 617 | } |
---|
| 618 | |
---|
[a87754b] | 619 | static gboolean bee_irc_chat_msg( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at ) |
---|
[aea8b68] | 620 | { |
---|
[27e2c66] | 621 | irc_t *irc = bee->ui_data; |
---|
| 622 | irc_user_t *iu = bu->ui_data; |
---|
| 623 | irc_channel_t *ic = c->ui_data; |
---|
| 624 | char *ts = NULL; |
---|
| 625 | |
---|
[b1af3e8] | 626 | if( ic == NULL ) |
---|
| 627 | return FALSE; |
---|
| 628 | |
---|
[27e2c66] | 629 | if( sent_at > 0 && set_getbool( &bee->set, "display_timestamps" ) ) |
---|
| 630 | ts = irc_format_timestamp( irc, sent_at ); |
---|
| 631 | |
---|
| 632 | irc_send_msg( iu, "PRIVMSG", ic->name, msg, ts ); |
---|
| 633 | g_free( ts ); |
---|
| 634 | |
---|
| 635 | return TRUE; |
---|
[aea8b68] | 636 | } |
---|
| 637 | |
---|
[a87754b] | 638 | static gboolean bee_irc_chat_add_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 639 | { |
---|
| 640 | irc_t *irc = bee->ui_data; |
---|
[b1af3e8] | 641 | irc_channel_t *ic = c->ui_data; |
---|
[aea8b68] | 642 | |
---|
[b1af3e8] | 643 | if( ic == NULL ) |
---|
| 644 | return FALSE; |
---|
| 645 | |
---|
| 646 | irc_channel_add_user( ic, bu == bee->user ? irc->user : bu->ui_data ); |
---|
[b17ce85] | 647 | |
---|
| 648 | return TRUE; |
---|
[aea8b68] | 649 | } |
---|
| 650 | |
---|
[a87754b] | 651 | static gboolean bee_irc_chat_remove_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 652 | { |
---|
[b17ce85] | 653 | irc_t *irc = bee->ui_data; |
---|
[b1af3e8] | 654 | irc_channel_t *ic = c->ui_data; |
---|
| 655 | |
---|
[d6657ce] | 656 | if( ic == NULL || bu == NULL ) |
---|
[b1af3e8] | 657 | return FALSE; |
---|
[b17ce85] | 658 | |
---|
[1c40aa7] | 659 | /* TODO: Possible bug here: If a module removes $user here instead of just |
---|
| 660 | using imcb_chat_free() and the channel was IRC_CHANNEL_TEMP, we get into |
---|
| 661 | a broken state around here. */ |
---|
[b1af3e8] | 662 | irc_channel_del_user( ic, bu == bee->user ? irc->user : bu->ui_data, IRC_CDU_PART, NULL ); |
---|
[b17ce85] | 663 | |
---|
| 664 | return TRUE; |
---|
[aea8b68] | 665 | } |
---|
| 666 | |
---|
[9e27f18] | 667 | static gboolean bee_irc_chat_topic( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu ) |
---|
| 668 | { |
---|
[b1af3e8] | 669 | irc_channel_t *ic = c->ui_data; |
---|
[9e27f18] | 670 | irc_t *irc = bee->ui_data; |
---|
| 671 | irc_user_t *iu; |
---|
| 672 | |
---|
[b1af3e8] | 673 | if( ic == NULL ) |
---|
| 674 | return FALSE; |
---|
| 675 | |
---|
[9e27f18] | 676 | if( bu == NULL ) |
---|
| 677 | iu = irc->root; |
---|
| 678 | else if( bu == bee->user ) |
---|
| 679 | iu = irc->user; |
---|
| 680 | else |
---|
| 681 | iu = bu->ui_data; |
---|
| 682 | |
---|
[b1af3e8] | 683 | irc_channel_set_topic( ic, new, iu ); |
---|
[9e27f18] | 684 | |
---|
| 685 | return TRUE; |
---|
| 686 | } |
---|
| 687 | |
---|
[d343eaa] | 688 | static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const char *name ) |
---|
| 689 | { |
---|
| 690 | irc_t *irc = bee->ui_data; |
---|
[52a2521] | 691 | irc_channel_t *ic = c->ui_data, *oic; |
---|
[d343eaa] | 692 | char stripped[MAX_NICK_LENGTH+1], *full_name; |
---|
| 693 | |
---|
[b1af3e8] | 694 | if( ic == NULL ) |
---|
| 695 | return FALSE; |
---|
| 696 | |
---|
[d343eaa] | 697 | /* Don't rename a channel if the user's in it already. */ |
---|
| 698 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 699 | return FALSE; |
---|
| 700 | |
---|
| 701 | strncpy( stripped, name, MAX_NICK_LENGTH ); |
---|
| 702 | stripped[MAX_NICK_LENGTH] = '\0'; |
---|
[134a02c] | 703 | irc_channel_name_strip( stripped ); |
---|
[d343eaa] | 704 | if( set_getbool( &bee->set, "lcnicks" ) ) |
---|
| 705 | nick_lc( stripped ); |
---|
| 706 | |
---|
[52a2521] | 707 | if( stripped[0] == '\0' ) |
---|
| 708 | return FALSE; |
---|
[d343eaa] | 709 | |
---|
[52a2521] | 710 | full_name = g_strdup_printf( "#%s", stripped ); |
---|
| 711 | if( ( oic = irc_channel_by_name( irc, full_name ) ) ) |
---|
[d343eaa] | 712 | { |
---|
[52a2521] | 713 | char *type, *chat_type; |
---|
| 714 | |
---|
| 715 | type = set_getstr( &oic->set, "type" ); |
---|
| 716 | chat_type = set_getstr( &oic->set, "chat_type" ); |
---|
| 717 | |
---|
| 718 | if( type && chat_type && oic->data == FALSE && |
---|
| 719 | strcmp( type, "chat" ) == 0 && |
---|
| 720 | strcmp( chat_type, "groupchat" ) == 0 ) |
---|
| 721 | { |
---|
| 722 | /* There's a channel with this name already, but it looks |
---|
| 723 | like it's not in use yet. Most likely the IRC client |
---|
| 724 | rejoined the channel after a reconnect. Remove it so |
---|
| 725 | we can reuse its name. */ |
---|
| 726 | irc_channel_free( oic ); |
---|
| 727 | } |
---|
| 728 | else |
---|
| 729 | { |
---|
| 730 | g_free( full_name ); |
---|
| 731 | return FALSE; |
---|
| 732 | } |
---|
[d343eaa] | 733 | } |
---|
| 734 | |
---|
[52a2521] | 735 | g_free( ic->name ); |
---|
| 736 | ic->name = full_name; |
---|
| 737 | |
---|
[d343eaa] | 738 | return TRUE; |
---|
| 739 | } |
---|
| 740 | |
---|
[1aa74f55] | 741 | static gboolean bee_irc_chat_invite( bee_t *bee, bee_user_t *bu, const char *name, const char *msg ) |
---|
| 742 | { |
---|
| 743 | char *channel, *s; |
---|
| 744 | irc_t *irc = bee->ui_data; |
---|
| 745 | irc_user_t *iu = bu->ui_data; |
---|
| 746 | irc_channel_t *chan; |
---|
| 747 | |
---|
| 748 | if( strchr( CTYPES, name[0] ) ) |
---|
| 749 | channel = g_strdup( name ); |
---|
| 750 | else |
---|
| 751 | channel = g_strdup_printf( "#%s", name ); |
---|
| 752 | |
---|
| 753 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 754 | *s = '\0'; |
---|
| 755 | |
---|
| 756 | if( strlen( channel ) > MAX_NICK_LENGTH ) |
---|
| 757 | { |
---|
| 758 | /* If the channel name is very long (like those insane GTalk |
---|
| 759 | UUID names), try if we can use the inviter's nick. */ |
---|
| 760 | s = g_strdup_printf( "#%s", iu->nick ); |
---|
| 761 | if( irc_channel_by_name( irc, s ) == NULL ) |
---|
| 762 | { |
---|
| 763 | g_free( channel ); |
---|
| 764 | channel = s; |
---|
| 765 | } |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | if( ( chan = irc_channel_new( irc, channel ) ) && |
---|
| 769 | set_setstr( &chan->set, "type", "chat" ) && |
---|
| 770 | set_setstr( &chan->set, "chat_type", "room" ) && |
---|
| 771 | set_setstr( &chan->set, "account", bu->ic->acc->tag ) && |
---|
| 772 | set_setstr( &chan->set, "room", (char*) name ) ) |
---|
| 773 | { |
---|
| 774 | /* I'm assuming that if the user didn't "chat add" the room |
---|
| 775 | himself but got invited, it's temporary, so make this a |
---|
| 776 | temporary mapping that is removed as soon as we /PART. */ |
---|
| 777 | chan->flags |= IRC_CHANNEL_TEMP; |
---|
| 778 | } |
---|
| 779 | else |
---|
| 780 | { |
---|
| 781 | irc_channel_free( chan ); |
---|
| 782 | chan = NULL; |
---|
| 783 | } |
---|
| 784 | g_free( channel ); |
---|
| 785 | |
---|
| 786 | irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "<< \002BitlBee\002 - Invitation to chatroom %s >>", name ); |
---|
| 787 | if( msg ) |
---|
| 788 | irc_send_msg( iu, "PRIVMSG", irc->user->nick, msg, NULL ); |
---|
| 789 | if( chan ) |
---|
| 790 | { |
---|
| 791 | irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "To join the room, just /join %s", chan->name ); |
---|
| 792 | irc_send_invite( iu, chan ); |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | return TRUE; |
---|
| 796 | } |
---|
| 797 | |
---|
[a87754b] | 798 | /* IRC->IM */ |
---|
[619dd18] | 799 | static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); |
---|
| 800 | |
---|
[a87754b] | 801 | static gboolean bee_irc_channel_chat_privmsg( irc_channel_t *ic, const char *msg ) |
---|
| 802 | { |
---|
| 803 | struct groupchat *c = ic->data; |
---|
[69b896b] | 804 | char *trans = NULL, *s; |
---|
[a87754b] | 805 | |
---|
[5a75d15] | 806 | if( c == NULL ) |
---|
| 807 | return FALSE; |
---|
[69b896b] | 808 | |
---|
| 809 | if( set_getbool( &ic->set, "translate_to_nicks" ) ) |
---|
| 810 | { |
---|
| 811 | char nick[MAX_NICK_LENGTH+1]; |
---|
| 812 | irc_user_t *iu; |
---|
| 813 | |
---|
| 814 | strncpy( nick, msg, MAX_NICK_LENGTH ); |
---|
| 815 | nick[MAX_NICK_LENGTH] = '\0'; |
---|
| 816 | if( ( s = strchr( nick, ':' ) ) || ( s = strchr( nick, ',' ) ) ) |
---|
| 817 | { |
---|
| 818 | *s = '\0'; |
---|
[4c737ebd] | 819 | if( ( iu = irc_user_by_name( ic->irc, nick ) ) && iu->bu && |
---|
[69b896b] | 820 | iu->bu->nick && irc_channel_has_user( ic, iu ) ) |
---|
| 821 | { |
---|
| 822 | trans = g_strconcat( iu->bu->nick, msg + ( s - nick ), NULL ); |
---|
| 823 | msg = trans; |
---|
| 824 | } |
---|
| 825 | } |
---|
| 826 | } |
---|
| 827 | |
---|
| 828 | if( set_getbool( &ic->irc->b->set, "paste_buffer" ) ) |
---|
[619dd18] | 829 | { |
---|
| 830 | int delay; |
---|
| 831 | |
---|
| 832 | if( ic->pastebuf == NULL ) |
---|
| 833 | ic->pastebuf = g_string_new( msg ); |
---|
| 834 | else |
---|
| 835 | { |
---|
| 836 | b_event_remove( ic->pastebuf_timer ); |
---|
| 837 | g_string_append_printf( ic->pastebuf, "\n%s", msg ); |
---|
| 838 | } |
---|
| 839 | |
---|
| 840 | if( ( delay = set_getint( &ic->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) |
---|
| 841 | delay *= 1000; |
---|
| 842 | |
---|
| 843 | ic->pastebuf_timer = b_timeout_add( delay, bee_irc_channel_chat_privmsg_cb, ic ); |
---|
| 844 | |
---|
[69b896b] | 845 | g_free( trans ); |
---|
[619dd18] | 846 | return TRUE; |
---|
| 847 | } |
---|
| 848 | else |
---|
| 849 | bee_chat_msg( ic->irc->b, c, msg, 0 ); |
---|
[a87754b] | 850 | |
---|
[69b896b] | 851 | g_free( trans ); |
---|
[a87754b] | 852 | return TRUE; |
---|
[5a75d15] | 853 | } |
---|
| 854 | |
---|
[619dd18] | 855 | static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) |
---|
| 856 | { |
---|
| 857 | irc_channel_t *ic = data; |
---|
| 858 | |
---|
[cc20520] | 859 | if( ic->data ) |
---|
| 860 | bee_chat_msg( ic->irc->b, ic->data, ic->pastebuf->str, 0 ); |
---|
[619dd18] | 861 | |
---|
| 862 | g_string_free( ic->pastebuf, TRUE ); |
---|
| 863 | ic->pastebuf = 0; |
---|
| 864 | ic->pastebuf_timer = 0; |
---|
| 865 | |
---|
| 866 | return FALSE; |
---|
| 867 | } |
---|
| 868 | |
---|
[5a75d15] | 869 | static gboolean bee_irc_channel_chat_join( irc_channel_t *ic ) |
---|
| 870 | { |
---|
| 871 | char *acc_s, *room; |
---|
| 872 | account_t *acc; |
---|
[a87754b] | 873 | |
---|
[5a75d15] | 874 | if( strcmp( set_getstr( &ic->set, "chat_type" ), "room" ) != 0 ) |
---|
| 875 | return TRUE; |
---|
| 876 | |
---|
| 877 | if( ( acc_s = set_getstr( &ic->set, "account" ) ) && |
---|
| 878 | ( room = set_getstr( &ic->set, "room" ) ) && |
---|
| 879 | ( acc = account_get( ic->irc->b, acc_s ) ) && |
---|
| 880 | acc->ic && acc->prpl->chat_join ) |
---|
| 881 | { |
---|
| 882 | char *nick; |
---|
| 883 | |
---|
| 884 | if( !( nick = set_getstr( &ic->set, "nick" ) ) ) |
---|
| 885 | nick = ic->irc->user->nick; |
---|
| 886 | |
---|
| 887 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
[03f3828] | 888 | acc->prpl->chat_join( acc->ic, room, nick, NULL, &ic->set ); |
---|
[5a75d15] | 889 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
| 890 | |
---|
| 891 | return FALSE; |
---|
| 892 | } |
---|
| 893 | else |
---|
| 894 | { |
---|
| 895 | irc_send_num( ic->irc, 403, "%s :Can't join channel, account offline?", ic->name ); |
---|
| 896 | return FALSE; |
---|
| 897 | } |
---|
[a87754b] | 898 | } |
---|
| 899 | |
---|
[bfb99ee] | 900 | static gboolean bee_irc_channel_chat_part( irc_channel_t *ic, const char *msg ) |
---|
| 901 | { |
---|
| 902 | struct groupchat *c = ic->data; |
---|
| 903 | |
---|
[5a75d15] | 904 | if( c && c->ic->acc->prpl->chat_leave ) |
---|
[bfb99ee] | 905 | c->ic->acc->prpl->chat_leave( c ); |
---|
| 906 | |
---|
[cc20520] | 907 | ic->data = NULL; |
---|
| 908 | |
---|
[bfb99ee] | 909 | return TRUE; |
---|
| 910 | } |
---|
| 911 | |
---|
[9e27f18] | 912 | static gboolean bee_irc_channel_chat_topic( irc_channel_t *ic, const char *new ) |
---|
| 913 | { |
---|
[4469e7e] | 914 | struct groupchat *c = ic->data; |
---|
[5a75d15] | 915 | |
---|
| 916 | if( c == NULL ) |
---|
| 917 | return FALSE; |
---|
[4469e7e] | 918 | |
---|
| 919 | if( c->ic->acc->prpl->chat_topic == NULL ) |
---|
| 920 | irc_send_num( ic->irc, 482, "%s :IM network does not support channel topics", ic->name ); |
---|
| 921 | else |
---|
| 922 | { |
---|
[5a75d15] | 923 | /* TODO: Need more const goodness here, sigh */ |
---|
| 924 | char *topic = g_strdup( new ); |
---|
[4469e7e] | 925 | c->ic->acc->prpl->chat_topic( c, topic ); |
---|
[5a75d15] | 926 | g_free( topic ); |
---|
[4469e7e] | 927 | } |
---|
| 928 | |
---|
[41e0c00] | 929 | /* Whatever happened, the IM module should ack the topic change. */ |
---|
[4469e7e] | 930 | return FALSE; |
---|
[9e27f18] | 931 | } |
---|
| 932 | |
---|
[66b9e36a] | 933 | static gboolean bee_irc_channel_chat_invite( irc_channel_t *ic, irc_user_t *iu ) |
---|
| 934 | { |
---|
| 935 | struct groupchat *c = ic->data; |
---|
[5a75d15] | 936 | bee_user_t *bu = iu->bu; |
---|
| 937 | |
---|
| 938 | if( bu == NULL ) |
---|
| 939 | return FALSE; |
---|
[66b9e36a] | 940 | |
---|
[5a75d15] | 941 | if( c ) |
---|
| 942 | { |
---|
| 943 | if( iu->bu->ic != c->ic ) |
---|
| 944 | irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name ); |
---|
| 945 | else if( c->ic->acc->prpl->chat_invite ) |
---|
| 946 | c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL ); |
---|
| 947 | else |
---|
| 948 | irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); |
---|
| 949 | } |
---|
| 950 | else if( bu->ic->acc->prpl->chat_with && |
---|
| 951 | strcmp( set_getstr( &ic->set, "chat_type" ), "groupchat" ) == 0 ) |
---|
| 952 | { |
---|
| 953 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
| 954 | iu->bu->ic->acc->prpl->chat_with( bu->ic, bu->handle ); |
---|
| 955 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
| 956 | } |
---|
[66b9e36a] | 957 | else |
---|
[5a75d15] | 958 | { |
---|
[66b9e36a] | 959 | irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); |
---|
[5a75d15] | 960 | } |
---|
[66b9e36a] | 961 | |
---|
| 962 | return TRUE; |
---|
| 963 | } |
---|
| 964 | |
---|
[5a75d15] | 965 | static char *set_eval_room_account( set_t *set, char *value ); |
---|
[1c40aa7] | 966 | static char *set_eval_chat_type( set_t *set, char *value ); |
---|
[5a75d15] | 967 | |
---|
| 968 | static gboolean bee_irc_channel_init( irc_channel_t *ic ) |
---|
| 969 | { |
---|
| 970 | set_add( &ic->set, "account", NULL, set_eval_room_account, ic ); |
---|
[1c40aa7] | 971 | set_add( &ic->set, "chat_type", "groupchat", set_eval_chat_type, ic ); |
---|
[5a75d15] | 972 | set_add( &ic->set, "nick", NULL, NULL, ic ); |
---|
| 973 | set_add( &ic->set, "room", NULL, NULL, ic ); |
---|
[69b896b] | 974 | set_add( &ic->set, "translate_to_nicks", "true", set_eval_bool, ic ); |
---|
[5a75d15] | 975 | |
---|
[1c40aa7] | 976 | /* chat_type == groupchat */ |
---|
| 977 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
| 978 | |
---|
[5a75d15] | 979 | return TRUE; |
---|
| 980 | } |
---|
| 981 | |
---|
| 982 | static char *set_eval_room_account( set_t *set, char *value ) |
---|
| 983 | { |
---|
| 984 | struct irc_channel *ic = set->data; |
---|
[03f3828] | 985 | account_t *acc, *oa; |
---|
[5a75d15] | 986 | |
---|
| 987 | if( !( acc = account_get( ic->irc->b, value ) ) ) |
---|
| 988 | return SET_INVALID; |
---|
| 989 | else if( !acc->prpl->chat_join ) |
---|
| 990 | { |
---|
| 991 | irc_usermsg( ic->irc, "Named chatrooms not supported on that account." ); |
---|
| 992 | return SET_INVALID; |
---|
| 993 | } |
---|
| 994 | |
---|
[03f3828] | 995 | if( set->value && ( oa = account_get( ic->irc->b, set->value ) ) && |
---|
| 996 | oa->prpl->chat_free_settings ) |
---|
| 997 | oa->prpl->chat_free_settings( oa, &ic->set ); |
---|
| 998 | |
---|
| 999 | if( acc->prpl->chat_add_settings ) |
---|
| 1000 | acc->prpl->chat_add_settings( acc, &ic->set ); |
---|
| 1001 | |
---|
[e135cd09] | 1002 | return g_strdup( acc->tag ); |
---|
[5a75d15] | 1003 | } |
---|
| 1004 | |
---|
[1c40aa7] | 1005 | static char *set_eval_chat_type( set_t *set, char *value ) |
---|
| 1006 | { |
---|
| 1007 | struct irc_channel *ic = set->data; |
---|
| 1008 | |
---|
| 1009 | if( strcmp( value, "groupchat" ) == 0 ) |
---|
| 1010 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
| 1011 | else if( strcmp( value, "room" ) == 0 ) |
---|
| 1012 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
| 1013 | else |
---|
| 1014 | return NULL; |
---|
| 1015 | |
---|
| 1016 | return value; |
---|
| 1017 | } |
---|
| 1018 | |
---|
[5a75d15] | 1019 | static gboolean bee_irc_channel_free( irc_channel_t *ic ) |
---|
| 1020 | { |
---|
[b1af3e8] | 1021 | struct groupchat *c = ic->data; |
---|
| 1022 | |
---|
[5a75d15] | 1023 | set_del( &ic->set, "account" ); |
---|
| 1024 | set_del( &ic->set, "chat_type" ); |
---|
| 1025 | set_del( &ic->set, "nick" ); |
---|
| 1026 | set_del( &ic->set, "room" ); |
---|
[69b896b] | 1027 | set_del( &ic->set, "translate_to_nicks" ); |
---|
[5a75d15] | 1028 | |
---|
[1c40aa7] | 1029 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
| 1030 | |
---|
[b1af3e8] | 1031 | /* That one still points at this channel. Don't. */ |
---|
| 1032 | if( c ) |
---|
| 1033 | c->ui_data = NULL; |
---|
| 1034 | |
---|
[5a75d15] | 1035 | return TRUE; |
---|
| 1036 | } |
---|
| 1037 | |
---|
| 1038 | const struct irc_channel_funcs irc_channel_im_chat_funcs = { |
---|
[a87754b] | 1039 | bee_irc_channel_chat_privmsg, |
---|
[5a75d15] | 1040 | bee_irc_channel_chat_join, |
---|
[bfb99ee] | 1041 | bee_irc_channel_chat_part, |
---|
[9e27f18] | 1042 | bee_irc_channel_chat_topic, |
---|
[66b9e36a] | 1043 | bee_irc_channel_chat_invite, |
---|
[5a75d15] | 1044 | |
---|
| 1045 | bee_irc_channel_init, |
---|
| 1046 | bee_irc_channel_free, |
---|
[a87754b] | 1047 | }; |
---|
| 1048 | |
---|
[aea8b68] | 1049 | |
---|
[e4816ea] | 1050 | /* IM->IRC: File transfers */ |
---|
[17a6ee9] | 1051 | static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size ) |
---|
| 1052 | { |
---|
| 1053 | return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size ); |
---|
| 1054 | } |
---|
| 1055 | |
---|
[a87754b] | 1056 | static gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 1057 | { |
---|
| 1058 | return dccs_recv_start( ft ); |
---|
| 1059 | } |
---|
| 1060 | |
---|
[a87754b] | 1061 | static void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 1062 | { |
---|
| 1063 | return dcc_close( ft ); |
---|
| 1064 | } |
---|
| 1065 | |
---|
[a87754b] | 1066 | static void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file ) |
---|
[17a6ee9] | 1067 | { |
---|
| 1068 | dcc_file_transfer_t *df = file->priv; |
---|
| 1069 | |
---|
| 1070 | if( file->bytes_transferred >= file->file_size ) |
---|
| 1071 | dcc_finish( file ); |
---|
| 1072 | else |
---|
| 1073 | df->proto_finished = TRUE; |
---|
| 1074 | } |
---|
| 1075 | |
---|
[d860a8d] | 1076 | const struct bee_ui_funcs irc_ui_funcs = { |
---|
[5c7b45c] | 1077 | bee_irc_imc_connected, |
---|
| 1078 | bee_irc_imc_disconnected, |
---|
| 1079 | |
---|
[81e04e1] | 1080 | bee_irc_user_new, |
---|
[d860a8d] | 1081 | bee_irc_user_free, |
---|
[1d39159] | 1082 | bee_irc_user_fullname, |
---|
[6ef9065] | 1083 | bee_irc_user_nick_hint, |
---|
[7e83e8e4] | 1084 | bee_irc_user_group, |
---|
[d860a8d] | 1085 | bee_irc_user_status, |
---|
[f012a9f] | 1086 | bee_irc_user_msg, |
---|
[573dab0] | 1087 | bee_irc_user_typing, |
---|
[d88c92a] | 1088 | bee_irc_user_action_response, |
---|
[17a6ee9] | 1089 | |
---|
[aea8b68] | 1090 | bee_irc_chat_new, |
---|
| 1091 | bee_irc_chat_free, |
---|
[27e2c66] | 1092 | bee_irc_chat_log, |
---|
| 1093 | bee_irc_chat_msg, |
---|
[aea8b68] | 1094 | bee_irc_chat_add_user, |
---|
[b17ce85] | 1095 | bee_irc_chat_remove_user, |
---|
[9e27f18] | 1096 | bee_irc_chat_topic, |
---|
[d343eaa] | 1097 | bee_irc_chat_name_hint, |
---|
[1aa74f55] | 1098 | bee_irc_chat_invite, |
---|
[aea8b68] | 1099 | |
---|
[17a6ee9] | 1100 | bee_irc_ft_in_start, |
---|
| 1101 | bee_irc_ft_out_start, |
---|
| 1102 | bee_irc_ft_close, |
---|
| 1103 | bee_irc_ft_finished, |
---|
[81e04e1] | 1104 | }; |
---|