[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 | |
---|
| 33 | static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu ) |
---|
| 34 | { |
---|
| 35 | irc_user_t *iu; |
---|
| 36 | char nick[MAX_NICK_LENGTH+1], *s; |
---|
| 37 | |
---|
| 38 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
| 39 | strcpy( nick, nick_get( bu->ic->acc, bu->handle ) ); |
---|
| 40 | |
---|
[d860a8d] | 41 | bu->ui_data = iu = irc_user_new( (irc_t*) bee->ui_data, nick ); |
---|
| 42 | iu->bu = bu; |
---|
[81e04e1] | 43 | |
---|
| 44 | if( ( s = strchr( bu->handle, '@' ) ) ) |
---|
| 45 | { |
---|
| 46 | iu->host = g_strdup( s + 1 ); |
---|
| 47 | iu->user = g_strndup( bu->handle, s - bu->handle ); |
---|
| 48 | } |
---|
| 49 | else if( bu->ic->acc->server ) |
---|
| 50 | { |
---|
| 51 | iu->host = g_strdup( bu->ic->acc->server ); |
---|
| 52 | iu->user = g_strdup( bu->handle ); |
---|
| 53 | |
---|
| 54 | /* s/ /_/ ... important for AOL screennames */ |
---|
| 55 | for( s = iu->user; *s; s ++ ) |
---|
| 56 | if( *s == ' ' ) |
---|
| 57 | *s = '_'; |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
| 61 | iu->host = g_strdup( bu->ic->acc->prpl->name ); |
---|
| 62 | iu->user = g_strdup( bu->handle ); |
---|
| 63 | } |
---|
| 64 | |
---|
[f012a9f] | 65 | if( set_getbool( &bee->set, "private" ) ) |
---|
| 66 | iu->flags |= IRC_USER_PRIVATE; |
---|
| 67 | |
---|
[81e04e1] | 68 | iu->f = &irc_user_im_funcs; |
---|
| 69 | //iu->last_typing_notice = 0; |
---|
| 70 | |
---|
| 71 | return TRUE; |
---|
| 72 | } |
---|
| 73 | |
---|
[d860a8d] | 74 | static gboolean bee_irc_user_free( bee_t *bee, bee_user_t *bu ) |
---|
| 75 | { |
---|
[eabc9d2] | 76 | return irc_user_free( bee->ui_data, (irc_user_t *) bu->ui_data ); |
---|
[d860a8d] | 77 | } |
---|
[81e04e1] | 78 | |
---|
[d860a8d] | 79 | static gboolean bee_irc_user_status( bee_t *bee, bee_user_t *bu, bee_user_t *old ) |
---|
| 80 | { |
---|
[231b08b] | 81 | irc_t *irc = bee->ui_data; |
---|
[003a12b] | 82 | irc_user_t *iu = bu->ui_data; |
---|
[231b08b] | 83 | |
---|
[eb50495] | 84 | /* Do this outside the if below since away state can change without |
---|
| 85 | the online state changing. */ |
---|
| 86 | iu->flags &= ~IRC_USER_AWAY; |
---|
| 87 | if( bu->flags & BEE_USER_AWAY || !( bu->flags & BEE_USER_ONLINE ) ) |
---|
| 88 | iu->flags |= IRC_USER_AWAY; |
---|
| 89 | |
---|
[231b08b] | 90 | if( ( bu->flags & BEE_USER_ONLINE ) != ( old->flags & BEE_USER_ONLINE ) ) |
---|
| 91 | { |
---|
| 92 | if( bu->flags & BEE_USER_ONLINE ) |
---|
[003a12b] | 93 | { |
---|
| 94 | if( g_hash_table_lookup( irc->watches, iu->key ) ) |
---|
| 95 | irc_send_num( irc, 600, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
| 96 | iu->host, (int) time( NULL ), "logged online" ); |
---|
| 97 | } |
---|
[231b08b] | 98 | else |
---|
[003a12b] | 99 | { |
---|
| 100 | if( g_hash_table_lookup( irc->watches, iu->key ) ) |
---|
| 101 | irc_send_num( irc, 601, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
| 102 | iu->host, (int) time( NULL ), "logged offline" ); |
---|
| 103 | } |
---|
[231b08b] | 104 | } |
---|
| 105 | |
---|
[13c1a9f] | 106 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 107 | |
---|
[d860a8d] | 108 | return TRUE; |
---|
| 109 | } |
---|
[81e04e1] | 110 | |
---|
[13c1a9f] | 111 | void bee_irc_channel_update( irc_t *irc, irc_channel_t *ic, irc_user_t *iu ) |
---|
| 112 | { |
---|
| 113 | struct irc_control_channel *icc; |
---|
| 114 | GSList *l; |
---|
| 115 | gboolean show; |
---|
| 116 | |
---|
| 117 | if( ic == NULL ) |
---|
| 118 | { |
---|
| 119 | for( l = irc->channels; l; l = l->next ) |
---|
| 120 | { |
---|
| 121 | ic = l->data; |
---|
| 122 | /* TODO: Just add a type flag or so.. */ |
---|
| 123 | if( ic->f == irc->default_channel->f ) |
---|
| 124 | bee_irc_channel_update( irc, ic, iu ); |
---|
| 125 | } |
---|
| 126 | return; |
---|
| 127 | } |
---|
| 128 | if( iu == NULL ) |
---|
| 129 | { |
---|
| 130 | for( l = irc->users; l; l = l->next ) |
---|
| 131 | { |
---|
| 132 | iu = l->data; |
---|
| 133 | if( iu->bu ) |
---|
| 134 | bee_irc_channel_update( irc, ic, l->data ); |
---|
| 135 | } |
---|
| 136 | return; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | icc = ic->data; |
---|
| 140 | |
---|
| 141 | if( !( iu->bu->flags & BEE_USER_ONLINE ) ) |
---|
| 142 | show = FALSE; |
---|
| 143 | else if( icc->type == IRC_CC_TYPE_DEFAULT ) |
---|
| 144 | show = TRUE; |
---|
| 145 | else if( icc->type == IRC_CC_TYPE_GROUP ) |
---|
| 146 | show = iu->bu->group == icc->group; |
---|
[a067771] | 147 | else if( icc->type == IRC_CC_TYPE_ACCOUNT ) |
---|
| 148 | show = iu->bu->ic->acc == icc->account; |
---|
[13c1a9f] | 149 | |
---|
| 150 | if( !show ) |
---|
| 151 | { |
---|
| 152 | irc_channel_del_user( ic, iu ); |
---|
| 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | irc_channel_add_user( ic, iu ); |
---|
| 157 | |
---|
| 158 | if( set_getbool( &irc->b->set, "away_devoice" ) ) |
---|
| 159 | irc_channel_user_set_mode( ic, iu, ( iu->bu->flags & BEE_USER_AWAY ) ? |
---|
| 160 | 0 : IRC_CHANNEL_USER_VOICE ); |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
[f012a9f] | 164 | static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at ) |
---|
| 165 | { |
---|
| 166 | irc_t *irc = bee->ui_data; |
---|
[fd45e1d1] | 167 | irc_channel_t *ic = irc->default_channel; |
---|
[f012a9f] | 168 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 169 | char *dst, *prefix = NULL; |
---|
[21c87a7] | 170 | char *wrapped, *ts = NULL; |
---|
| 171 | |
---|
| 172 | if( sent_at > 0 && set_getbool( &irc->b->set, "display_timestamps" ) ) |
---|
| 173 | ts = irc_format_timestamp( irc, sent_at ); |
---|
[f012a9f] | 174 | |
---|
| 175 | if( iu->flags & IRC_USER_PRIVATE ) |
---|
| 176 | { |
---|
| 177 | dst = irc->user->nick; |
---|
[21c87a7] | 178 | prefix = ts; |
---|
| 179 | ts = NULL; |
---|
[f012a9f] | 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
| 183 | dst = ic->name; |
---|
[bce78c8] | 184 | prefix = g_strdup_printf( "%s%s%s", irc->user->nick, set_getstr( &bee->set, "to_char" ), ts ? : "" ); |
---|
[f012a9f] | 185 | } |
---|
| 186 | |
---|
| 187 | wrapped = word_wrap( msg, 425 ); |
---|
| 188 | irc_send_msg( iu, "PRIVMSG", dst, wrapped, prefix ); |
---|
| 189 | |
---|
| 190 | g_free( wrapped ); |
---|
| 191 | g_free( prefix ); |
---|
[21c87a7] | 192 | g_free( ts ); |
---|
[f012a9f] | 193 | |
---|
| 194 | return TRUE; |
---|
| 195 | } |
---|
| 196 | |
---|
[573dab0] | 197 | static gboolean bee_irc_user_typing( bee_t *bee, bee_user_t *bu, uint32_t flags ) |
---|
| 198 | { |
---|
| 199 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
| 200 | |
---|
| 201 | if( set_getbool( &bee->set, "typing_notice" ) ) |
---|
| 202 | irc_send_msg_f( (irc_user_t *) bu->ui_data, "PRIVMSG", irc->user->nick, |
---|
| 203 | "\001TYPING %d\001", ( flags >> 8 ) & 3 ); |
---|
| 204 | else |
---|
| 205 | return FALSE; |
---|
| 206 | |
---|
| 207 | return TRUE; |
---|
| 208 | } |
---|
| 209 | |
---|
[1d39159] | 210 | static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu ) |
---|
| 211 | { |
---|
| 212 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 213 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
| 214 | char *s; |
---|
| 215 | |
---|
| 216 | if( iu->fullname != iu->nick ) |
---|
| 217 | g_free( iu->fullname ); |
---|
| 218 | iu->fullname = g_strdup( bu->fullname ); |
---|
| 219 | |
---|
| 220 | /* Strip newlines (unlikely, but IRC-unfriendly so they must go) |
---|
| 221 | TODO(wilmer): Do the same with away msgs again! */ |
---|
| 222 | for( s = iu->fullname; *s; s ++ ) |
---|
| 223 | if( isspace( *s ) ) *s = ' '; |
---|
| 224 | |
---|
| 225 | if( ( bu->ic->flags & OPT_LOGGED_IN ) && set_getbool( &bee->set, "display_namechanges" ) ) |
---|
| 226 | { |
---|
| 227 | char *msg = g_strdup_printf( "<< \002BitlBee\002 - Changed name to `%s' >>", iu->fullname ); |
---|
| 228 | irc_send_msg( iu, "NOTICE", irc->user->nick, msg, NULL ); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | s = set_getstr( &bu->ic->acc->set, "nick_source" ); |
---|
| 232 | if( strcmp( s, "handle" ) != 0 ) |
---|
| 233 | { |
---|
| 234 | char *name = g_strdup( bu->fullname ); |
---|
| 235 | |
---|
| 236 | if( strcmp( s, "first_name" ) == 0 ) |
---|
| 237 | { |
---|
| 238 | int i; |
---|
| 239 | for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {} |
---|
| 240 | name[i] = '\0'; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | imcb_buddy_nick_hint( bu->ic, bu->handle, name ); |
---|
| 244 | |
---|
| 245 | g_free( name ); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | return TRUE; |
---|
| 249 | } |
---|
| 250 | |
---|
[e4816ea] | 251 | /* IRC->IM calls */ |
---|
| 252 | |
---|
| 253 | static gboolean bee_irc_user_privmsg( irc_user_t *iu, const char *msg ) |
---|
| 254 | { |
---|
| 255 | if( iu->bu ) |
---|
| 256 | return bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); |
---|
| 257 | else |
---|
| 258 | return FALSE; |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | static gboolean bee_irc_user_ctcp( irc_user_t *iu, char *const *ctcp ) |
---|
| 262 | { |
---|
| 263 | if( ctcp[1] && g_strcasecmp( ctcp[0], "DCC" ) == 0 |
---|
| 264 | && g_strcasecmp( ctcp[1], "SEND" ) == 0 ) |
---|
| 265 | { |
---|
| 266 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request ) |
---|
| 267 | { |
---|
| 268 | file_transfer_t *ft = dcc_request( iu->bu->ic, ctcp ); |
---|
| 269 | if ( ft ) |
---|
| 270 | iu->bu->ic->acc->prpl->transfer_request( iu->bu->ic, ft, iu->bu->handle ); |
---|
| 271 | |
---|
| 272 | return TRUE; |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | else if( g_strcasecmp( ctcp[0], "TYPING" ) == 0 ) |
---|
| 276 | { |
---|
| 277 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->send_typing && ctcp[1] ) |
---|
| 278 | { |
---|
| 279 | int st = ctcp[1][0]; |
---|
| 280 | if( st >= '0' && st <= '2' ) |
---|
| 281 | { |
---|
| 282 | st <<= 8; |
---|
| 283 | iu->bu->ic->acc->prpl->send_typing( iu->bu->ic, iu->bu->handle, st ); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | return TRUE; |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | return FALSE; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | static const struct irc_user_funcs irc_user_im_funcs = { |
---|
| 294 | bee_irc_user_privmsg, |
---|
| 295 | bee_irc_user_ctcp, |
---|
| 296 | }; |
---|
| 297 | |
---|
[aea8b68] | 298 | |
---|
[e4816ea] | 299 | /* IM->IRC: Groupchats */ |
---|
[a87754b] | 300 | static const struct irc_channel_funcs irc_channel_im_chat_funcs; |
---|
| 301 | |
---|
| 302 | static gboolean bee_irc_chat_new( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 303 | { |
---|
| 304 | irc_t *irc = bee->ui_data; |
---|
| 305 | irc_channel_t *ic; |
---|
| 306 | char *topic; |
---|
[eb37735] | 307 | GSList *l; |
---|
[aea8b68] | 308 | int i; |
---|
| 309 | |
---|
[eb37735] | 310 | /* Try to find a channel that expects to receive a groupchat. |
---|
| 311 | This flag is set by groupchat_stub_invite(). */ |
---|
| 312 | for( l = irc->channels; l; l = l->next ) |
---|
| 313 | { |
---|
| 314 | ic = l->data; |
---|
| 315 | if( ic->flags & IRC_CHANNEL_CHAT_PICKME ) |
---|
| 316 | break; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | /* If we found none, just generate some stupid name. */ |
---|
| 320 | if( l == NULL ) for( i = 0; i <= 999; i ++ ) |
---|
[aea8b68] | 321 | { |
---|
| 322 | char name[16]; |
---|
| 323 | sprintf( name, "&chat_%03d", i ); |
---|
| 324 | if( ( ic = irc_channel_new( irc, name ) ) ) |
---|
| 325 | break; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | if( ic == NULL ) |
---|
| 329 | return FALSE; |
---|
| 330 | |
---|
| 331 | c->ui_data = ic; |
---|
| 332 | ic->data = c; |
---|
[a87754b] | 333 | ic->f = &irc_channel_im_chat_funcs; |
---|
[aea8b68] | 334 | |
---|
| 335 | topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
| 336 | irc_channel_set_topic( ic, topic, irc->root ); |
---|
| 337 | g_free( topic ); |
---|
| 338 | |
---|
| 339 | return TRUE; |
---|
| 340 | } |
---|
| 341 | |
---|
[a87754b] | 342 | static gboolean bee_irc_chat_free( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 343 | { |
---|
| 344 | irc_channel_t *ic = c->ui_data; |
---|
| 345 | |
---|
| 346 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 347 | irc_channel_printf( ic, "Cleaning up channel, bye!" ); |
---|
| 348 | |
---|
| 349 | irc_channel_free( ic ); |
---|
| 350 | |
---|
| 351 | return TRUE; |
---|
| 352 | } |
---|
| 353 | |
---|
[a87754b] | 354 | static gboolean bee_irc_chat_log( bee_t *bee, struct groupchat *c, const char *text ) |
---|
[aea8b68] | 355 | { |
---|
[27e2c66] | 356 | irc_channel_t *ic = c->ui_data; |
---|
| 357 | |
---|
| 358 | irc_channel_printf( ic, "%s", text ); |
---|
[b17ce85] | 359 | |
---|
| 360 | return TRUE; |
---|
[aea8b68] | 361 | } |
---|
| 362 | |
---|
[a87754b] | 363 | static gboolean bee_irc_chat_msg( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at ) |
---|
[aea8b68] | 364 | { |
---|
[27e2c66] | 365 | irc_t *irc = bee->ui_data; |
---|
| 366 | irc_user_t *iu = bu->ui_data; |
---|
| 367 | irc_channel_t *ic = c->ui_data; |
---|
| 368 | char *ts = NULL; |
---|
| 369 | |
---|
| 370 | if( sent_at > 0 && set_getbool( &bee->set, "display_timestamps" ) ) |
---|
| 371 | ts = irc_format_timestamp( irc, sent_at ); |
---|
| 372 | |
---|
| 373 | irc_send_msg( iu, "PRIVMSG", ic->name, msg, ts ); |
---|
| 374 | g_free( ts ); |
---|
| 375 | |
---|
| 376 | return TRUE; |
---|
[aea8b68] | 377 | } |
---|
| 378 | |
---|
[a87754b] | 379 | static gboolean bee_irc_chat_add_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 380 | { |
---|
| 381 | irc_t *irc = bee->ui_data; |
---|
| 382 | |
---|
| 383 | irc_channel_add_user( c->ui_data, bu == bee->user ? irc->user : bu->ui_data ); |
---|
[b17ce85] | 384 | |
---|
| 385 | return TRUE; |
---|
[aea8b68] | 386 | } |
---|
| 387 | |
---|
[a87754b] | 388 | static gboolean bee_irc_chat_remove_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 389 | { |
---|
[b17ce85] | 390 | irc_t *irc = bee->ui_data; |
---|
| 391 | |
---|
| 392 | irc_channel_del_user( c->ui_data, bu == bee->user ? irc->user : bu->ui_data ); |
---|
| 393 | |
---|
| 394 | return TRUE; |
---|
[aea8b68] | 395 | } |
---|
| 396 | |
---|
[9e27f18] | 397 | static gboolean bee_irc_chat_topic( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu ) |
---|
| 398 | { |
---|
| 399 | irc_t *irc = bee->ui_data; |
---|
| 400 | irc_user_t *iu; |
---|
| 401 | |
---|
| 402 | if( bu == NULL ) |
---|
| 403 | iu = irc->root; |
---|
| 404 | else if( bu == bee->user ) |
---|
| 405 | iu = irc->user; |
---|
| 406 | else |
---|
| 407 | iu = bu->ui_data; |
---|
| 408 | |
---|
| 409 | irc_channel_set_topic( c->ui_data, new, iu ); |
---|
| 410 | |
---|
| 411 | return TRUE; |
---|
| 412 | } |
---|
| 413 | |
---|
[d343eaa] | 414 | static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const char *name ) |
---|
| 415 | { |
---|
| 416 | irc_t *irc = bee->ui_data; |
---|
| 417 | irc_channel_t *ic = c->ui_data; |
---|
| 418 | char stripped[MAX_NICK_LENGTH+1], *full_name; |
---|
| 419 | |
---|
| 420 | /* Don't rename a channel if the user's in it already. */ |
---|
| 421 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 422 | return FALSE; |
---|
| 423 | |
---|
| 424 | strncpy( stripped, name, MAX_NICK_LENGTH ); |
---|
| 425 | stripped[MAX_NICK_LENGTH] = '\0'; |
---|
| 426 | nick_strip( stripped ); |
---|
| 427 | if( set_getbool( &bee->set, "lcnicks" ) ) |
---|
| 428 | nick_lc( stripped ); |
---|
| 429 | |
---|
| 430 | full_name = g_strdup_printf( "&%s", stripped ); |
---|
| 431 | |
---|
| 432 | if( stripped[0] && irc_channel_by_name( irc, full_name ) == NULL ) |
---|
| 433 | { |
---|
| 434 | g_free( ic->name ); |
---|
| 435 | ic->name = full_name; |
---|
| 436 | } |
---|
| 437 | else |
---|
| 438 | { |
---|
| 439 | g_free( full_name ); |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | return TRUE; |
---|
| 443 | } |
---|
| 444 | |
---|
[a87754b] | 445 | /* IRC->IM */ |
---|
| 446 | static gboolean bee_irc_channel_chat_privmsg( irc_channel_t *ic, const char *msg ) |
---|
| 447 | { |
---|
| 448 | struct groupchat *c = ic->data; |
---|
| 449 | |
---|
| 450 | bee_chat_msg( ic->irc->b, c, msg, 0 ); |
---|
| 451 | |
---|
| 452 | return TRUE; |
---|
| 453 | |
---|
| 454 | } |
---|
| 455 | |
---|
[bfb99ee] | 456 | static gboolean bee_irc_channel_chat_part( irc_channel_t *ic, const char *msg ) |
---|
| 457 | { |
---|
| 458 | struct groupchat *c = ic->data; |
---|
| 459 | |
---|
| 460 | if( c->ic->acc->prpl->chat_leave ) |
---|
| 461 | c->ic->acc->prpl->chat_leave( c ); |
---|
| 462 | |
---|
| 463 | return TRUE; |
---|
| 464 | |
---|
| 465 | } |
---|
| 466 | |
---|
[9e27f18] | 467 | static gboolean bee_irc_channel_chat_topic( irc_channel_t *ic, const char *new ) |
---|
| 468 | { |
---|
[fd45e1d1] | 469 | return TRUE; |
---|
[9e27f18] | 470 | } |
---|
| 471 | |
---|
[66b9e36a] | 472 | static gboolean bee_irc_channel_chat_invite( irc_channel_t *ic, irc_user_t *iu ) |
---|
| 473 | { |
---|
| 474 | struct groupchat *c = ic->data; |
---|
| 475 | |
---|
| 476 | if( iu->bu->ic != c->ic ) |
---|
| 477 | irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name ); |
---|
| 478 | else if( c->ic->acc->prpl->chat_invite ) |
---|
| 479 | c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL ); |
---|
| 480 | else |
---|
| 481 | irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); |
---|
| 482 | |
---|
| 483 | return TRUE; |
---|
| 484 | } |
---|
| 485 | |
---|
[a87754b] | 486 | static const struct irc_channel_funcs irc_channel_im_chat_funcs = { |
---|
| 487 | bee_irc_channel_chat_privmsg, |
---|
[d343eaa] | 488 | NULL, /* join */ |
---|
[bfb99ee] | 489 | bee_irc_channel_chat_part, |
---|
[9e27f18] | 490 | bee_irc_channel_chat_topic, |
---|
[66b9e36a] | 491 | bee_irc_channel_chat_invite, |
---|
[a87754b] | 492 | }; |
---|
| 493 | |
---|
[aea8b68] | 494 | |
---|
[e4816ea] | 495 | /* IM->IRC: File transfers */ |
---|
[17a6ee9] | 496 | static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size ) |
---|
| 497 | { |
---|
| 498 | return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size ); |
---|
| 499 | } |
---|
| 500 | |
---|
[a87754b] | 501 | static gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 502 | { |
---|
| 503 | return dccs_recv_start( ft ); |
---|
| 504 | } |
---|
| 505 | |
---|
[a87754b] | 506 | static void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 507 | { |
---|
| 508 | return dcc_close( ft ); |
---|
| 509 | } |
---|
| 510 | |
---|
[a87754b] | 511 | static void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file ) |
---|
[17a6ee9] | 512 | { |
---|
| 513 | dcc_file_transfer_t *df = file->priv; |
---|
| 514 | |
---|
| 515 | if( file->bytes_transferred >= file->file_size ) |
---|
| 516 | dcc_finish( file ); |
---|
| 517 | else |
---|
| 518 | df->proto_finished = TRUE; |
---|
| 519 | } |
---|
| 520 | |
---|
[d860a8d] | 521 | const struct bee_ui_funcs irc_ui_funcs = { |
---|
[81e04e1] | 522 | bee_irc_user_new, |
---|
[d860a8d] | 523 | bee_irc_user_free, |
---|
[1d39159] | 524 | bee_irc_user_fullname, |
---|
[d860a8d] | 525 | bee_irc_user_status, |
---|
[f012a9f] | 526 | bee_irc_user_msg, |
---|
[573dab0] | 527 | bee_irc_user_typing, |
---|
[17a6ee9] | 528 | |
---|
[aea8b68] | 529 | bee_irc_chat_new, |
---|
| 530 | bee_irc_chat_free, |
---|
[27e2c66] | 531 | bee_irc_chat_log, |
---|
| 532 | bee_irc_chat_msg, |
---|
[aea8b68] | 533 | bee_irc_chat_add_user, |
---|
[b17ce85] | 534 | bee_irc_chat_remove_user, |
---|
[9e27f18] | 535 | bee_irc_chat_topic, |
---|
[d343eaa] | 536 | bee_irc_chat_name_hint, |
---|
[aea8b68] | 537 | |
---|
[17a6ee9] | 538 | bee_irc_ft_in_start, |
---|
| 539 | bee_irc_ft_out_start, |
---|
| 540 | bee_irc_ft_close, |
---|
| 541 | bee_irc_ft_finished, |
---|
[81e04e1] | 542 | }; |
---|