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