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