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