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