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