[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 | |
---|
| 38 | static int remove_chat_buddy_silent( struct conversation *b, char *handle ); |
---|
| 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) { |
---|
| 50 | log_message(LOGLVL_ERROR, "Can't find `%s', not loading", path); |
---|
| 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 | |
---|
| 102 | struct prpl *find_protocol(const char *name) |
---|
| 103 | { |
---|
| 104 | GList *gl; |
---|
| 105 | for (gl = protocols; gl; gl = gl->next) |
---|
| 106 | { |
---|
| 107 | struct prpl *proto = gl->data; |
---|
| 108 | if(!g_strcasecmp(proto->name, name)) |
---|
| 109 | return proto; |
---|
| 110 | } |
---|
| 111 | return NULL; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /* nogaim.c */ |
---|
[b7d3cc34] | 115 | void nogaim_init() |
---|
| 116 | { |
---|
[65e2ce1] | 117 | extern void msn_init(); |
---|
| 118 | extern void oscar_init(); |
---|
| 119 | extern void byahoo_init(); |
---|
| 120 | extern void jabber_init(); |
---|
[7b23afd] | 121 | |
---|
[b7d3cc34] | 122 | #ifdef WITH_MSN |
---|
[7b23afd] | 123 | msn_init(); |
---|
[b7d3cc34] | 124 | #endif |
---|
| 125 | |
---|
| 126 | #ifdef WITH_OSCAR |
---|
[7b23afd] | 127 | oscar_init(); |
---|
[b7d3cc34] | 128 | #endif |
---|
| 129 | |
---|
| 130 | #ifdef WITH_YAHOO |
---|
[7b23afd] | 131 | byahoo_init(); |
---|
[b7d3cc34] | 132 | #endif |
---|
| 133 | |
---|
| 134 | #ifdef WITH_JABBER |
---|
[7b23afd] | 135 | jabber_init(); |
---|
[b7d3cc34] | 136 | #endif |
---|
[7b23afd] | 137 | |
---|
[65e2ce1] | 138 | #ifdef WITH_PLUGINS |
---|
| 139 | load_plugins(); |
---|
[b7d3cc34] | 140 | #endif |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | GSList *get_connections() { return connections; } |
---|
| 144 | |
---|
| 145 | /* multi.c */ |
---|
| 146 | |
---|
| 147 | struct gaim_connection *new_gaim_conn( struct aim_user *user ) |
---|
| 148 | { |
---|
| 149 | struct gaim_connection *gc; |
---|
| 150 | account_t *a; |
---|
| 151 | |
---|
| 152 | gc = g_new0( struct gaim_connection, 1 ); |
---|
| 153 | |
---|
[7b23afd] | 154 | gc->prpl = user->prpl; |
---|
[b7d3cc34] | 155 | g_snprintf( gc->username, sizeof( gc->username ), "%s", user->username ); |
---|
| 156 | g_snprintf( gc->password, sizeof( gc->password ), "%s", user->password ); |
---|
| 157 | /* [MD] BUGFIX: don't set gc->irc to the global IRC, but use the one from the struct aim_user. |
---|
| 158 | * This fixes daemon mode breakage where IRC doesn't point to the currently active connection. |
---|
| 159 | */ |
---|
[c98be00] | 160 | gc->irc = user->irc; |
---|
[b7d3cc34] | 161 | |
---|
| 162 | connections = g_slist_append( connections, gc ); |
---|
| 163 | |
---|
| 164 | user->gc = gc; |
---|
| 165 | gc->user = user; |
---|
| 166 | |
---|
| 167 | // Find the account_t so we can set its gc pointer |
---|
| 168 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
| 169 | if( ( struct aim_user * ) a->gc == user ) |
---|
| 170 | { |
---|
| 171 | a->gc = gc; |
---|
| 172 | break; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | return( gc ); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | void destroy_gaim_conn( struct gaim_connection *gc ) |
---|
| 179 | { |
---|
| 180 | account_t *a; |
---|
| 181 | |
---|
| 182 | /* Destroy the pointer to this connection from the account list */ |
---|
| 183 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
| 184 | if( a->gc == gc ) |
---|
| 185 | { |
---|
| 186 | a->gc = NULL; |
---|
| 187 | break; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | connections = g_slist_remove( connections, gc ); |
---|
| 191 | g_free( gc->user ); |
---|
| 192 | g_free( gc ); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | void set_login_progress( struct gaim_connection *gc, int step, char *msg ) |
---|
| 196 | { |
---|
[5c09a59] | 197 | serv_got_crap( gc, "Logging in: %s", msg ); |
---|
[b7d3cc34] | 198 | } |
---|
| 199 | |
---|
| 200 | /* Errors *while* logging in */ |
---|
| 201 | void hide_login_progress( struct gaim_connection *gc, char *msg ) |
---|
| 202 | { |
---|
[5c09a59] | 203 | serv_got_crap( gc, "Login error: %s", msg ); |
---|
[b7d3cc34] | 204 | } |
---|
| 205 | |
---|
| 206 | /* Errors *after* logging in */ |
---|
| 207 | void hide_login_progress_error( struct gaim_connection *gc, char *msg ) |
---|
| 208 | { |
---|
[5c09a59] | 209 | serv_got_crap( gc, "Logged out: %s", msg ); |
---|
[b7d3cc34] | 210 | } |
---|
| 211 | |
---|
| 212 | void serv_got_crap( struct gaim_connection *gc, char *format, ... ) |
---|
| 213 | { |
---|
| 214 | va_list params; |
---|
[e27661d] | 215 | char *text; |
---|
[dfde8e0] | 216 | account_t *a; |
---|
[b7d3cc34] | 217 | |
---|
| 218 | va_start( params, format ); |
---|
[e27661d] | 219 | text = g_strdup_vprintf( format, params ); |
---|
[b7d3cc34] | 220 | va_end( params ); |
---|
| 221 | |
---|
[c572dd6] | 222 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
| 223 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
[e27661d] | 224 | strip_html( text ); |
---|
[b7d3cc34] | 225 | |
---|
[dfde8e0] | 226 | /* Try to find a different connection on the same protocol. */ |
---|
| 227 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
[b20b32f] | 228 | if( a->prpl == gc->prpl && a->gc != gc ) |
---|
[dfde8e0] | 229 | break; |
---|
| 230 | |
---|
[e27661d] | 231 | /* If we found one, include the screenname in the message. */ |
---|
[dfde8e0] | 232 | if( a ) |
---|
[e27661d] | 233 | irc_usermsg( gc->irc, "%s(%s) - %s", gc->prpl->name, gc->username, text ); |
---|
[dfde8e0] | 234 | else |
---|
[e27661d] | 235 | irc_usermsg( gc->irc, "%s - %s", gc->prpl->name, text ); |
---|
[7b07dc6] | 236 | |
---|
[e27661d] | 237 | g_free( text ); |
---|
[b7d3cc34] | 238 | } |
---|
| 239 | |
---|
[ba9edaa] | 240 | static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 241 | { |
---|
| 242 | struct gaim_connection *gc = d; |
---|
| 243 | |
---|
| 244 | if( gc->prpl && gc->prpl->keepalive ) |
---|
| 245 | gc->prpl->keepalive( gc ); |
---|
| 246 | |
---|
| 247 | return TRUE; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | void account_online( struct gaim_connection *gc ) |
---|
| 251 | { |
---|
| 252 | user_t *u; |
---|
| 253 | |
---|
| 254 | /* MSN servers sometimes redirect you to a different server and do |
---|
[84c1a0a] | 255 | the whole login sequence again, so these "late" calls to this |
---|
[b7d3cc34] | 256 | function should be handled correctly. (IOW, ignored) */ |
---|
| 257 | if( gc->flags & OPT_LOGGED_IN ) |
---|
| 258 | return; |
---|
| 259 | |
---|
| 260 | u = user_find( gc->irc, gc->irc->nick ); |
---|
| 261 | |
---|
[5c09a59] | 262 | serv_got_crap( gc, "Logged in" ); |
---|
[b7d3cc34] | 263 | |
---|
[ba9edaa] | 264 | gc->keepalive = b_timeout_add( 60000, send_keepalive, gc ); |
---|
[b7d3cc34] | 265 | gc->flags |= OPT_LOGGED_IN; |
---|
| 266 | |
---|
[61dddd0] | 267 | /* Also necessary when we're not away, at least for some of the |
---|
| 268 | protocols. */ |
---|
[226fce1] | 269 | bim_set_away( gc, u->away ); |
---|
[b7d3cc34] | 270 | } |
---|
| 271 | |
---|
[ba9edaa] | 272 | gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 273 | { |
---|
| 274 | account_t *a = data; |
---|
| 275 | |
---|
| 276 | a->reconnect = 0; |
---|
| 277 | account_on( a->irc, a ); |
---|
| 278 | |
---|
| 279 | return( FALSE ); /* Only have to run the timeout once */ |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | void cancel_auto_reconnect( account_t *a ) |
---|
| 283 | { |
---|
[c98be00] | 284 | /* while( b_event_remove_by_data( (gpointer) a ) ); */ |
---|
| 285 | b_event_remove( a->reconnect ); |
---|
[b7d3cc34] | 286 | a->reconnect = 0; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | void signoff( struct gaim_connection *gc ) |
---|
| 290 | { |
---|
| 291 | irc_t *irc = gc->irc; |
---|
| 292 | user_t *t, *u = irc->users; |
---|
| 293 | account_t *a; |
---|
| 294 | |
---|
[5c09a59] | 295 | serv_got_crap( gc, "Signing off.." ); |
---|
[b7d3cc34] | 296 | |
---|
[ba9edaa] | 297 | b_event_remove( gc->keepalive ); |
---|
[b7d3cc34] | 298 | gc->keepalive = 0; |
---|
| 299 | gc->prpl->close( gc ); |
---|
[ba9edaa] | 300 | b_event_remove( gc->inpa ); |
---|
[b7d3cc34] | 301 | |
---|
| 302 | while( u ) |
---|
| 303 | { |
---|
| 304 | if( u->gc == gc ) |
---|
| 305 | { |
---|
| 306 | t = u->next; |
---|
| 307 | user_del( irc, u->nick ); |
---|
| 308 | u = t; |
---|
| 309 | } |
---|
| 310 | else |
---|
| 311 | u = u->next; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | query_del_by_gc( gc->irc, gc ); |
---|
| 315 | |
---|
| 316 | for( a = irc->accounts; a; a = a->next ) |
---|
| 317 | if( a->gc == gc ) |
---|
| 318 | break; |
---|
| 319 | |
---|
| 320 | if( !a ) |
---|
| 321 | { |
---|
| 322 | /* Uhm... This is very sick. */ |
---|
| 323 | } |
---|
| 324 | else if( !gc->wants_to_die && set_getint( irc, "auto_reconnect" ) ) |
---|
| 325 | { |
---|
| 326 | int delay = set_getint( irc, "auto_reconnect_delay" ); |
---|
| 327 | |
---|
[c98be00] | 328 | serv_got_crap( gc, "Reconnecting in %d seconds..", delay ); |
---|
| 329 | a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a ); |
---|
[b7d3cc34] | 330 | } |
---|
| 331 | |
---|
| 332 | destroy_gaim_conn( gc ); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | /* dialogs.c */ |
---|
| 337 | |
---|
| 338 | void do_error_dialog( struct gaim_connection *gc, char *msg, char *title ) |
---|
| 339 | { |
---|
[25d1be7] | 340 | if( msg && title ) |
---|
| 341 | serv_got_crap( gc, "Error: %s: %s", title, msg ); |
---|
| 342 | else if( msg ) |
---|
| 343 | serv_got_crap( gc, "Error: %s", msg ); |
---|
| 344 | else if( title ) |
---|
| 345 | serv_got_crap( gc, "Error: %s", title ); |
---|
| 346 | else |
---|
| 347 | serv_got_crap( gc, "Error" ); |
---|
[b7d3cc34] | 348 | } |
---|
| 349 | |
---|
| 350 | void do_ask_dialog( struct gaim_connection *gc, char *msg, void *data, void *doit, void *dont ) |
---|
| 351 | { |
---|
| 352 | query_add( gc->irc, gc, msg, doit, dont, data ); |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | |
---|
| 356 | /* list.c */ |
---|
| 357 | |
---|
| 358 | void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *realname ) |
---|
| 359 | { |
---|
| 360 | user_t *u; |
---|
| 361 | char nick[MAX_NICK_LENGTH+1]; |
---|
| 362 | char *s; |
---|
| 363 | irc_t *irc = gc->irc; |
---|
| 364 | |
---|
| 365 | if( set_getint( irc, "debug" ) && 0 ) /* This message is too useless */ |
---|
[5c09a59] | 366 | serv_got_crap( gc, "Receiving user add from handle: %s", handle ); |
---|
[b7d3cc34] | 367 | |
---|
| 368 | if( user_findhandle( gc, handle ) ) |
---|
| 369 | { |
---|
| 370 | if( set_getint( irc, "debug" ) ) |
---|
[5c09a59] | 371 | serv_got_crap( gc, "User already exists, ignoring add request: %s", handle ); |
---|
[b7d3cc34] | 372 | |
---|
| 373 | return; |
---|
| 374 | |
---|
| 375 | /* Buddy seems to exist already. Let's ignore this request then... */ |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
[7b23afd] | 379 | strcpy( nick, nick_get( gc->irc, handle, gc->prpl, realname ) ); |
---|
[b7d3cc34] | 380 | |
---|
| 381 | u = user_add( gc->irc, nick ); |
---|
| 382 | |
---|
| 383 | if( !realname || !*realname ) realname = nick; |
---|
| 384 | u->realname = g_strdup( realname ); |
---|
| 385 | |
---|
| 386 | if( ( s = strchr( handle, '@' ) ) ) |
---|
| 387 | { |
---|
| 388 | u->host = g_strdup( s + 1 ); |
---|
| 389 | u->user = g_strndup( handle, s - handle ); |
---|
| 390 | } |
---|
| 391 | else if( gc->user->proto_opt[0] && *gc->user->proto_opt[0] ) |
---|
| 392 | { |
---|
[c53911e] | 393 | char *colon; |
---|
| 394 | |
---|
| 395 | if( ( colon = strchr( gc->user->proto_opt[0], ':' ) ) ) |
---|
| 396 | u->host = g_strndup( gc->user->proto_opt[0], |
---|
| 397 | colon - gc->user->proto_opt[0] ); |
---|
| 398 | else |
---|
| 399 | u->host = g_strdup( gc->user->proto_opt[0] ); |
---|
| 400 | |
---|
[b7d3cc34] | 401 | u->user = g_strdup( handle ); |
---|
| 402 | |
---|
| 403 | /* s/ /_/ ... important for AOL screennames */ |
---|
| 404 | for( s = u->user; *s; s ++ ) |
---|
| 405 | if( *s == ' ' ) |
---|
| 406 | *s = '_'; |
---|
| 407 | } |
---|
| 408 | else |
---|
| 409 | { |
---|
[7b23afd] | 410 | u->host = g_strdup( gc->user->prpl->name ); |
---|
[b7d3cc34] | 411 | u->user = g_strdup( handle ); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | u->gc = gc; |
---|
| 415 | u->handle = g_strdup( handle ); |
---|
[9b8a38b] | 416 | if( group ) u->group = g_strdup( group ); |
---|
[b7d3cc34] | 417 | u->send_handler = buddy_send_handler; |
---|
| 418 | u->last_typing_notice = 0; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | struct buddy *find_buddy( struct gaim_connection *gc, char *handle ) |
---|
| 422 | { |
---|
| 423 | static struct buddy b[1]; |
---|
| 424 | user_t *u; |
---|
| 425 | |
---|
| 426 | u = user_findhandle( gc, handle ); |
---|
| 427 | |
---|
| 428 | if( !u ) |
---|
| 429 | return( NULL ); |
---|
| 430 | |
---|
| 431 | memset( b, 0, sizeof( b ) ); |
---|
| 432 | strncpy( b->name, handle, 80 ); |
---|
| 433 | strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN ); |
---|
| 434 | b->present = u->online; |
---|
| 435 | b->gc = u->gc; |
---|
| 436 | |
---|
| 437 | return( b ); |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | void signoff_blocked( struct gaim_connection *gc ) |
---|
| 441 | { |
---|
| 442 | return; /* Make all blocked users look invisible (TODO?) */ |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | |
---|
| 446 | void serv_buddy_rename( struct gaim_connection *gc, char *handle, char *realname ) |
---|
| 447 | { |
---|
| 448 | user_t *u = user_findhandle( gc, handle ); |
---|
| 449 | |
---|
| 450 | if( !u ) return; |
---|
| 451 | |
---|
[e27661d] | 452 | if( g_strcasecmp( u->realname, realname ) != 0 ) |
---|
[b7d3cc34] | 453 | { |
---|
| 454 | if( u->realname != u->nick ) g_free( u->realname ); |
---|
| 455 | |
---|
[e27661d] | 456 | u->realname = g_strdup( realname ); |
---|
[b7d3cc34] | 457 | |
---|
| 458 | if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( gc->irc, "display_namechanges" ) ) |
---|
[5c09a59] | 459 | serv_got_crap( gc, "User `%s' changed name to `%s'", u->nick, u->realname ); |
---|
[b7d3cc34] | 460 | } |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | |
---|
| 464 | /* prpl.c */ |
---|
| 465 | |
---|
[7bf0f5f0] | 466 | struct show_got_added_data |
---|
| 467 | { |
---|
| 468 | struct gaim_connection *gc; |
---|
| 469 | char *handle; |
---|
| 470 | }; |
---|
| 471 | |
---|
| 472 | void show_got_added_no( gpointer w, struct show_got_added_data *data ) |
---|
| 473 | { |
---|
| 474 | g_free( data->handle ); |
---|
| 475 | g_free( data ); |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | void show_got_added_yes( gpointer w, struct show_got_added_data *data ) |
---|
| 479 | { |
---|
| 480 | data->gc->prpl->add_buddy( data->gc, data->handle ); |
---|
| 481 | add_buddy( data->gc, NULL, data->handle, data->handle ); |
---|
| 482 | |
---|
| 483 | return show_got_added_no( w, data ); |
---|
| 484 | } |
---|
| 485 | |
---|
[e6d6047] | 486 | void show_got_added( struct gaim_connection *gc, char *handle, const char *realname ) |
---|
[b7d3cc34] | 487 | { |
---|
[7bf0f5f0] | 488 | struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); |
---|
| 489 | char *s; |
---|
| 490 | |
---|
| 491 | /* TODO: Make a setting for this! */ |
---|
| 492 | if( user_findhandle( gc, handle ) != NULL ) |
---|
| 493 | return; |
---|
| 494 | |
---|
| 495 | s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); |
---|
| 496 | |
---|
| 497 | data->gc = gc; |
---|
| 498 | data->handle = g_strdup( handle ); |
---|
| 499 | query_add( gc->irc, gc, s, show_got_added_yes, show_got_added_no, data ); |
---|
[b7d3cc34] | 500 | } |
---|
| 501 | |
---|
| 502 | |
---|
| 503 | /* server.c */ |
---|
| 504 | |
---|
| 505 | void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, int evil, time_t signon, time_t idle, int type, guint caps ) |
---|
| 506 | { |
---|
| 507 | user_t *u; |
---|
| 508 | int oa, oo; |
---|
| 509 | |
---|
| 510 | u = user_findhandle( gc, handle ); |
---|
| 511 | |
---|
| 512 | if( !u ) |
---|
| 513 | { |
---|
| 514 | if( g_strcasecmp( set_getstr( gc->irc, "handle_unknown" ), "add" ) == 0 ) |
---|
| 515 | { |
---|
| 516 | add_buddy( gc, NULL, handle, NULL ); |
---|
| 517 | u = user_findhandle( gc, handle ); |
---|
| 518 | } |
---|
| 519 | else |
---|
| 520 | { |
---|
| 521 | if( set_getint( gc->irc, "debug" ) || g_strcasecmp( set_getstr( gc->irc, "handle_unknown" ), "ignore" ) != 0 ) |
---|
| 522 | { |
---|
[5c09a59] | 523 | serv_got_crap( gc, "serv_got_update() for handle %s:", handle ); |
---|
| 524 | serv_got_crap( gc, "loggedin = %d, type = %d", loggedin, type ); |
---|
[b7d3cc34] | 525 | } |
---|
| 526 | |
---|
| 527 | return; |
---|
| 528 | } |
---|
[dd89a55] | 529 | /* Why did we have this here.... |
---|
| 530 | return; */ |
---|
[b7d3cc34] | 531 | } |
---|
| 532 | |
---|
| 533 | oa = u->away != NULL; |
---|
| 534 | oo = u->online; |
---|
| 535 | |
---|
| 536 | if( u->away ) |
---|
| 537 | { |
---|
| 538 | g_free( u->away ); |
---|
| 539 | u->away = NULL; |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | if( loggedin && !u->online ) |
---|
| 543 | { |
---|
| 544 | irc_spawn( gc->irc, u ); |
---|
| 545 | u->online = 1; |
---|
| 546 | } |
---|
| 547 | else if( !loggedin && u->online ) |
---|
| 548 | { |
---|
| 549 | struct conversation *c; |
---|
| 550 | |
---|
| 551 | irc_kill( gc->irc, u ); |
---|
| 552 | u->online = 0; |
---|
| 553 | |
---|
| 554 | /* Remove him/her from the conversations to prevent PART messages after he/she QUIT already */ |
---|
| 555 | for( c = gc->conversations; c; c = c->next ) |
---|
| 556 | remove_chat_buddy_silent( c, handle ); |
---|
| 557 | } |
---|
| 558 | |
---|
[7b23afd] | 559 | if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "oscar") || !strcmp(gc->prpl->name, "icq")) ) |
---|
[b7d3cc34] | 560 | { |
---|
| 561 | u->away = g_strdup( "Away" ); |
---|
| 562 | } |
---|
[7b23afd] | 563 | else if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "jabber") ) ) |
---|
[b7d3cc34] | 564 | { |
---|
| 565 | if( type & UC_DND ) |
---|
| 566 | u->away = g_strdup( "Do Not Disturb" ); |
---|
| 567 | else if( type & UC_XA ) |
---|
| 568 | u->away = g_strdup( "Extended Away" ); |
---|
| 569 | else // if( type & UC_AWAY ) |
---|
| 570 | u->away = g_strdup( "Away" ); |
---|
| 571 | } |
---|
| 572 | else if( ( type & UC_UNAVAILABLE ) && gc->prpl->get_status_string ) |
---|
| 573 | { |
---|
| 574 | u->away = g_strdup( gc->prpl->get_status_string( gc, type ) ); |
---|
| 575 | } |
---|
| 576 | else |
---|
| 577 | u->away = NULL; |
---|
| 578 | |
---|
| 579 | /* LISPy... */ |
---|
| 580 | if( ( set_getint( gc->irc, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ |
---|
| 581 | ( u->online ) && /* Don't touch offline people */ |
---|
| 582 | ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ |
---|
| 583 | ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ |
---|
| 584 | { |
---|
| 585 | irc_write( gc->irc, ":%s!%s@%s MODE %s %cv %s", gc->irc->mynick, gc->irc->mynick, gc->irc->myhost, |
---|
| 586 | gc->irc->channel, u->away?'-':'+', u->nick ); |
---|
| 587 | } |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 flags, time_t mtime, gint len ) |
---|
| 591 | { |
---|
| 592 | irc_t *irc = gc->irc; |
---|
| 593 | user_t *u; |
---|
| 594 | |
---|
| 595 | u = user_findhandle( gc, handle ); |
---|
| 596 | |
---|
| 597 | if( !u ) |
---|
| 598 | { |
---|
| 599 | char *h = set_getstr( irc, "handle_unknown" ); |
---|
| 600 | |
---|
| 601 | if( g_strcasecmp( h, "ignore" ) == 0 ) |
---|
| 602 | { |
---|
| 603 | if( set_getint( irc, "debug" ) ) |
---|
[5c09a59] | 604 | serv_got_crap( gc, "Ignoring message from unknown handle %s", handle ); |
---|
[b7d3cc34] | 605 | |
---|
| 606 | return; |
---|
| 607 | } |
---|
| 608 | else if( g_strncasecmp( h, "add", 3 ) == 0 ) |
---|
| 609 | { |
---|
| 610 | int private = set_getint( irc, "private" ); |
---|
| 611 | |
---|
| 612 | if( h[3] ) |
---|
| 613 | { |
---|
| 614 | if( g_strcasecmp( h + 3, "_private" ) == 0 ) |
---|
| 615 | private = 1; |
---|
| 616 | else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) |
---|
| 617 | private = 0; |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | add_buddy( gc, NULL, handle, NULL ); |
---|
| 621 | u = user_findhandle( gc, handle ); |
---|
| 622 | u->is_private = private; |
---|
| 623 | } |
---|
| 624 | else |
---|
| 625 | { |
---|
[5c09a59] | 626 | serv_got_crap( gc, "Message from unknown handle %s:", handle ); |
---|
[b7d3cc34] | 627 | u = user_find( irc, irc->mynick ); |
---|
| 628 | } |
---|
| 629 | } |
---|
| 630 | |
---|
[c572dd6] | 631 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
| 632 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
[b7d3cc34] | 633 | strip_html( msg ); |
---|
| 634 | |
---|
[30f248a] | 635 | while( strlen( msg ) > 425 ) |
---|
[b7d3cc34] | 636 | { |
---|
| 637 | char tmp, *nl; |
---|
| 638 | |
---|
[30f248a] | 639 | tmp = msg[425]; |
---|
| 640 | msg[425] = 0; |
---|
[b7d3cc34] | 641 | |
---|
[30f248a] | 642 | /* If there's a newline/space in this string, split up there, |
---|
| 643 | looks a bit prettier. */ |
---|
[f1df064] | 644 | if( ( nl = strrchr( msg, '\n' ) ) || ( nl = strrchr( msg, ' ' ) ) ) |
---|
[30f248a] | 645 | { |
---|
| 646 | msg[425] = tmp; |
---|
| 647 | tmp = *nl; |
---|
[b7d3cc34] | 648 | *nl = 0; |
---|
[30f248a] | 649 | } |
---|
[b7d3cc34] | 650 | |
---|
| 651 | irc_msgfrom( irc, u->nick, msg ); |
---|
| 652 | |
---|
| 653 | /* Move on. */ |
---|
| 654 | if( nl ) |
---|
| 655 | { |
---|
[30f248a] | 656 | *nl = tmp; |
---|
[b7d3cc34] | 657 | msg = nl + 1; |
---|
| 658 | } |
---|
| 659 | else |
---|
| 660 | { |
---|
[30f248a] | 661 | msg[425] = tmp; |
---|
| 662 | msg += 425; |
---|
[b7d3cc34] | 663 | } |
---|
| 664 | } |
---|
| 665 | irc_msgfrom( irc, u->nick, msg ); |
---|
| 666 | } |
---|
| 667 | |
---|
[e7f46c5] | 668 | void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout, int type ) |
---|
[b7d3cc34] | 669 | { |
---|
| 670 | user_t *u; |
---|
| 671 | |
---|
| 672 | if( !set_getint( gc->irc, "typing_notice" ) ) |
---|
| 673 | return; |
---|
| 674 | |
---|
[e7f46c5] | 675 | if( ( u = user_findhandle( gc, handle ) ) ) { |
---|
| 676 | /* If type is: |
---|
| 677 | * 0: user has stopped typing |
---|
| 678 | * 1: user is actively typing |
---|
| 679 | * 2: user has entered text, but is not actively typing |
---|
| 680 | */ |
---|
| 681 | if (type == 0 || type == 1 || type == 2) { |
---|
| 682 | char buf[256]; |
---|
| 683 | g_snprintf(buf, 256, "\1TYPING %d\1", type); |
---|
| 684 | irc_privmsg( gc->irc, u, "PRIVMSG", gc->irc->nick, NULL, buf ); |
---|
| 685 | } |
---|
| 686 | } |
---|
[b7d3cc34] | 687 | } |
---|
| 688 | |
---|
| 689 | void serv_got_chat_left( struct gaim_connection *gc, int id ) |
---|
| 690 | { |
---|
| 691 | struct conversation *c, *l = NULL; |
---|
| 692 | GList *ir; |
---|
| 693 | |
---|
| 694 | if( set_getint( gc->irc, "debug" ) ) |
---|
[5c09a59] | 695 | serv_got_crap( gc, "You were removed from conversation %d", (int) id ); |
---|
[b7d3cc34] | 696 | |
---|
| 697 | for( c = gc->conversations; c && c->id != id; c = (l=c)->next ); |
---|
| 698 | |
---|
| 699 | if( c ) |
---|
| 700 | { |
---|
| 701 | if( c->joined ) |
---|
| 702 | { |
---|
| 703 | user_t *u, *r; |
---|
| 704 | |
---|
| 705 | r = user_find( gc->irc, gc->irc->mynick ); |
---|
| 706 | irc_privmsg( gc->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
| 707 | |
---|
| 708 | u = user_find( gc->irc, gc->irc->nick ); |
---|
| 709 | irc_kick( gc->irc, u, c->channel, r ); |
---|
| 710 | /* irc_part( gc->irc, u, c->channel ); */ |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | if( l ) |
---|
| 714 | l->next = c->next; |
---|
| 715 | else |
---|
| 716 | gc->conversations = c->next; |
---|
| 717 | |
---|
| 718 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
| 719 | g_free( ir->data ); |
---|
| 720 | g_list_free( c->in_room ); |
---|
| 721 | g_free( c->channel ); |
---|
| 722 | g_free( c->title ); |
---|
| 723 | g_free( c ); |
---|
| 724 | } |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | void serv_got_chat_in( struct gaim_connection *gc, int id, char *who, int whisper, char *msg, time_t mtime ) |
---|
| 728 | { |
---|
| 729 | struct conversation *c; |
---|
| 730 | user_t *u; |
---|
| 731 | |
---|
| 732 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
| 733 | if( g_strcasecmp( who, gc->user->username ) == 0 ) |
---|
| 734 | return; |
---|
| 735 | |
---|
| 736 | u = user_findhandle( gc, who ); |
---|
| 737 | for( c = gc->conversations; c && c->id != id; c = c->next ); |
---|
| 738 | |
---|
[c572dd6] | 739 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
| 740 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
[b7d3cc34] | 741 | strip_html( msg ); |
---|
| 742 | |
---|
| 743 | if( c && u ) |
---|
| 744 | irc_privmsg( gc->irc, u, "PRIVMSG", c->channel, "", msg ); |
---|
| 745 | else |
---|
[5c09a59] | 746 | serv_got_crap( gc, "Message from/to conversation %s@%d (unknown conv/user): %s", who, id, msg ); |
---|
[b7d3cc34] | 747 | } |
---|
| 748 | |
---|
| 749 | struct conversation *serv_got_joined_chat( struct gaim_connection *gc, int id, char *handle ) |
---|
| 750 | { |
---|
| 751 | struct conversation *c; |
---|
| 752 | char *s; |
---|
| 753 | |
---|
| 754 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
| 755 | |
---|
| 756 | if( gc->conversations ) |
---|
| 757 | { |
---|
| 758 | for( c = gc->conversations; c->next; c = c->next ); |
---|
| 759 | c = c->next = g_new0( struct conversation, 1 ); |
---|
| 760 | } |
---|
| 761 | else |
---|
| 762 | gc->conversations = c = g_new0( struct conversation, 1); |
---|
| 763 | |
---|
| 764 | c->id = id; |
---|
| 765 | c->gc = gc; |
---|
| 766 | c->title = g_strdup( handle ); |
---|
| 767 | |
---|
| 768 | s = g_new( char, 16 ); |
---|
[94281ef] | 769 | sprintf( s, "&chat_%03d", gc->irc->c_id++ ); |
---|
[b7d3cc34] | 770 | c->channel = g_strdup( s ); |
---|
| 771 | g_free( s ); |
---|
| 772 | |
---|
| 773 | if( set_getint( gc->irc, "debug" ) ) |
---|
[5c09a59] | 774 | serv_got_crap( gc, "Creating new conversation: (id=%d,handle=%s)", id, handle ); |
---|
[b7d3cc34] | 775 | |
---|
| 776 | return( c ); |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | |
---|
| 780 | /* buddy_chat.c */ |
---|
| 781 | |
---|
| 782 | void add_chat_buddy( struct conversation *b, char *handle ) |
---|
| 783 | { |
---|
| 784 | user_t *u = user_findhandle( b->gc, handle ); |
---|
| 785 | int me = 0; |
---|
| 786 | |
---|
| 787 | if( set_getint( b->gc->irc, "debug" ) ) |
---|
[5c09a59] | 788 | serv_got_crap( b->gc, "User %s added to conversation %d", handle, b->id ); |
---|
[b7d3cc34] | 789 | |
---|
| 790 | /* It might be yourself! */ |
---|
[9cb9868] | 791 | if( b->gc->prpl->cmp_buddynames( handle, b->gc->user->username ) == 0 ) |
---|
[b7d3cc34] | 792 | { |
---|
| 793 | u = user_find( b->gc->irc, b->gc->irc->nick ); |
---|
| 794 | if( !b->joined ) |
---|
| 795 | irc_join( b->gc->irc, u, b->channel ); |
---|
| 796 | b->joined = me = 1; |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | /* Most protocols allow people to join, even when they're not in |
---|
| 800 | your contact list. Try to handle that here */ |
---|
| 801 | if( !u ) |
---|
| 802 | { |
---|
| 803 | add_buddy( b->gc, NULL, handle, NULL ); |
---|
| 804 | u = user_findhandle( b->gc, handle ); |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
| 808 | if( !me ) |
---|
| 809 | { |
---|
| 810 | if( b->joined ) |
---|
| 811 | irc_join( b->gc->irc, u, b->channel ); |
---|
| 812 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
| 813 | } |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | void remove_chat_buddy( struct conversation *b, char *handle, char *reason ) |
---|
| 817 | { |
---|
| 818 | user_t *u; |
---|
| 819 | int me = 0; |
---|
| 820 | |
---|
| 821 | if( set_getint( b->gc->irc, "debug" ) ) |
---|
[5c09a59] | 822 | serv_got_crap( b->gc, "User %s removed from conversation %d (%s)", handle, b->id, reason ? reason : "" ); |
---|
[b7d3cc34] | 823 | |
---|
| 824 | /* It might be yourself! */ |
---|
| 825 | if( g_strcasecmp( handle, b->gc->user->username ) == 0 ) |
---|
| 826 | { |
---|
| 827 | u = user_find( b->gc->irc, b->gc->irc->nick ); |
---|
| 828 | b->joined = 0; |
---|
| 829 | me = 1; |
---|
| 830 | } |
---|
| 831 | else |
---|
| 832 | { |
---|
| 833 | u = user_findhandle( b->gc, handle ); |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | if( remove_chat_buddy_silent( b, handle ) ) |
---|
| 837 | if( ( b->joined || me ) && u ) |
---|
| 838 | irc_part( b->gc->irc, u, b->channel ); |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | static int remove_chat_buddy_silent( struct conversation *b, char *handle ) |
---|
| 842 | { |
---|
| 843 | GList *i; |
---|
| 844 | |
---|
| 845 | /* Find the handle in the room userlist and shoot it */ |
---|
| 846 | i = b->in_room; |
---|
| 847 | while( i ) |
---|
| 848 | { |
---|
| 849 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
| 850 | { |
---|
| 851 | g_free( i->data ); |
---|
| 852 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
| 853 | return( 1 ); |
---|
| 854 | } |
---|
| 855 | |
---|
| 856 | i = i->next; |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | return( 0 ); |
---|
| 860 | } |
---|
| 861 | |
---|
| 862 | |
---|
| 863 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
| 864 | |
---|
| 865 | struct conversation *conv_findchannel( char *channel ) |
---|
| 866 | { |
---|
| 867 | struct gaim_connection *gc; |
---|
| 868 | struct conversation *c; |
---|
| 869 | GSList *l; |
---|
| 870 | |
---|
| 871 | /* This finds the connection which has a conversation which belongs to this channel */ |
---|
| 872 | for( l = connections; l; l = l->next ) |
---|
| 873 | { |
---|
| 874 | gc = l->data; |
---|
| 875 | for( c = gc->conversations; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next ); |
---|
| 876 | if( c ) |
---|
| 877 | return( c ); |
---|
| 878 | } |
---|
| 879 | |
---|
| 880 | return( NULL ); |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | char *set_eval_away_devoice( irc_t *irc, set_t *set, char *value ) |
---|
| 884 | { |
---|
| 885 | int st; |
---|
| 886 | |
---|
| 887 | if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) |
---|
| 888 | st = 1; |
---|
| 889 | else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) |
---|
| 890 | st = 0; |
---|
| 891 | else if( sscanf( value, "%d", &st ) != 1 ) |
---|
| 892 | return( NULL ); |
---|
| 893 | |
---|
| 894 | st = st != 0; |
---|
| 895 | |
---|
| 896 | /* Horror.... */ |
---|
| 897 | |
---|
| 898 | if( st != set_getint( irc, "away_devoice" ) ) |
---|
| 899 | { |
---|
| 900 | char list[80] = ""; |
---|
| 901 | user_t *u = irc->users; |
---|
| 902 | int i = 0, count = 0; |
---|
| 903 | char pm; |
---|
| 904 | char v[80]; |
---|
| 905 | |
---|
| 906 | if( st ) |
---|
| 907 | pm = '+'; |
---|
| 908 | else |
---|
| 909 | pm = '-'; |
---|
| 910 | |
---|
| 911 | while( u ) |
---|
| 912 | { |
---|
| 913 | if( u->gc && u->online && !u->away ) |
---|
| 914 | { |
---|
| 915 | if( ( strlen( list ) + strlen( u->nick ) ) >= 79 ) |
---|
| 916 | { |
---|
| 917 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
| 918 | irc_write( irc, ":%s!%s@%s MODE %s %c%s%s", |
---|
| 919 | irc->mynick, irc->mynick, irc->myhost, |
---|
| 920 | irc->channel, pm, v, list ); |
---|
| 921 | |
---|
| 922 | *list = 0; |
---|
| 923 | count = 0; |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | sprintf( list + strlen( list ), " %s", u->nick ); |
---|
| 927 | count ++; |
---|
| 928 | } |
---|
| 929 | u = u->next; |
---|
| 930 | } |
---|
| 931 | |
---|
| 932 | /* $v = 'v' x $i */ |
---|
| 933 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
| 934 | irc_write( irc, ":%s!%s@%s MODE %s %c%s%s", irc->mynick, irc->mynick, irc->myhost, |
---|
| 935 | irc->channel, pm, v, list ); |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | return( set_eval_bool( irc, set, value ) ); |
---|
| 939 | } |
---|
| 940 | |
---|
[226fce1] | 941 | |
---|
| 942 | |
---|
| 943 | |
---|
| 944 | /* The plan is to not allow straight calls to prpl functions anymore, but do |
---|
| 945 | them all from some wrappers. We'll start to define some down here: */ |
---|
| 946 | |
---|
| 947 | int bim_buddy_msg( struct gaim_connection *gc, char *handle, char *msg, int flags ) |
---|
[b7d3cc34] | 948 | { |
---|
[e27661d] | 949 | char *buf = NULL; |
---|
| 950 | int st; |
---|
[b7d3cc34] | 951 | |
---|
[226fce1] | 952 | if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[c572dd6] | 953 | { |
---|
[e27661d] | 954 | buf = escape_html( msg ); |
---|
[c572dd6] | 955 | msg = buf; |
---|
[b7d3cc34] | 956 | } |
---|
| 957 | |
---|
[226fce1] | 958 | st = gc->prpl->send_im( gc, handle, msg, strlen( msg ), flags ); |
---|
[e27661d] | 959 | g_free( buf ); |
---|
| 960 | |
---|
| 961 | return st; |
---|
[b7d3cc34] | 962 | } |
---|
| 963 | |
---|
[226fce1] | 964 | int bim_chat_msg( struct gaim_connection *gc, int id, char *msg ) |
---|
[b7d3cc34] | 965 | { |
---|
[e27661d] | 966 | char *buf = NULL; |
---|
| 967 | int st; |
---|
[b7d3cc34] | 968 | |
---|
[e27661d] | 969 | if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
| 970 | { |
---|
| 971 | buf = escape_html( msg ); |
---|
[b7d3cc34] | 972 | msg = buf; |
---|
| 973 | } |
---|
| 974 | |
---|
[e27661d] | 975 | st = gc->prpl->chat_send( gc, id, msg ); |
---|
| 976 | g_free( buf ); |
---|
| 977 | |
---|
| 978 | return st; |
---|
[b7d3cc34] | 979 | } |
---|
[226fce1] | 980 | |
---|
| 981 | static char *bim_away_alias_find( GList *gcm, char *away ); |
---|
| 982 | |
---|
| 983 | int bim_set_away( struct gaim_connection *gc, char *away ) |
---|
| 984 | { |
---|
| 985 | GList *m, *ms; |
---|
| 986 | char *s; |
---|
| 987 | |
---|
| 988 | if( !away ) away = ""; |
---|
| 989 | ms = m = gc->prpl->away_states( gc ); |
---|
| 990 | |
---|
| 991 | while( m ) |
---|
| 992 | { |
---|
| 993 | if( *away ) |
---|
| 994 | { |
---|
| 995 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
| 996 | break; |
---|
| 997 | } |
---|
| 998 | else |
---|
| 999 | { |
---|
| 1000 | if( g_strcasecmp( m->data, "Available" ) == 0 ) |
---|
| 1001 | break; |
---|
| 1002 | if( g_strcasecmp( m->data, "Online" ) == 0 ) |
---|
| 1003 | break; |
---|
| 1004 | } |
---|
| 1005 | m = m->next; |
---|
| 1006 | } |
---|
| 1007 | |
---|
| 1008 | if( m ) |
---|
| 1009 | { |
---|
| 1010 | gc->prpl->set_away( gc, m->data, *away ? away : NULL ); |
---|
| 1011 | } |
---|
| 1012 | else |
---|
| 1013 | { |
---|
| 1014 | s = bim_away_alias_find( ms, away ); |
---|
| 1015 | if( s ) |
---|
| 1016 | { |
---|
| 1017 | gc->prpl->set_away( gc, s, away ); |
---|
| 1018 | if( set_getint( gc->irc, "debug" ) ) |
---|
| 1019 | serv_got_crap( gc, "Setting away state to %s", s ); |
---|
| 1020 | } |
---|
| 1021 | else |
---|
| 1022 | gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away ); |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | g_list_free( ms ); |
---|
| 1026 | |
---|
| 1027 | return( 1 ); |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | static char *bim_away_alias_list[8][5] = |
---|
| 1031 | { |
---|
| 1032 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
| 1033 | { "NA", "N/A", "Not available", NULL }, |
---|
| 1034 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
| 1035 | { "Be right back", "BRB", NULL }, |
---|
| 1036 | { "On the phone", "Phone", "On phone", NULL }, |
---|
| 1037 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
| 1038 | { "Invisible", "Hidden" }, |
---|
| 1039 | { NULL } |
---|
| 1040 | }; |
---|
| 1041 | |
---|
| 1042 | static char *bim_away_alias_find( GList *gcm, char *away ) |
---|
| 1043 | { |
---|
| 1044 | GList *m; |
---|
| 1045 | int i, j; |
---|
| 1046 | |
---|
| 1047 | for( i = 0; *bim_away_alias_list[i]; i ++ ) |
---|
| 1048 | { |
---|
| 1049 | for( j = 0; bim_away_alias_list[i][j]; j ++ ) |
---|
| 1050 | if( g_strncasecmp( away, bim_away_alias_list[i][j], strlen( bim_away_alias_list[i][j] ) ) == 0 ) |
---|
| 1051 | break; |
---|
| 1052 | |
---|
| 1053 | if( !bim_away_alias_list[i][j] ) /* If we reach the end, this row */ |
---|
| 1054 | continue; /* is not what we want. Next! */ |
---|
| 1055 | |
---|
| 1056 | /* Now find an entry in this row which exists in gcm */ |
---|
| 1057 | for( j = 0; bim_away_alias_list[i][j]; j ++ ) |
---|
| 1058 | { |
---|
| 1059 | m = gcm; |
---|
| 1060 | while( m ) |
---|
| 1061 | { |
---|
| 1062 | if( g_strcasecmp( bim_away_alias_list[i][j], m->data ) == 0 ) |
---|
| 1063 | return( bim_away_alias_list[i][j] ); |
---|
| 1064 | m = m->next; |
---|
| 1065 | } |
---|
| 1066 | } |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | return( NULL ); |
---|
| 1070 | } |
---|
[da3b536] | 1071 | |
---|
| 1072 | void bim_add_allow( struct gaim_connection *gc, char *handle ) |
---|
| 1073 | { |
---|
| 1074 | if( g_slist_find_custom( gc->permit, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) == NULL ) |
---|
| 1075 | { |
---|
| 1076 | gc->permit = g_slist_prepend( gc->permit, g_strdup( handle ) ); |
---|
| 1077 | } |
---|
| 1078 | |
---|
| 1079 | gc->prpl->add_permit( gc, handle ); |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | void bim_rem_allow( struct gaim_connection *gc, char *handle ) |
---|
| 1083 | { |
---|
| 1084 | GSList *l; |
---|
| 1085 | |
---|
| 1086 | if( ( l = g_slist_find_custom( gc->permit, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) ) ) |
---|
| 1087 | { |
---|
| 1088 | g_free( l->data ); |
---|
| 1089 | gc->permit = g_slist_delete_link( gc->permit, l ); |
---|
| 1090 | } |
---|
| 1091 | |
---|
| 1092 | gc->prpl->rem_permit( gc, handle ); |
---|
| 1093 | } |
---|
| 1094 | |
---|
| 1095 | void bim_add_block( struct gaim_connection *gc, char *handle ) |
---|
| 1096 | { |
---|
| 1097 | if( g_slist_find_custom( gc->deny, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) == NULL ) |
---|
| 1098 | { |
---|
| 1099 | gc->deny = g_slist_prepend( gc->deny, g_strdup( handle ) ); |
---|
| 1100 | } |
---|
| 1101 | |
---|
| 1102 | gc->prpl->add_deny( gc, handle ); |
---|
| 1103 | } |
---|
| 1104 | |
---|
| 1105 | void bim_rem_block( struct gaim_connection *gc, char *handle ) |
---|
| 1106 | { |
---|
| 1107 | GSList *l; |
---|
| 1108 | |
---|
| 1109 | if( ( l = g_slist_find_custom( gc->deny, handle, (GCompareFunc) gc->prpl->cmp_buddynames ) ) ) |
---|
| 1110 | { |
---|
| 1111 | g_free( l->data ); |
---|
| 1112 | gc->deny = g_slist_delete_link( gc->deny, l ); |
---|
| 1113 | } |
---|
| 1114 | |
---|
| 1115 | gc->prpl->rem_deny( gc, handle ); |
---|
| 1116 | } |
---|