[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[ecf8fa8] | 4 | * Copyright 2002-2006 Wilmer van der Gaast and others * |
---|
[b7d3cc34] | 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* |
---|
| 8 | * nogaim |
---|
| 9 | * |
---|
| 10 | * Gaim without gaim - for BitlBee |
---|
| 11 | * |
---|
| 12 | * This file contains functions called by the Gaim IM-modules. It's written |
---|
| 13 | * from scratch for BitlBee and doesn't contain any code from Gaim anymore |
---|
| 14 | * (except for the function names). |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | /* |
---|
| 18 | This program is free software; you can redistribute it and/or modify |
---|
| 19 | it under the terms of the GNU General Public License as published by |
---|
| 20 | the Free Software Foundation; either version 2 of the License, or |
---|
| 21 | (at your option) any later version. |
---|
| 22 | |
---|
| 23 | This program is distributed in the hope that it will be useful, |
---|
| 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 26 | GNU General Public License for more details. |
---|
| 27 | |
---|
| 28 | You should have received a copy of the GNU General Public License with |
---|
| 29 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 30 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 31 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #define BITLBEE_CORE |
---|
| 35 | #include "nogaim.h" |
---|
| 36 | #include <ctype.h> |
---|
| 37 | |
---|
[764b163d] | 38 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); |
---|
[b7d3cc34] | 39 | |
---|
| 40 | GSList *connections; |
---|
| 41 | |
---|
[65e2ce1] | 42 | #ifdef WITH_PLUGINS |
---|
[7b23afd] | 43 | gboolean load_plugin(char *path) |
---|
| 44 | { |
---|
| 45 | void (*init_function) (void); |
---|
| 46 | |
---|
| 47 | GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); |
---|
| 48 | |
---|
| 49 | if(!mod) { |
---|
[8ad90fb] | 50 | log_message(LOGLVL_ERROR, "Can't find `%s', not loading (%s)\n", path, g_module_error()); |
---|
[7b23afd] | 51 | return FALSE; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) { |
---|
| 55 | log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path); |
---|
| 56 | return FALSE; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | init_function(); |
---|
| 60 | |
---|
| 61 | return TRUE; |
---|
| 62 | } |
---|
[b7d3cc34] | 63 | |
---|
[65e2ce1] | 64 | void load_plugins(void) |
---|
| 65 | { |
---|
| 66 | GDir *dir; |
---|
| 67 | GError *error = NULL; |
---|
| 68 | |
---|
[4bfca70] | 69 | dir = g_dir_open(global.conf->plugindir, 0, &error); |
---|
[65e2ce1] | 70 | |
---|
| 71 | if (dir) { |
---|
| 72 | const gchar *entry; |
---|
| 73 | char *path; |
---|
| 74 | |
---|
| 75 | while ((entry = g_dir_read_name(dir))) { |
---|
[4bfca70] | 76 | path = g_build_filename(global.conf->plugindir, entry, NULL); |
---|
[65e2ce1] | 77 | if(!path) { |
---|
| 78 | log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); |
---|
| 79 | continue; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | load_plugin(path); |
---|
| 83 | |
---|
| 84 | g_free(path); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | g_dir_close(dir); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | #endif |
---|
[b7d3cc34] | 91 | |
---|
| 92 | /* nogaim.c */ |
---|
| 93 | |
---|
[7b23afd] | 94 | GList *protocols = NULL; |
---|
| 95 | |
---|
| 96 | void register_protocol (struct prpl *p) |
---|
| 97 | { |
---|
| 98 | protocols = g_list_append(protocols, p); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | struct prpl *find_protocol(const char *name) |
---|
| 102 | { |
---|
| 103 | GList *gl; |
---|
| 104 | for (gl = protocols; gl; gl = gl->next) |
---|
| 105 | { |
---|
| 106 | struct prpl *proto = gl->data; |
---|
| 107 | if(!g_strcasecmp(proto->name, name)) |
---|
| 108 | return proto; |
---|
| 109 | } |
---|
| 110 | return NULL; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /* nogaim.c */ |
---|
[b7d3cc34] | 114 | void nogaim_init() |
---|
| 115 | { |
---|
[0da65d5] | 116 | extern void msn_initmodule(); |
---|
| 117 | extern void oscar_initmodule(); |
---|
| 118 | extern void byahoo_initmodule(); |
---|
| 119 | extern void jabber_initmodule(); |
---|
[796da03] | 120 | extern void purple_initmodule(); |
---|
[7b23afd] | 121 | |
---|
[b7d3cc34] | 122 | #ifdef WITH_MSN |
---|
[0da65d5] | 123 | msn_initmodule(); |
---|
[b7d3cc34] | 124 | #endif |
---|
| 125 | |
---|
| 126 | #ifdef WITH_OSCAR |
---|
[0da65d5] | 127 | oscar_initmodule(); |
---|
[b7d3cc34] | 128 | #endif |
---|
| 129 | |
---|
| 130 | #ifdef WITH_YAHOO |
---|
[0da65d5] | 131 | byahoo_initmodule(); |
---|
[b7d3cc34] | 132 | #endif |
---|
| 133 | |
---|
| 134 | #ifdef WITH_JABBER |
---|
[0da65d5] | 135 | jabber_initmodule(); |
---|
[b7d3cc34] | 136 | #endif |
---|
[796da03] | 137 | |
---|
| 138 | #ifdef WITH_PURPLE |
---|
| 139 | purple_initmodule(); |
---|
| 140 | #endif |
---|
[7b23afd] | 141 | |
---|
[65e2ce1] | 142 | #ifdef WITH_PLUGINS |
---|
| 143 | load_plugins(); |
---|
[b7d3cc34] | 144 | #endif |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | GSList *get_connections() { return connections; } |
---|
| 148 | |
---|
| 149 | /* multi.c */ |
---|
| 150 | |
---|
[84b045d] | 151 | struct im_connection *imcb_new( account_t *acc ) |
---|
[b7d3cc34] | 152 | { |
---|
[0da65d5] | 153 | struct im_connection *ic; |
---|
[b7d3cc34] | 154 | |
---|
[0da65d5] | 155 | ic = g_new0( struct im_connection, 1 ); |
---|
[b7d3cc34] | 156 | |
---|
[0da65d5] | 157 | ic->irc = acc->irc; |
---|
| 158 | ic->acc = acc; |
---|
| 159 | acc->ic = ic; |
---|
[b7d3cc34] | 160 | |
---|
[0da65d5] | 161 | connections = g_slist_append( connections, ic ); |
---|
[b7d3cc34] | 162 | |
---|
[0da65d5] | 163 | return( ic ); |
---|
[b7d3cc34] | 164 | } |
---|
| 165 | |
---|
[aef4828] | 166 | void imc_free( struct im_connection *ic ) |
---|
[b7d3cc34] | 167 | { |
---|
| 168 | account_t *a; |
---|
| 169 | |
---|
| 170 | /* Destroy the pointer to this connection from the account list */ |
---|
[0da65d5] | 171 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
| 172 | if( a->ic == ic ) |
---|
[b7d3cc34] | 173 | { |
---|
[0da65d5] | 174 | a->ic = NULL; |
---|
[b7d3cc34] | 175 | break; |
---|
| 176 | } |
---|
| 177 | |
---|
[0da65d5] | 178 | connections = g_slist_remove( connections, ic ); |
---|
| 179 | g_free( ic ); |
---|
[b7d3cc34] | 180 | } |
---|
| 181 | |
---|
[aef4828] | 182 | static void serv_got_crap( struct im_connection *ic, char *format, ... ) |
---|
[b7d3cc34] | 183 | { |
---|
| 184 | va_list params; |
---|
[e27661d] | 185 | char *text; |
---|
[dfde8e0] | 186 | account_t *a; |
---|
[b7d3cc34] | 187 | |
---|
| 188 | va_start( params, format ); |
---|
[e27661d] | 189 | text = g_strdup_vprintf( format, params ); |
---|
[b7d3cc34] | 190 | va_end( params ); |
---|
| 191 | |
---|
[0da65d5] | 192 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 193 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[e27661d] | 194 | strip_html( text ); |
---|
[b7d3cc34] | 195 | |
---|
[dfde8e0] | 196 | /* Try to find a different connection on the same protocol. */ |
---|
[0da65d5] | 197 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
| 198 | if( a->prpl == ic->acc->prpl && a->ic != ic ) |
---|
[dfde8e0] | 199 | break; |
---|
| 200 | |
---|
[e27661d] | 201 | /* If we found one, include the screenname in the message. */ |
---|
[dfde8e0] | 202 | if( a ) |
---|
[c2fb3809] | 203 | irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); |
---|
[dfde8e0] | 204 | else |
---|
[0da65d5] | 205 | irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text ); |
---|
[7b07dc6] | 206 | |
---|
[e27661d] | 207 | g_free( text ); |
---|
[b7d3cc34] | 208 | } |
---|
| 209 | |
---|
[84b045d] | 210 | void imcb_log( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 211 | { |
---|
| 212 | va_list params; |
---|
| 213 | char *text; |
---|
| 214 | |
---|
| 215 | va_start( params, format ); |
---|
| 216 | text = g_strdup_vprintf( format, params ); |
---|
| 217 | va_end( params ); |
---|
| 218 | |
---|
| 219 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 220 | serv_got_crap( ic, "%s", text ); |
---|
| 221 | else |
---|
| 222 | serv_got_crap( ic, "Logging in: %s", text ); |
---|
| 223 | |
---|
| 224 | g_free( text ); |
---|
| 225 | } |
---|
| 226 | |
---|
[84b045d] | 227 | void imcb_error( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 228 | { |
---|
| 229 | va_list params; |
---|
| 230 | char *text; |
---|
| 231 | |
---|
| 232 | va_start( params, format ); |
---|
| 233 | text = g_strdup_vprintf( format, params ); |
---|
| 234 | va_end( params ); |
---|
| 235 | |
---|
| 236 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 237 | serv_got_crap( ic, "Error: %s", text ); |
---|
| 238 | else |
---|
| 239 | serv_got_crap( ic, "Couldn't log in: %s", text ); |
---|
| 240 | |
---|
| 241 | g_free( text ); |
---|
| 242 | } |
---|
| 243 | |
---|
[ba9edaa] | 244 | static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 245 | { |
---|
[0da65d5] | 246 | struct im_connection *ic = d; |
---|
[b7d3cc34] | 247 | |
---|
[0da65d5] | 248 | if( ic->acc->prpl->keepalive ) |
---|
| 249 | ic->acc->prpl->keepalive( ic ); |
---|
[b7d3cc34] | 250 | |
---|
| 251 | return TRUE; |
---|
| 252 | } |
---|
| 253 | |
---|
[84b045d] | 254 | void imcb_connected( struct im_connection *ic ) |
---|
[b7d3cc34] | 255 | { |
---|
[3611717] | 256 | irc_t *irc = ic->irc; |
---|
| 257 | struct chat *c; |
---|
[b7d3cc34] | 258 | user_t *u; |
---|
| 259 | |
---|
| 260 | /* MSN servers sometimes redirect you to a different server and do |
---|
[84c1a0a] | 261 | the whole login sequence again, so these "late" calls to this |
---|
[b7d3cc34] | 262 | function should be handled correctly. (IOW, ignored) */ |
---|
[0da65d5] | 263 | if( ic->flags & OPT_LOGGED_IN ) |
---|
[b7d3cc34] | 264 | return; |
---|
| 265 | |
---|
[0da65d5] | 266 | u = user_find( ic->irc, ic->irc->nick ); |
---|
[b7d3cc34] | 267 | |
---|
[84b045d] | 268 | imcb_log( ic, "Logged in" ); |
---|
[b7d3cc34] | 269 | |
---|
[0da65d5] | 270 | ic->keepalive = b_timeout_add( 60000, send_keepalive, ic ); |
---|
| 271 | ic->flags |= OPT_LOGGED_IN; |
---|
[b7d3cc34] | 272 | |
---|
[61dddd0] | 273 | /* Also necessary when we're not away, at least for some of the |
---|
| 274 | protocols. */ |
---|
[84b045d] | 275 | imc_set_away( ic, u->away ); |
---|
[280e655] | 276 | |
---|
| 277 | /* Apparently we're connected successfully, so reset the |
---|
| 278 | exponential backoff timer. */ |
---|
| 279 | ic->acc->auto_reconnect_delay = 0; |
---|
[3611717] | 280 | |
---|
| 281 | for( c = irc->chatrooms; c; c = c->next ) |
---|
| 282 | { |
---|
| 283 | if( c->acc != ic->acc ) |
---|
| 284 | continue; |
---|
| 285 | |
---|
| 286 | if( set_getbool( &c->set, "auto_join" ) ) |
---|
[94acdd0] | 287 | chat_join( irc, c, NULL ); |
---|
[3611717] | 288 | } |
---|
[b7d3cc34] | 289 | } |
---|
| 290 | |
---|
[ba9edaa] | 291 | gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 292 | { |
---|
| 293 | account_t *a = data; |
---|
| 294 | |
---|
| 295 | a->reconnect = 0; |
---|
| 296 | account_on( a->irc, a ); |
---|
| 297 | |
---|
| 298 | return( FALSE ); /* Only have to run the timeout once */ |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | void cancel_auto_reconnect( account_t *a ) |
---|
| 302 | { |
---|
[c98be00] | 303 | b_event_remove( a->reconnect ); |
---|
[b7d3cc34] | 304 | a->reconnect = 0; |
---|
| 305 | } |
---|
| 306 | |
---|
[c2fb3809] | 307 | void imc_logout( struct im_connection *ic, int allow_reconnect ) |
---|
[b7d3cc34] | 308 | { |
---|
[0da65d5] | 309 | irc_t *irc = ic->irc; |
---|
[c9c7ca7] | 310 | user_t *t, *u; |
---|
[b7d3cc34] | 311 | account_t *a; |
---|
[4230221] | 312 | int delay; |
---|
[b7d3cc34] | 313 | |
---|
[8d74291] | 314 | /* Nested calls might happen sometimes, this is probably the best |
---|
| 315 | place to catch them. */ |
---|
[0da65d5] | 316 | if( ic->flags & OPT_LOGGING_OUT ) |
---|
[8d74291] | 317 | return; |
---|
[66f783f] | 318 | else |
---|
[0da65d5] | 319 | ic->flags |= OPT_LOGGING_OUT; |
---|
[8d74291] | 320 | |
---|
[84b045d] | 321 | imcb_log( ic, "Signing off.." ); |
---|
[fb62f81f] | 322 | |
---|
[0da65d5] | 323 | b_event_remove( ic->keepalive ); |
---|
| 324 | ic->keepalive = 0; |
---|
| 325 | ic->acc->prpl->logout( ic ); |
---|
| 326 | b_event_remove( ic->inpa ); |
---|
[b7d3cc34] | 327 | |
---|
[c0c43fb] | 328 | g_free( ic->away ); |
---|
| 329 | ic->away = NULL; |
---|
| 330 | |
---|
[c9c7ca7] | 331 | u = irc->users; |
---|
[b7d3cc34] | 332 | while( u ) |
---|
| 333 | { |
---|
[0da65d5] | 334 | if( u->ic == ic ) |
---|
[b7d3cc34] | 335 | { |
---|
| 336 | t = u->next; |
---|
| 337 | user_del( irc, u->nick ); |
---|
| 338 | u = t; |
---|
| 339 | } |
---|
| 340 | else |
---|
| 341 | u = u->next; |
---|
| 342 | } |
---|
| 343 | |
---|
[0da65d5] | 344 | query_del_by_conn( ic->irc, ic ); |
---|
[b7d3cc34] | 345 | |
---|
| 346 | for( a = irc->accounts; a; a = a->next ) |
---|
[0da65d5] | 347 | if( a->ic == ic ) |
---|
[b7d3cc34] | 348 | break; |
---|
| 349 | |
---|
| 350 | if( !a ) |
---|
| 351 | { |
---|
| 352 | /* Uhm... This is very sick. */ |
---|
| 353 | } |
---|
[c2fb3809] | 354 | else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && |
---|
[4230221] | 355 | set_getbool( &a->set, "auto_reconnect" ) && |
---|
| 356 | ( delay = account_reconnect_delay( a ) ) > 0 ) |
---|
[b7d3cc34] | 357 | { |
---|
[84b045d] | 358 | imcb_log( ic, "Reconnecting in %d seconds..", delay ); |
---|
[c98be00] | 359 | a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a ); |
---|
[b7d3cc34] | 360 | } |
---|
| 361 | |
---|
[aef4828] | 362 | imc_free( ic ); |
---|
[b7d3cc34] | 363 | } |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | /* dialogs.c */ |
---|
| 367 | |
---|
[9143aeb] | 368 | void imcb_ask( struct im_connection *ic, char *msg, void *data, |
---|
| 369 | query_callback doit, query_callback dont ) |
---|
[b7d3cc34] | 370 | { |
---|
[0da65d5] | 371 | query_add( ic->irc, ic, msg, doit, dont, data ); |
---|
[b7d3cc34] | 372 | } |
---|
| 373 | |
---|
| 374 | |
---|
| 375 | /* list.c */ |
---|
| 376 | |
---|
[f0cb961] | 377 | void imcb_add_buddy( struct im_connection *ic, char *handle, char *group ) |
---|
[b7d3cc34] | 378 | { |
---|
| 379 | user_t *u; |
---|
[f0cb961] | 380 | char nick[MAX_NICK_LENGTH+1], *s; |
---|
[0da65d5] | 381 | irc_t *irc = ic->irc; |
---|
[b7d3cc34] | 382 | |
---|
[0da65d5] | 383 | if( user_findhandle( ic, handle ) ) |
---|
[b7d3cc34] | 384 | { |
---|
[d5ccd83] | 385 | if( set_getbool( &irc->set, "debug" ) ) |
---|
[84b045d] | 386 | imcb_log( ic, "User already exists, ignoring add request: %s", handle ); |
---|
[b7d3cc34] | 387 | |
---|
| 388 | return; |
---|
| 389 | |
---|
[f0cb961] | 390 | /* Buddy seems to exist already. Let's ignore this request then... |
---|
| 391 | Eventually subsequent calls to this function *should* be possible |
---|
| 392 | when a buddy is in multiple groups. But for now BitlBee doesn't |
---|
| 393 | even support groups so let's silently ignore this for now. */ |
---|
[b7d3cc34] | 394 | } |
---|
| 395 | |
---|
| 396 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
[d323394c] | 397 | strcpy( nick, nick_get( ic->acc, handle ) ); |
---|
[b7d3cc34] | 398 | |
---|
[0da65d5] | 399 | u = user_add( ic->irc, nick ); |
---|
[b7d3cc34] | 400 | |
---|
[f0cb961] | 401 | // if( !realname || !*realname ) realname = nick; |
---|
| 402 | // u->realname = g_strdup( realname ); |
---|
[b7d3cc34] | 403 | |
---|
| 404 | if( ( s = strchr( handle, '@' ) ) ) |
---|
| 405 | { |
---|
| 406 | u->host = g_strdup( s + 1 ); |
---|
| 407 | u->user = g_strndup( handle, s - handle ); |
---|
| 408 | } |
---|
[0da65d5] | 409 | else if( ic->acc->server ) |
---|
[b7d3cc34] | 410 | { |
---|
[f0cb961] | 411 | u->host = g_strdup( ic->acc->server ); |
---|
[b7d3cc34] | 412 | u->user = g_strdup( handle ); |
---|
| 413 | |
---|
| 414 | /* s/ /_/ ... important for AOL screennames */ |
---|
| 415 | for( s = u->user; *s; s ++ ) |
---|
| 416 | if( *s == ' ' ) |
---|
| 417 | *s = '_'; |
---|
| 418 | } |
---|
| 419 | else |
---|
| 420 | { |
---|
[0da65d5] | 421 | u->host = g_strdup( ic->acc->prpl->name ); |
---|
[b7d3cc34] | 422 | u->user = g_strdup( handle ); |
---|
| 423 | } |
---|
| 424 | |
---|
[0da65d5] | 425 | u->ic = ic; |
---|
[b7d3cc34] | 426 | u->handle = g_strdup( handle ); |
---|
[9b8a38b] | 427 | if( group ) u->group = g_strdup( group ); |
---|
[b7d3cc34] | 428 | u->send_handler = buddy_send_handler; |
---|
| 429 | u->last_typing_notice = 0; |
---|
| 430 | } |
---|
| 431 | |
---|
[f0cb961] | 432 | struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle ) |
---|
[b7d3cc34] | 433 | { |
---|
| 434 | static struct buddy b[1]; |
---|
| 435 | user_t *u; |
---|
| 436 | |
---|
[0da65d5] | 437 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 438 | |
---|
| 439 | if( !u ) |
---|
| 440 | return( NULL ); |
---|
[9624fdf] | 441 | |
---|
[b7d3cc34] | 442 | memset( b, 0, sizeof( b ) ); |
---|
| 443 | strncpy( b->name, handle, 80 ); |
---|
| 444 | strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN ); |
---|
| 445 | b->present = u->online; |
---|
[0da65d5] | 446 | b->ic = u->ic; |
---|
[b7d3cc34] | 447 | |
---|
| 448 | return( b ); |
---|
| 449 | } |
---|
| 450 | |
---|
[f0cb961] | 451 | void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname ) |
---|
[b7d3cc34] | 452 | { |
---|
[0da65d5] | 453 | user_t *u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 454 | |
---|
[f0cb961] | 455 | if( !u || !realname ) return; |
---|
[b7d3cc34] | 456 | |
---|
[e27661d] | 457 | if( g_strcasecmp( u->realname, realname ) != 0 ) |
---|
[b7d3cc34] | 458 | { |
---|
| 459 | if( u->realname != u->nick ) g_free( u->realname ); |
---|
| 460 | |
---|
[e27661d] | 461 | u->realname = g_strdup( realname ); |
---|
[b7d3cc34] | 462 | |
---|
[0da65d5] | 463 | if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) ) |
---|
[84b045d] | 464 | imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); |
---|
[b7d3cc34] | 465 | } |
---|
| 466 | } |
---|
| 467 | |
---|
[998b103] | 468 | void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group ) |
---|
| 469 | { |
---|
| 470 | user_t *u; |
---|
| 471 | |
---|
| 472 | if( ( u = user_findhandle( ic, handle ) ) ) |
---|
| 473 | user_del( ic->irc, u->nick ); |
---|
| 474 | } |
---|
| 475 | |
---|
[d06eabf] | 476 | /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM |
---|
| 477 | modules to suggest a nickname for a handle. */ |
---|
| 478 | void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick ) |
---|
| 479 | { |
---|
| 480 | user_t *u = user_findhandle( ic, handle ); |
---|
[43d8cc5] | 481 | char newnick[MAX_NICK_LENGTH+1], *orig_nick; |
---|
[d06eabf] | 482 | |
---|
[e0e2a71] | 483 | if( u && !u->online && !nick_saved( ic->acc, handle ) ) |
---|
[d06eabf] | 484 | { |
---|
| 485 | /* Only do this if the person isn't online yet (which should |
---|
| 486 | be the case if we just added it) and if the user hasn't |
---|
| 487 | assigned a nickname to this buddy already. */ |
---|
| 488 | |
---|
[e0e2a71] | 489 | strncpy( newnick, nick, MAX_NICK_LENGTH ); |
---|
| 490 | newnick[MAX_NICK_LENGTH] = 0; |
---|
[d06eabf] | 491 | |
---|
| 492 | /* Some processing to make sure this string is a valid IRC nickname. */ |
---|
| 493 | nick_strip( newnick ); |
---|
| 494 | if( set_getbool( &ic->irc->set, "lcnicks" ) ) |
---|
| 495 | nick_lc( newnick ); |
---|
| 496 | |
---|
[1962ac1] | 497 | if( strcmp( u->nick, newnick ) != 0 ) |
---|
| 498 | { |
---|
| 499 | /* Only do this if newnick is different from the current one. |
---|
| 500 | If rejoining a channel, maybe we got this nick already |
---|
| 501 | (and dedupe would only add an underscore. */ |
---|
| 502 | nick_dedupe( ic->acc, handle, newnick ); |
---|
| 503 | |
---|
| 504 | /* u->nick will be freed halfway the process, so it can't be |
---|
| 505 | passed as an argument. */ |
---|
| 506 | orig_nick = g_strdup( u->nick ); |
---|
| 507 | user_rename( ic->irc, orig_nick, newnick ); |
---|
| 508 | g_free( orig_nick ); |
---|
| 509 | } |
---|
[d06eabf] | 510 | } |
---|
| 511 | } |
---|
[b7d3cc34] | 512 | |
---|
| 513 | /* prpl.c */ |
---|
| 514 | |
---|
[7bf0f5f0] | 515 | struct show_got_added_data |
---|
| 516 | { |
---|
[0da65d5] | 517 | struct im_connection *ic; |
---|
[7bf0f5f0] | 518 | char *handle; |
---|
| 519 | }; |
---|
| 520 | |
---|
[9143aeb] | 521 | void show_got_added_no( void *data ) |
---|
[7bf0f5f0] | 522 | { |
---|
[9143aeb] | 523 | g_free( ((struct show_got_added_data*)data)->handle ); |
---|
[7bf0f5f0] | 524 | g_free( data ); |
---|
| 525 | } |
---|
| 526 | |
---|
[9143aeb] | 527 | void show_got_added_yes( void *data ) |
---|
[7bf0f5f0] | 528 | { |
---|
[9143aeb] | 529 | struct show_got_added_data *sga = data; |
---|
[7bf0f5f0] | 530 | |
---|
[9143aeb] | 531 | sga->ic->acc->prpl->add_buddy( sga->ic, sga->handle, NULL ); |
---|
| 532 | /* imcb_add_buddy( sga->ic, NULL, sga->handle, sga->handle ); */ |
---|
| 533 | |
---|
| 534 | return show_got_added_no( data ); |
---|
[7bf0f5f0] | 535 | } |
---|
| 536 | |
---|
[84b045d] | 537 | void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname ) |
---|
[b7d3cc34] | 538 | { |
---|
[7bf0f5f0] | 539 | struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); |
---|
| 540 | char *s; |
---|
| 541 | |
---|
| 542 | /* TODO: Make a setting for this! */ |
---|
[0da65d5] | 543 | if( user_findhandle( ic, handle ) != NULL ) |
---|
[7bf0f5f0] | 544 | return; |
---|
| 545 | |
---|
| 546 | s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); |
---|
| 547 | |
---|
[0da65d5] | 548 | data->ic = ic; |
---|
[7bf0f5f0] | 549 | data->handle = g_strdup( handle ); |
---|
[0da65d5] | 550 | query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data ); |
---|
[b7d3cc34] | 551 | } |
---|
| 552 | |
---|
| 553 | |
---|
| 554 | /* server.c */ |
---|
| 555 | |
---|
[6bbb939] | 556 | void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ) |
---|
[b7d3cc34] | 557 | { |
---|
| 558 | user_t *u; |
---|
| 559 | int oa, oo; |
---|
| 560 | |
---|
[6bbb939] | 561 | u = user_findhandle( ic, (char*) handle ); |
---|
[b7d3cc34] | 562 | |
---|
| 563 | if( !u ) |
---|
| 564 | { |
---|
[0da65d5] | 565 | if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 ) |
---|
[b7d3cc34] | 566 | { |
---|
[f0cb961] | 567 | imcb_add_buddy( ic, (char*) handle, NULL ); |
---|
[6bbb939] | 568 | u = user_findhandle( ic, (char*) handle ); |
---|
[b7d3cc34] | 569 | } |
---|
| 570 | else |
---|
| 571 | { |
---|
[0da65d5] | 572 | if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 ) |
---|
[b7d3cc34] | 573 | { |
---|
[6bbb939] | 574 | imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle ); |
---|
| 575 | imcb_log( ic, "flags = %d, state = %s, message = %s", flags, |
---|
| 576 | state ? state : "NULL", message ? message : "NULL" ); |
---|
[b7d3cc34] | 577 | } |
---|
| 578 | |
---|
| 579 | return; |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | oa = u->away != NULL; |
---|
| 584 | oo = u->online; |
---|
| 585 | |
---|
| 586 | if( u->away ) |
---|
| 587 | { |
---|
| 588 | g_free( u->away ); |
---|
| 589 | u->away = NULL; |
---|
| 590 | } |
---|
| 591 | |
---|
[6bbb939] | 592 | if( ( flags & OPT_LOGGED_IN ) && !u->online ) |
---|
[b7d3cc34] | 593 | { |
---|
[0da65d5] | 594 | irc_spawn( ic->irc, u ); |
---|
[b7d3cc34] | 595 | u->online = 1; |
---|
| 596 | } |
---|
[6bbb939] | 597 | else if( !( flags & OPT_LOGGED_IN ) && u->online ) |
---|
[b7d3cc34] | 598 | { |
---|
[0da65d5] | 599 | struct groupchat *c; |
---|
[b7d3cc34] | 600 | |
---|
[0da65d5] | 601 | irc_kill( ic->irc, u ); |
---|
[b7d3cc34] | 602 | u->online = 0; |
---|
| 603 | |
---|
[e35d1a1] | 604 | /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ |
---|
| 605 | for( c = ic->groupchats; c; c = c->next ) |
---|
[764b163d] | 606 | remove_chat_buddy_silent( c, handle ); |
---|
[b7d3cc34] | 607 | } |
---|
| 608 | |
---|
[6bbb939] | 609 | if( flags & OPT_AWAY ) |
---|
[b7d3cc34] | 610 | { |
---|
[6bbb939] | 611 | if( state && message ) |
---|
| 612 | { |
---|
| 613 | u->away = g_strdup_printf( "%s (%s)", state, message ); |
---|
| 614 | } |
---|
| 615 | else if( state ) |
---|
| 616 | { |
---|
| 617 | u->away = g_strdup( state ); |
---|
| 618 | } |
---|
| 619 | else if( message ) |
---|
| 620 | { |
---|
| 621 | u->away = g_strdup( message ); |
---|
| 622 | } |
---|
| 623 | else |
---|
| 624 | { |
---|
| 625 | u->away = g_strdup( "Away" ); |
---|
| 626 | } |
---|
[b7d3cc34] | 627 | } |
---|
[6bbb939] | 628 | /* else waste_any_state_information_for_now(); */ |
---|
[b7d3cc34] | 629 | |
---|
| 630 | /* LISPy... */ |
---|
[0da65d5] | 631 | if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ |
---|
[b7d3cc34] | 632 | ( u->online ) && /* Don't touch offline people */ |
---|
| 633 | ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ |
---|
| 634 | ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ |
---|
| 635 | { |
---|
[1186382] | 636 | char *from; |
---|
| 637 | |
---|
| 638 | if( set_getbool( &ic->irc->set, "simulate_netsplit" ) ) |
---|
| 639 | { |
---|
| 640 | from = g_strdup( ic->irc->myhost ); |
---|
| 641 | } |
---|
| 642 | else |
---|
| 643 | { |
---|
| 644 | from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick, |
---|
| 645 | ic->irc->myhost ); |
---|
| 646 | } |
---|
| 647 | irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, |
---|
| 648 | u->away?'-':'+', u->nick ); |
---|
| 649 | g_free( from ); |
---|
[b7d3cc34] | 650 | } |
---|
| 651 | } |
---|
| 652 | |
---|
[52744f8] | 653 | void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at ) |
---|
[b7d3cc34] | 654 | { |
---|
[0da65d5] | 655 | irc_t *irc = ic->irc; |
---|
[d444c09] | 656 | char *wrapped; |
---|
[b7d3cc34] | 657 | user_t *u; |
---|
| 658 | |
---|
[0da65d5] | 659 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 660 | |
---|
| 661 | if( !u ) |
---|
| 662 | { |
---|
[5c9512f] | 663 | char *h = set_getstr( &irc->set, "handle_unknown" ); |
---|
[b7d3cc34] | 664 | |
---|
| 665 | if( g_strcasecmp( h, "ignore" ) == 0 ) |
---|
| 666 | { |
---|
[d5ccd83] | 667 | if( set_getbool( &irc->set, "debug" ) ) |
---|
[84b045d] | 668 | imcb_log( ic, "Ignoring message from unknown handle %s", handle ); |
---|
[b7d3cc34] | 669 | |
---|
| 670 | return; |
---|
| 671 | } |
---|
| 672 | else if( g_strncasecmp( h, "add", 3 ) == 0 ) |
---|
| 673 | { |
---|
[d5ccd83] | 674 | int private = set_getbool( &irc->set, "private" ); |
---|
[b7d3cc34] | 675 | |
---|
| 676 | if( h[3] ) |
---|
| 677 | { |
---|
| 678 | if( g_strcasecmp( h + 3, "_private" ) == 0 ) |
---|
| 679 | private = 1; |
---|
| 680 | else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) |
---|
| 681 | private = 0; |
---|
| 682 | } |
---|
| 683 | |
---|
[f0cb961] | 684 | imcb_add_buddy( ic, handle, NULL ); |
---|
[0da65d5] | 685 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 686 | u->is_private = private; |
---|
| 687 | } |
---|
| 688 | else |
---|
| 689 | { |
---|
[84b045d] | 690 | imcb_log( ic, "Message from unknown handle %s:", handle ); |
---|
[b7d3cc34] | 691 | u = user_find( irc, irc->mynick ); |
---|
| 692 | } |
---|
| 693 | } |
---|
| 694 | |
---|
[0da65d5] | 695 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 696 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[b7d3cc34] | 697 | strip_html( msg ); |
---|
| 698 | |
---|
[d444c09] | 699 | wrapped = word_wrap( msg, 425 ); |
---|
| 700 | irc_msgfrom( irc, u->nick, wrapped ); |
---|
| 701 | g_free( wrapped ); |
---|
[b7d3cc34] | 702 | } |
---|
| 703 | |
---|
[52744f8] | 704 | void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags ) |
---|
[b7d3cc34] | 705 | { |
---|
| 706 | user_t *u; |
---|
| 707 | |
---|
[0da65d5] | 708 | if( !set_getbool( &ic->irc->set, "typing_notice" ) ) |
---|
[b7d3cc34] | 709 | return; |
---|
| 710 | |
---|
[9624fdf] | 711 | if( ( u = user_findhandle( ic, handle ) ) ) |
---|
| 712 | { |
---|
| 713 | char buf[256]; |
---|
| 714 | |
---|
| 715 | g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 ); |
---|
| 716 | irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf ); |
---|
[e7f46c5] | 717 | } |
---|
[b7d3cc34] | 718 | } |
---|
| 719 | |
---|
[94acdd0] | 720 | struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle ) |
---|
[83ba3e5] | 721 | { |
---|
| 722 | struct groupchat *c; |
---|
| 723 | |
---|
| 724 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
| 725 | |
---|
| 726 | if( ic->groupchats ) |
---|
| 727 | { |
---|
| 728 | for( c = ic->groupchats; c->next; c = c->next ); |
---|
| 729 | c = c->next = g_new0( struct groupchat, 1 ); |
---|
| 730 | } |
---|
| 731 | else |
---|
| 732 | ic->groupchats = c = g_new0( struct groupchat, 1 ); |
---|
| 733 | |
---|
| 734 | c->ic = ic; |
---|
| 735 | c->title = g_strdup( handle ); |
---|
| 736 | c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ ); |
---|
| 737 | c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
| 738 | |
---|
| 739 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
| 740 | imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle ); |
---|
| 741 | |
---|
| 742 | return c; |
---|
| 743 | } |
---|
| 744 | |
---|
[e35d1a1] | 745 | void imcb_chat_free( struct groupchat *c ) |
---|
[b7d3cc34] | 746 | { |
---|
[0da65d5] | 747 | struct im_connection *ic = c->ic; |
---|
[e35d1a1] | 748 | struct groupchat *l; |
---|
[b7d3cc34] | 749 | GList *ir; |
---|
| 750 | |
---|
[0da65d5] | 751 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
[56f260a] | 752 | imcb_log( ic, "You were removed from conversation %p", c ); |
---|
[b7d3cc34] | 753 | |
---|
| 754 | if( c ) |
---|
| 755 | { |
---|
| 756 | if( c->joined ) |
---|
| 757 | { |
---|
| 758 | user_t *u, *r; |
---|
| 759 | |
---|
[0da65d5] | 760 | r = user_find( ic->irc, ic->irc->mynick ); |
---|
| 761 | irc_privmsg( ic->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
[b7d3cc34] | 762 | |
---|
[0da65d5] | 763 | u = user_find( ic->irc, ic->irc->nick ); |
---|
| 764 | irc_kick( ic->irc, u, c->channel, r ); |
---|
| 765 | /* irc_part( ic->irc, u, c->channel ); */ |
---|
[b7d3cc34] | 766 | } |
---|
| 767 | |
---|
[e35d1a1] | 768 | /* Find the previous chat in the linked list. */ |
---|
| 769 | for( l = ic->groupchats; l && l->next != c; l = l->next ); |
---|
| 770 | |
---|
[b7d3cc34] | 771 | if( l ) |
---|
| 772 | l->next = c->next; |
---|
| 773 | else |
---|
[e35d1a1] | 774 | ic->groupchats = c->next; |
---|
[b7d3cc34] | 775 | |
---|
| 776 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
| 777 | g_free( ir->data ); |
---|
| 778 | g_list_free( c->in_room ); |
---|
| 779 | g_free( c->channel ); |
---|
| 780 | g_free( c->title ); |
---|
[83ba3e5] | 781 | g_free( c->topic ); |
---|
[b7d3cc34] | 782 | g_free( c ); |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | |
---|
[52744f8] | 786 | void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at ) |
---|
[b7d3cc34] | 787 | { |
---|
[0da65d5] | 788 | struct im_connection *ic = c->ic; |
---|
[d444c09] | 789 | char *wrapped; |
---|
[b7d3cc34] | 790 | user_t *u; |
---|
| 791 | |
---|
| 792 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
[c2fb3809] | 793 | if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 794 | return; |
---|
| 795 | |
---|
[0da65d5] | 796 | u = user_findhandle( ic, who ); |
---|
[b7d3cc34] | 797 | |
---|
[0da65d5] | 798 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 799 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[b7d3cc34] | 800 | strip_html( msg ); |
---|
| 801 | |
---|
[d444c09] | 802 | wrapped = word_wrap( msg, 425 ); |
---|
[b7d3cc34] | 803 | if( c && u ) |
---|
[d444c09] | 804 | { |
---|
| 805 | irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped ); |
---|
| 806 | } |
---|
[b7d3cc34] | 807 | else |
---|
[d444c09] | 808 | { |
---|
[56f260a] | 809 | imcb_log( ic, "Message from/to conversation %s@%p (unknown conv/user): %s", who, c, wrapped ); |
---|
[d444c09] | 810 | } |
---|
| 811 | g_free( wrapped ); |
---|
[b7d3cc34] | 812 | } |
---|
| 813 | |
---|
[31e5846] | 814 | void imcb_chat_log( struct groupchat *c, char *format, ... ) |
---|
| 815 | { |
---|
| 816 | irc_t *irc = c->ic->irc; |
---|
| 817 | va_list params; |
---|
| 818 | char *text; |
---|
| 819 | user_t *u; |
---|
| 820 | |
---|
| 821 | va_start( params, format ); |
---|
| 822 | text = g_strdup_vprintf( format, params ); |
---|
| 823 | va_end( params ); |
---|
| 824 | |
---|
| 825 | u = user_find( irc, irc->mynick ); |
---|
| 826 | |
---|
| 827 | irc_privmsg( irc, u, "PRIVMSG", c->channel, "System message: ", text ); |
---|
| 828 | |
---|
| 829 | g_free( text ); |
---|
| 830 | } |
---|
| 831 | |
---|
[ef5c185] | 832 | void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at ) |
---|
[50e1776] | 833 | { |
---|
| 834 | struct im_connection *ic = c->ic; |
---|
| 835 | user_t *u = NULL; |
---|
| 836 | |
---|
| 837 | if( who == NULL) |
---|
[ef5c185] | 838 | u = user_find( ic->irc, ic->irc->mynick ); |
---|
[50e1776] | 839 | else if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
[ef5c185] | 840 | u = user_find( ic->irc, ic->irc->nick ); |
---|
[50e1776] | 841 | else |
---|
| 842 | u = user_findhandle( ic, who ); |
---|
| 843 | |
---|
| 844 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
| 845 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
| 846 | strip_html( topic ); |
---|
| 847 | |
---|
| 848 | g_free( c->topic ); |
---|
| 849 | c->topic = g_strdup( topic ); |
---|
| 850 | |
---|
| 851 | if( c->joined && u ) |
---|
| 852 | irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic ); |
---|
| 853 | } |
---|
| 854 | |
---|
[b7d3cc34] | 855 | |
---|
| 856 | /* buddy_chat.c */ |
---|
| 857 | |
---|
[61ae52c] | 858 | void imcb_chat_add_buddy( struct groupchat *b, char *handle ) |
---|
[b7d3cc34] | 859 | { |
---|
[0da65d5] | 860 | user_t *u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 861 | int me = 0; |
---|
| 862 | |
---|
[0da65d5] | 863 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
[56f260a] | 864 | imcb_log( b->ic, "User %s added to conversation %p", handle, b ); |
---|
[b7d3cc34] | 865 | |
---|
| 866 | /* It might be yourself! */ |
---|
[c2fb3809] | 867 | if( b->ic->acc->prpl->handle_cmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 868 | { |
---|
[0da65d5] | 869 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 870 | if( !b->joined ) |
---|
[0da65d5] | 871 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 872 | b->joined = me = 1; |
---|
| 873 | } |
---|
| 874 | |
---|
| 875 | /* Most protocols allow people to join, even when they're not in |
---|
| 876 | your contact list. Try to handle that here */ |
---|
| 877 | if( !u ) |
---|
| 878 | { |
---|
[f0cb961] | 879 | imcb_add_buddy( b->ic, handle, NULL ); |
---|
[0da65d5] | 880 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 881 | } |
---|
| 882 | |
---|
| 883 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
| 884 | if( !me ) |
---|
| 885 | { |
---|
| 886 | if( b->joined ) |
---|
[0da65d5] | 887 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 888 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
| 889 | } |
---|
| 890 | } |
---|
| 891 | |
---|
[2d317bb] | 892 | /* This function is one BIG hack... :-( EREWRITE */ |
---|
[61ae52c] | 893 | void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason ) |
---|
[b7d3cc34] | 894 | { |
---|
| 895 | user_t *u; |
---|
| 896 | int me = 0; |
---|
| 897 | |
---|
[0da65d5] | 898 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
[56f260a] | 899 | imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" ); |
---|
[b7d3cc34] | 900 | |
---|
| 901 | /* It might be yourself! */ |
---|
[c2fb3809] | 902 | if( g_strcasecmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 903 | { |
---|
[2d317bb] | 904 | if( b->joined == 0 ) |
---|
| 905 | return; |
---|
| 906 | |
---|
[0da65d5] | 907 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 908 | b->joined = 0; |
---|
| 909 | me = 1; |
---|
| 910 | } |
---|
| 911 | else |
---|
| 912 | { |
---|
[0da65d5] | 913 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 914 | } |
---|
| 915 | |
---|
[2d317bb] | 916 | if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) ) |
---|
| 917 | irc_part( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 918 | } |
---|
| 919 | |
---|
[764b163d] | 920 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ) |
---|
[b7d3cc34] | 921 | { |
---|
| 922 | GList *i; |
---|
| 923 | |
---|
| 924 | /* Find the handle in the room userlist and shoot it */ |
---|
| 925 | i = b->in_room; |
---|
| 926 | while( i ) |
---|
| 927 | { |
---|
| 928 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
| 929 | { |
---|
| 930 | g_free( i->data ); |
---|
| 931 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
| 932 | return( 1 ); |
---|
| 933 | } |
---|
| 934 | |
---|
| 935 | i = i->next; |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | return( 0 ); |
---|
| 939 | } |
---|
| 940 | |
---|
| 941 | |
---|
| 942 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
| 943 | |
---|
[5c9512f] | 944 | char *set_eval_away_devoice( set_t *set, char *value ) |
---|
[b7d3cc34] | 945 | { |
---|
[5c9512f] | 946 | irc_t *irc = set->data; |
---|
[b7d3cc34] | 947 | int st; |
---|
| 948 | |
---|
[7125cb3] | 949 | if( !is_bool( value ) ) |
---|
| 950 | return SET_INVALID; |
---|
[b7d3cc34] | 951 | |
---|
[7125cb3] | 952 | st = bool2int( value ); |
---|
[b7d3cc34] | 953 | |
---|
| 954 | /* Horror.... */ |
---|
| 955 | |
---|
[d5ccd83] | 956 | if( st != set_getbool( &irc->set, "away_devoice" ) ) |
---|
[b7d3cc34] | 957 | { |
---|
| 958 | char list[80] = ""; |
---|
| 959 | user_t *u = irc->users; |
---|
| 960 | int i = 0, count = 0; |
---|
| 961 | char pm; |
---|
| 962 | char v[80]; |
---|
| 963 | |
---|
| 964 | if( st ) |
---|
| 965 | pm = '+'; |
---|
| 966 | else |
---|
| 967 | pm = '-'; |
---|
| 968 | |
---|
| 969 | while( u ) |
---|
| 970 | { |
---|
[0da65d5] | 971 | if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 972 | { |
---|
| 973 | if( ( strlen( list ) + strlen( u->nick ) ) >= 79 ) |
---|
| 974 | { |
---|
| 975 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 976 | irc_write( irc, ":%s MODE %s %c%s%s", |
---|
| 977 | irc->myhost, |
---|
[b7d3cc34] | 978 | irc->channel, pm, v, list ); |
---|
| 979 | |
---|
| 980 | *list = 0; |
---|
| 981 | count = 0; |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | sprintf( list + strlen( list ), " %s", u->nick ); |
---|
| 985 | count ++; |
---|
| 986 | } |
---|
| 987 | u = u->next; |
---|
| 988 | } |
---|
| 989 | |
---|
| 990 | /* $v = 'v' x $i */ |
---|
| 991 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 992 | irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost, |
---|
[b7d3cc34] | 993 | irc->channel, pm, v, list ); |
---|
| 994 | } |
---|
| 995 | |
---|
[7125cb3] | 996 | return value; |
---|
[b7d3cc34] | 997 | } |
---|
| 998 | |
---|
[226fce1] | 999 | |
---|
| 1000 | |
---|
| 1001 | |
---|
| 1002 | /* The plan is to not allow straight calls to prpl functions anymore, but do |
---|
| 1003 | them all from some wrappers. We'll start to define some down here: */ |
---|
| 1004 | |
---|
[84b045d] | 1005 | int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags ) |
---|
[b7d3cc34] | 1006 | { |
---|
[e27661d] | 1007 | char *buf = NULL; |
---|
| 1008 | int st; |
---|
[b7d3cc34] | 1009 | |
---|
[6bbb939] | 1010 | if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[c572dd6] | 1011 | { |
---|
[e27661d] | 1012 | buf = escape_html( msg ); |
---|
[c572dd6] | 1013 | msg = buf; |
---|
[b7d3cc34] | 1014 | } |
---|
| 1015 | |
---|
[f6c963b] | 1016 | st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags ); |
---|
[e27661d] | 1017 | g_free( buf ); |
---|
| 1018 | |
---|
| 1019 | return st; |
---|
[b7d3cc34] | 1020 | } |
---|
| 1021 | |
---|
[84b045d] | 1022 | int imc_chat_msg( struct groupchat *c, char *msg, int flags ) |
---|
[b7d3cc34] | 1023 | { |
---|
[e27661d] | 1024 | char *buf = NULL; |
---|
[b7d3cc34] | 1025 | |
---|
[6bbb939] | 1026 | if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[e27661d] | 1027 | { |
---|
| 1028 | buf = escape_html( msg ); |
---|
[b7d3cc34] | 1029 | msg = buf; |
---|
| 1030 | } |
---|
| 1031 | |
---|
[f6c963b] | 1032 | c->ic->acc->prpl->chat_msg( c, msg, flags ); |
---|
[e27661d] | 1033 | g_free( buf ); |
---|
| 1034 | |
---|
[0da65d5] | 1035 | return 1; |
---|
[b7d3cc34] | 1036 | } |
---|
[226fce1] | 1037 | |
---|
[84b045d] | 1038 | static char *imc_away_alias_find( GList *gcm, char *away ); |
---|
[226fce1] | 1039 | |
---|
[84b045d] | 1040 | int imc_set_away( struct im_connection *ic, char *away ) |
---|
[226fce1] | 1041 | { |
---|
| 1042 | GList *m, *ms; |
---|
| 1043 | char *s; |
---|
| 1044 | |
---|
| 1045 | if( !away ) away = ""; |
---|
[0da65d5] | 1046 | ms = m = ic->acc->prpl->away_states( ic ); |
---|
[226fce1] | 1047 | |
---|
| 1048 | while( m ) |
---|
| 1049 | { |
---|
| 1050 | if( *away ) |
---|
| 1051 | { |
---|
| 1052 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
| 1053 | break; |
---|
| 1054 | } |
---|
| 1055 | else |
---|
| 1056 | { |
---|
| 1057 | if( g_strcasecmp( m->data, "Available" ) == 0 ) |
---|
| 1058 | break; |
---|
| 1059 | if( g_strcasecmp( m->data, "Online" ) == 0 ) |
---|
| 1060 | break; |
---|
| 1061 | } |
---|
| 1062 | m = m->next; |
---|
| 1063 | } |
---|
| 1064 | |
---|
| 1065 | if( m ) |
---|
| 1066 | { |
---|
[0da65d5] | 1067 | ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL ); |
---|
[226fce1] | 1068 | } |
---|
| 1069 | else |
---|
| 1070 | { |
---|
[84b045d] | 1071 | s = imc_away_alias_find( ms, away ); |
---|
[226fce1] | 1072 | if( s ) |
---|
| 1073 | { |
---|
[0da65d5] | 1074 | ic->acc->prpl->set_away( ic, s, away ); |
---|
| 1075 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
[84b045d] | 1076 | imcb_log( ic, "Setting away state to %s", s ); |
---|
[226fce1] | 1077 | } |
---|
| 1078 | else |
---|
[0da65d5] | 1079 | ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away ); |
---|
[226fce1] | 1080 | } |
---|
| 1081 | |
---|
| 1082 | return( 1 ); |
---|
| 1083 | } |
---|
| 1084 | |
---|
[84b045d] | 1085 | static char *imc_away_alias_list[8][5] = |
---|
[226fce1] | 1086 | { |
---|
| 1087 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
| 1088 | { "NA", "N/A", "Not available", NULL }, |
---|
| 1089 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
| 1090 | { "Be right back", "BRB", NULL }, |
---|
| 1091 | { "On the phone", "Phone", "On phone", NULL }, |
---|
| 1092 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
| 1093 | { "Invisible", "Hidden" }, |
---|
| 1094 | { NULL } |
---|
| 1095 | }; |
---|
| 1096 | |
---|
[84b045d] | 1097 | static char *imc_away_alias_find( GList *gcm, char *away ) |
---|
[226fce1] | 1098 | { |
---|
| 1099 | GList *m; |
---|
| 1100 | int i, j; |
---|
| 1101 | |
---|
[84b045d] | 1102 | for( i = 0; *imc_away_alias_list[i]; i ++ ) |
---|
[226fce1] | 1103 | { |
---|
[84b045d] | 1104 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
| 1105 | if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) |
---|
[226fce1] | 1106 | break; |
---|
| 1107 | |
---|
[84b045d] | 1108 | if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ |
---|
[226fce1] | 1109 | continue; /* is not what we want. Next! */ |
---|
| 1110 | |
---|
| 1111 | /* Now find an entry in this row which exists in gcm */ |
---|
[84b045d] | 1112 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
[226fce1] | 1113 | { |
---|
| 1114 | m = gcm; |
---|
| 1115 | while( m ) |
---|
| 1116 | { |
---|
[84b045d] | 1117 | if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) |
---|
| 1118 | return( imc_away_alias_list[i][j] ); |
---|
[226fce1] | 1119 | m = m->next; |
---|
| 1120 | } |
---|
| 1121 | } |
---|
| 1122 | } |
---|
| 1123 | |
---|
| 1124 | return( NULL ); |
---|
| 1125 | } |
---|
[da3b536] | 1126 | |
---|
[84b045d] | 1127 | void imc_add_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1128 | { |
---|
[0da65d5] | 1129 | if( g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 1130 | { |
---|
[0da65d5] | 1131 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
[da3b536] | 1132 | } |
---|
| 1133 | |
---|
[0da65d5] | 1134 | ic->acc->prpl->add_permit( ic, handle ); |
---|
[da3b536] | 1135 | } |
---|
| 1136 | |
---|
[84b045d] | 1137 | void imc_rem_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1138 | { |
---|
| 1139 | GSList *l; |
---|
| 1140 | |
---|
[0da65d5] | 1141 | if( ( l = g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 1142 | { |
---|
| 1143 | g_free( l->data ); |
---|
[0da65d5] | 1144 | ic->permit = g_slist_delete_link( ic->permit, l ); |
---|
[da3b536] | 1145 | } |
---|
| 1146 | |
---|
[0da65d5] | 1147 | ic->acc->prpl->rem_permit( ic, handle ); |
---|
[da3b536] | 1148 | } |
---|
| 1149 | |
---|
[84b045d] | 1150 | void imc_add_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1151 | { |
---|
[0da65d5] | 1152 | if( g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 1153 | { |
---|
[0da65d5] | 1154 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
[da3b536] | 1155 | } |
---|
| 1156 | |
---|
[0da65d5] | 1157 | ic->acc->prpl->add_deny( ic, handle ); |
---|
[da3b536] | 1158 | } |
---|
| 1159 | |
---|
[84b045d] | 1160 | void imc_rem_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1161 | { |
---|
| 1162 | GSList *l; |
---|
| 1163 | |
---|
[0da65d5] | 1164 | if( ( l = g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 1165 | { |
---|
| 1166 | g_free( l->data ); |
---|
[0da65d5] | 1167 | ic->deny = g_slist_delete_link( ic->deny, l ); |
---|
[da3b536] | 1168 | } |
---|
| 1169 | |
---|
[0da65d5] | 1170 | ic->acc->prpl->rem_deny( ic, handle ); |
---|
[da3b536] | 1171 | } |
---|
[85023c6] | 1172 | |
---|
| 1173 | void imcb_clean_handle( struct im_connection *ic, char *handle ) |
---|
| 1174 | { |
---|
| 1175 | /* Accepts a handle and does whatever is necessary to make it |
---|
| 1176 | BitlBee-friendly. Currently this means removing everything |
---|
| 1177 | outside 33-127 (ASCII printable excl spaces), @ (only one |
---|
| 1178 | is allowed) and ! and : */ |
---|
| 1179 | char out[strlen(handle)+1]; |
---|
| 1180 | int s, d; |
---|
| 1181 | |
---|
| 1182 | s = d = 0; |
---|
| 1183 | while( handle[s] ) |
---|
| 1184 | { |
---|
| 1185 | if( handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' && |
---|
| 1186 | ( handle[s] & 0x80 ) == 0 ) |
---|
| 1187 | { |
---|
| 1188 | if( handle[s] == '@' ) |
---|
| 1189 | { |
---|
| 1190 | /* See if we got an @ already? */ |
---|
| 1191 | out[d] = 0; |
---|
| 1192 | if( strchr( out, '@' ) ) |
---|
| 1193 | continue; |
---|
| 1194 | } |
---|
| 1195 | |
---|
| 1196 | out[d++] = handle[s]; |
---|
| 1197 | } |
---|
| 1198 | s ++; |
---|
| 1199 | } |
---|
| 1200 | out[d] = handle[s]; |
---|
| 1201 | |
---|
| 1202 | strcpy( handle, out ); |
---|
| 1203 | } |
---|