[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 | |
---|
[764b163d] | 38 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); |
---|
[b7d3cc34] | 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) { |
---|
[8ad90fb] | 50 | log_message(LOGLVL_ERROR, "Can't find `%s', not loading (%s)\n", path, g_module_error()); |
---|
[7b23afd] | 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 | struct prpl *find_protocol(const char *name) |
---|
| 102 | { |
---|
| 103 | GList *gl; |
---|
| 104 | for (gl = protocols; gl; gl = gl->next) |
---|
| 105 | { |
---|
| 106 | struct prpl *proto = gl->data; |
---|
| 107 | if(!g_strcasecmp(proto->name, name)) |
---|
| 108 | return proto; |
---|
| 109 | } |
---|
| 110 | return NULL; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /* nogaim.c */ |
---|
[b7d3cc34] | 114 | void nogaim_init() |
---|
| 115 | { |
---|
[0da65d5] | 116 | extern void msn_initmodule(); |
---|
| 117 | extern void oscar_initmodule(); |
---|
| 118 | extern void byahoo_initmodule(); |
---|
| 119 | extern void jabber_initmodule(); |
---|
[7b23afd] | 120 | |
---|
[b7d3cc34] | 121 | #ifdef WITH_MSN |
---|
[0da65d5] | 122 | msn_initmodule(); |
---|
[b7d3cc34] | 123 | #endif |
---|
| 124 | |
---|
| 125 | #ifdef WITH_OSCAR |
---|
[0da65d5] | 126 | oscar_initmodule(); |
---|
[b7d3cc34] | 127 | #endif |
---|
| 128 | |
---|
| 129 | #ifdef WITH_YAHOO |
---|
[0da65d5] | 130 | byahoo_initmodule(); |
---|
[b7d3cc34] | 131 | #endif |
---|
| 132 | |
---|
| 133 | #ifdef WITH_JABBER |
---|
[0da65d5] | 134 | jabber_initmodule(); |
---|
[b7d3cc34] | 135 | #endif |
---|
[7b23afd] | 136 | |
---|
[65e2ce1] | 137 | #ifdef WITH_PLUGINS |
---|
| 138 | load_plugins(); |
---|
[b7d3cc34] | 139 | #endif |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | GSList *get_connections() { return connections; } |
---|
| 143 | |
---|
| 144 | /* multi.c */ |
---|
| 145 | |
---|
[84b045d] | 146 | struct im_connection *imcb_new( account_t *acc ) |
---|
[b7d3cc34] | 147 | { |
---|
[0da65d5] | 148 | struct im_connection *ic; |
---|
[b7d3cc34] | 149 | |
---|
[0da65d5] | 150 | ic = g_new0( struct im_connection, 1 ); |
---|
[b7d3cc34] | 151 | |
---|
[0da65d5] | 152 | ic->irc = acc->irc; |
---|
| 153 | ic->acc = acc; |
---|
| 154 | acc->ic = ic; |
---|
[b7d3cc34] | 155 | |
---|
[0da65d5] | 156 | connections = g_slist_append( connections, ic ); |
---|
[b7d3cc34] | 157 | |
---|
[0da65d5] | 158 | return( ic ); |
---|
[b7d3cc34] | 159 | } |
---|
| 160 | |
---|
[aef4828] | 161 | void imc_free( struct im_connection *ic ) |
---|
[b7d3cc34] | 162 | { |
---|
| 163 | account_t *a; |
---|
| 164 | |
---|
| 165 | /* Destroy the pointer to this connection from the account list */ |
---|
[0da65d5] | 166 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
| 167 | if( a->ic == ic ) |
---|
[b7d3cc34] | 168 | { |
---|
[0da65d5] | 169 | a->ic = NULL; |
---|
[b7d3cc34] | 170 | break; |
---|
| 171 | } |
---|
| 172 | |
---|
[0da65d5] | 173 | connections = g_slist_remove( connections, ic ); |
---|
| 174 | g_free( ic ); |
---|
[b7d3cc34] | 175 | } |
---|
| 176 | |
---|
[aef4828] | 177 | static void serv_got_crap( struct im_connection *ic, char *format, ... ) |
---|
[b7d3cc34] | 178 | { |
---|
| 179 | va_list params; |
---|
[e27661d] | 180 | char *text; |
---|
[dfde8e0] | 181 | account_t *a; |
---|
[b7d3cc34] | 182 | |
---|
| 183 | va_start( params, format ); |
---|
[e27661d] | 184 | text = g_strdup_vprintf( format, params ); |
---|
[b7d3cc34] | 185 | va_end( params ); |
---|
| 186 | |
---|
[0da65d5] | 187 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 188 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[e27661d] | 189 | strip_html( text ); |
---|
[b7d3cc34] | 190 | |
---|
[dfde8e0] | 191 | /* Try to find a different connection on the same protocol. */ |
---|
[0da65d5] | 192 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
| 193 | if( a->prpl == ic->acc->prpl && a->ic != ic ) |
---|
[dfde8e0] | 194 | break; |
---|
| 195 | |
---|
[e27661d] | 196 | /* If we found one, include the screenname in the message. */ |
---|
[dfde8e0] | 197 | if( a ) |
---|
[c2fb3809] | 198 | irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); |
---|
[dfde8e0] | 199 | else |
---|
[0da65d5] | 200 | irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text ); |
---|
[7b07dc6] | 201 | |
---|
[e27661d] | 202 | g_free( text ); |
---|
[b7d3cc34] | 203 | } |
---|
| 204 | |
---|
[84b045d] | 205 | void imcb_log( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 206 | { |
---|
| 207 | va_list params; |
---|
| 208 | char *text; |
---|
| 209 | |
---|
| 210 | va_start( params, format ); |
---|
| 211 | text = g_strdup_vprintf( format, params ); |
---|
| 212 | va_end( params ); |
---|
| 213 | |
---|
| 214 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 215 | serv_got_crap( ic, "%s", text ); |
---|
| 216 | else |
---|
| 217 | serv_got_crap( ic, "Logging in: %s", text ); |
---|
| 218 | |
---|
| 219 | g_free( text ); |
---|
| 220 | } |
---|
| 221 | |
---|
[84b045d] | 222 | void imcb_error( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 223 | { |
---|
| 224 | va_list params; |
---|
| 225 | char *text; |
---|
| 226 | |
---|
| 227 | va_start( params, format ); |
---|
| 228 | text = g_strdup_vprintf( format, params ); |
---|
| 229 | va_end( params ); |
---|
| 230 | |
---|
| 231 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 232 | serv_got_crap( ic, "Error: %s", text ); |
---|
| 233 | else |
---|
| 234 | serv_got_crap( ic, "Couldn't log in: %s", text ); |
---|
| 235 | |
---|
| 236 | g_free( text ); |
---|
| 237 | } |
---|
| 238 | |
---|
[ba9edaa] | 239 | static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 240 | { |
---|
[0da65d5] | 241 | struct im_connection *ic = d; |
---|
[b7d3cc34] | 242 | |
---|
[0da65d5] | 243 | if( ic->acc->prpl->keepalive ) |
---|
| 244 | ic->acc->prpl->keepalive( ic ); |
---|
[b7d3cc34] | 245 | |
---|
| 246 | return TRUE; |
---|
| 247 | } |
---|
| 248 | |
---|
[84b045d] | 249 | void imcb_connected( struct im_connection *ic ) |
---|
[b7d3cc34] | 250 | { |
---|
| 251 | user_t *u; |
---|
| 252 | |
---|
| 253 | /* MSN servers sometimes redirect you to a different server and do |
---|
[84c1a0a] | 254 | the whole login sequence again, so these "late" calls to this |
---|
[b7d3cc34] | 255 | function should be handled correctly. (IOW, ignored) */ |
---|
[0da65d5] | 256 | if( ic->flags & OPT_LOGGED_IN ) |
---|
[b7d3cc34] | 257 | return; |
---|
| 258 | |
---|
[0da65d5] | 259 | u = user_find( ic->irc, ic->irc->nick ); |
---|
[b7d3cc34] | 260 | |
---|
[84b045d] | 261 | imcb_log( ic, "Logged in" ); |
---|
[b7d3cc34] | 262 | |
---|
[0da65d5] | 263 | ic->keepalive = b_timeout_add( 60000, send_keepalive, ic ); |
---|
| 264 | ic->flags |= OPT_LOGGED_IN; |
---|
[b7d3cc34] | 265 | |
---|
[61dddd0] | 266 | /* Also necessary when we're not away, at least for some of the |
---|
| 267 | protocols. */ |
---|
[84b045d] | 268 | imc_set_away( ic, u->away ); |
---|
[b7d3cc34] | 269 | } |
---|
| 270 | |
---|
[ba9edaa] | 271 | gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 272 | { |
---|
| 273 | account_t *a = data; |
---|
| 274 | |
---|
| 275 | a->reconnect = 0; |
---|
| 276 | account_on( a->irc, a ); |
---|
| 277 | |
---|
| 278 | return( FALSE ); /* Only have to run the timeout once */ |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | void cancel_auto_reconnect( account_t *a ) |
---|
| 282 | { |
---|
[c98be00] | 283 | b_event_remove( a->reconnect ); |
---|
[b7d3cc34] | 284 | a->reconnect = 0; |
---|
| 285 | } |
---|
| 286 | |
---|
[c2fb3809] | 287 | void imc_logout( struct im_connection *ic, int allow_reconnect ) |
---|
[b7d3cc34] | 288 | { |
---|
[0da65d5] | 289 | irc_t *irc = ic->irc; |
---|
[c9c7ca7] | 290 | user_t *t, *u; |
---|
[b7d3cc34] | 291 | account_t *a; |
---|
| 292 | |
---|
[8d74291] | 293 | /* Nested calls might happen sometimes, this is probably the best |
---|
| 294 | place to catch them. */ |
---|
[0da65d5] | 295 | if( ic->flags & OPT_LOGGING_OUT ) |
---|
[8d74291] | 296 | return; |
---|
[66f783f] | 297 | else |
---|
[0da65d5] | 298 | ic->flags |= OPT_LOGGING_OUT; |
---|
[8d74291] | 299 | |
---|
[84b045d] | 300 | imcb_log( ic, "Signing off.." ); |
---|
[fb62f81f] | 301 | |
---|
[0da65d5] | 302 | b_event_remove( ic->keepalive ); |
---|
| 303 | ic->keepalive = 0; |
---|
| 304 | ic->acc->prpl->logout( ic ); |
---|
| 305 | b_event_remove( ic->inpa ); |
---|
[b7d3cc34] | 306 | |
---|
[c9c7ca7] | 307 | u = irc->users; |
---|
[b7d3cc34] | 308 | while( u ) |
---|
| 309 | { |
---|
[0da65d5] | 310 | if( u->ic == ic ) |
---|
[b7d3cc34] | 311 | { |
---|
| 312 | t = u->next; |
---|
| 313 | user_del( irc, u->nick ); |
---|
| 314 | u = t; |
---|
| 315 | } |
---|
| 316 | else |
---|
| 317 | u = u->next; |
---|
| 318 | } |
---|
| 319 | |
---|
[0da65d5] | 320 | query_del_by_conn( ic->irc, ic ); |
---|
[b7d3cc34] | 321 | |
---|
| 322 | for( a = irc->accounts; a; a = a->next ) |
---|
[0da65d5] | 323 | if( a->ic == ic ) |
---|
[b7d3cc34] | 324 | break; |
---|
| 325 | |
---|
| 326 | if( !a ) |
---|
| 327 | { |
---|
| 328 | /* Uhm... This is very sick. */ |
---|
| 329 | } |
---|
[c2fb3809] | 330 | else if( allow_reconnect && set_getbool( &irc->set, "auto_reconnect" ) && |
---|
[00a5270] | 331 | set_getbool( &a->set, "auto_reconnect" ) ) |
---|
[b7d3cc34] | 332 | { |
---|
[5c9512f] | 333 | int delay = set_getint( &irc->set, "auto_reconnect_delay" ); |
---|
[b7d3cc34] | 334 | |
---|
[84b045d] | 335 | imcb_log( ic, "Reconnecting in %d seconds..", delay ); |
---|
[c98be00] | 336 | a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a ); |
---|
[b7d3cc34] | 337 | } |
---|
| 338 | |
---|
[aef4828] | 339 | imc_free( ic ); |
---|
[b7d3cc34] | 340 | } |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | /* dialogs.c */ |
---|
| 344 | |
---|
[84b045d] | 345 | void imcb_ask( struct im_connection *ic, char *msg, void *data, void *doit, void *dont ) |
---|
[b7d3cc34] | 346 | { |
---|
[0da65d5] | 347 | query_add( ic->irc, ic, msg, doit, dont, data ); |
---|
[b7d3cc34] | 348 | } |
---|
| 349 | |
---|
| 350 | |
---|
| 351 | /* list.c */ |
---|
| 352 | |
---|
[f0cb961] | 353 | void imcb_add_buddy( struct im_connection *ic, char *handle, char *group ) |
---|
[b7d3cc34] | 354 | { |
---|
| 355 | user_t *u; |
---|
[f0cb961] | 356 | char nick[MAX_NICK_LENGTH+1], *s; |
---|
[0da65d5] | 357 | irc_t *irc = ic->irc; |
---|
[b7d3cc34] | 358 | |
---|
[0da65d5] | 359 | if( user_findhandle( ic, handle ) ) |
---|
[b7d3cc34] | 360 | { |
---|
[d5ccd83] | 361 | if( set_getbool( &irc->set, "debug" ) ) |
---|
[84b045d] | 362 | imcb_log( ic, "User already exists, ignoring add request: %s", handle ); |
---|
[b7d3cc34] | 363 | |
---|
| 364 | return; |
---|
| 365 | |
---|
[f0cb961] | 366 | /* Buddy seems to exist already. Let's ignore this request then... |
---|
| 367 | Eventually subsequent calls to this function *should* be possible |
---|
| 368 | when a buddy is in multiple groups. But for now BitlBee doesn't |
---|
| 369 | even support groups so let's silently ignore this for now. */ |
---|
[b7d3cc34] | 370 | } |
---|
| 371 | |
---|
| 372 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
[d323394c] | 373 | strcpy( nick, nick_get( ic->acc, handle ) ); |
---|
[b7d3cc34] | 374 | |
---|
[0da65d5] | 375 | u = user_add( ic->irc, nick ); |
---|
[b7d3cc34] | 376 | |
---|
[f0cb961] | 377 | // if( !realname || !*realname ) realname = nick; |
---|
| 378 | // u->realname = g_strdup( realname ); |
---|
[b7d3cc34] | 379 | |
---|
| 380 | if( ( s = strchr( handle, '@' ) ) ) |
---|
| 381 | { |
---|
| 382 | u->host = g_strdup( s + 1 ); |
---|
| 383 | u->user = g_strndup( handle, s - handle ); |
---|
| 384 | } |
---|
[0da65d5] | 385 | else if( ic->acc->server ) |
---|
[b7d3cc34] | 386 | { |
---|
[f0cb961] | 387 | u->host = g_strdup( ic->acc->server ); |
---|
[b7d3cc34] | 388 | u->user = g_strdup( handle ); |
---|
| 389 | |
---|
| 390 | /* s/ /_/ ... important for AOL screennames */ |
---|
| 391 | for( s = u->user; *s; s ++ ) |
---|
| 392 | if( *s == ' ' ) |
---|
| 393 | *s = '_'; |
---|
| 394 | } |
---|
| 395 | else |
---|
| 396 | { |
---|
[0da65d5] | 397 | u->host = g_strdup( ic->acc->prpl->name ); |
---|
[b7d3cc34] | 398 | u->user = g_strdup( handle ); |
---|
| 399 | } |
---|
| 400 | |
---|
[0da65d5] | 401 | u->ic = ic; |
---|
[b7d3cc34] | 402 | u->handle = g_strdup( handle ); |
---|
[9b8a38b] | 403 | if( group ) u->group = g_strdup( group ); |
---|
[b7d3cc34] | 404 | u->send_handler = buddy_send_handler; |
---|
| 405 | u->last_typing_notice = 0; |
---|
| 406 | } |
---|
| 407 | |
---|
[f0cb961] | 408 | struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle ) |
---|
[b7d3cc34] | 409 | { |
---|
| 410 | static struct buddy b[1]; |
---|
| 411 | user_t *u; |
---|
| 412 | |
---|
[0da65d5] | 413 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 414 | |
---|
| 415 | if( !u ) |
---|
| 416 | return( NULL ); |
---|
[9624fdf] | 417 | |
---|
[b7d3cc34] | 418 | memset( b, 0, sizeof( b ) ); |
---|
| 419 | strncpy( b->name, handle, 80 ); |
---|
| 420 | strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN ); |
---|
| 421 | b->present = u->online; |
---|
[0da65d5] | 422 | b->ic = u->ic; |
---|
[b7d3cc34] | 423 | |
---|
| 424 | return( b ); |
---|
| 425 | } |
---|
| 426 | |
---|
[f0cb961] | 427 | void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname ) |
---|
[b7d3cc34] | 428 | { |
---|
[0da65d5] | 429 | user_t *u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 430 | |
---|
[f0cb961] | 431 | if( !u || !realname ) return; |
---|
[b7d3cc34] | 432 | |
---|
[e27661d] | 433 | if( g_strcasecmp( u->realname, realname ) != 0 ) |
---|
[b7d3cc34] | 434 | { |
---|
| 435 | if( u->realname != u->nick ) g_free( u->realname ); |
---|
| 436 | |
---|
[e27661d] | 437 | u->realname = g_strdup( realname ); |
---|
[b7d3cc34] | 438 | |
---|
[0da65d5] | 439 | if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) ) |
---|
[84b045d] | 440 | imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); |
---|
[b7d3cc34] | 441 | } |
---|
| 442 | } |
---|
| 443 | |
---|
[998b103] | 444 | void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group ) |
---|
| 445 | { |
---|
| 446 | user_t *u; |
---|
| 447 | |
---|
| 448 | if( ( u = user_findhandle( ic, handle ) ) ) |
---|
| 449 | user_del( ic->irc, u->nick ); |
---|
| 450 | } |
---|
| 451 | |
---|
[d06eabf] | 452 | /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM |
---|
| 453 | modules to suggest a nickname for a handle. */ |
---|
| 454 | void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick ) |
---|
| 455 | { |
---|
| 456 | user_t *u = user_findhandle( ic, handle ); |
---|
[43d8cc5] | 457 | char newnick[MAX_NICK_LENGTH+1], *orig_nick; |
---|
[d06eabf] | 458 | |
---|
[e0e2a71] | 459 | if( u && !u->online && !nick_saved( ic->acc, handle ) ) |
---|
[d06eabf] | 460 | { |
---|
| 461 | /* Only do this if the person isn't online yet (which should |
---|
| 462 | be the case if we just added it) and if the user hasn't |
---|
| 463 | assigned a nickname to this buddy already. */ |
---|
| 464 | |
---|
[e0e2a71] | 465 | strncpy( newnick, nick, MAX_NICK_LENGTH ); |
---|
| 466 | newnick[MAX_NICK_LENGTH] = 0; |
---|
[d06eabf] | 467 | |
---|
| 468 | /* Some processing to make sure this string is a valid IRC nickname. */ |
---|
| 469 | nick_strip( newnick ); |
---|
| 470 | if( set_getbool( &ic->irc->set, "lcnicks" ) ) |
---|
| 471 | nick_lc( newnick ); |
---|
| 472 | |
---|
[1962ac1] | 473 | if( strcmp( u->nick, newnick ) != 0 ) |
---|
| 474 | { |
---|
| 475 | /* Only do this if newnick is different from the current one. |
---|
| 476 | If rejoining a channel, maybe we got this nick already |
---|
| 477 | (and dedupe would only add an underscore. */ |
---|
| 478 | nick_dedupe( ic->acc, handle, newnick ); |
---|
| 479 | |
---|
| 480 | /* u->nick will be freed halfway the process, so it can't be |
---|
| 481 | passed as an argument. */ |
---|
| 482 | orig_nick = g_strdup( u->nick ); |
---|
| 483 | user_rename( ic->irc, orig_nick, newnick ); |
---|
| 484 | g_free( orig_nick ); |
---|
| 485 | } |
---|
[d06eabf] | 486 | } |
---|
| 487 | } |
---|
[b7d3cc34] | 488 | |
---|
| 489 | /* prpl.c */ |
---|
| 490 | |
---|
[7bf0f5f0] | 491 | struct show_got_added_data |
---|
| 492 | { |
---|
[0da65d5] | 493 | struct im_connection *ic; |
---|
[7bf0f5f0] | 494 | char *handle; |
---|
| 495 | }; |
---|
| 496 | |
---|
| 497 | void show_got_added_no( gpointer w, struct show_got_added_data *data ) |
---|
| 498 | { |
---|
| 499 | g_free( data->handle ); |
---|
| 500 | g_free( data ); |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | void show_got_added_yes( gpointer w, struct show_got_added_data *data ) |
---|
| 504 | { |
---|
[0da65d5] | 505 | data->ic->acc->prpl->add_buddy( data->ic, data->handle, NULL ); |
---|
[f0cb961] | 506 | /* imcb_add_buddy( data->ic, NULL, data->handle, data->handle ); */ |
---|
[7bf0f5f0] | 507 | |
---|
| 508 | return show_got_added_no( w, data ); |
---|
| 509 | } |
---|
| 510 | |
---|
[84b045d] | 511 | void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname ) |
---|
[b7d3cc34] | 512 | { |
---|
[7bf0f5f0] | 513 | struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); |
---|
| 514 | char *s; |
---|
| 515 | |
---|
| 516 | /* TODO: Make a setting for this! */ |
---|
[0da65d5] | 517 | if( user_findhandle( ic, handle ) != NULL ) |
---|
[7bf0f5f0] | 518 | return; |
---|
| 519 | |
---|
| 520 | s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); |
---|
| 521 | |
---|
[0da65d5] | 522 | data->ic = ic; |
---|
[7bf0f5f0] | 523 | data->handle = g_strdup( handle ); |
---|
[0da65d5] | 524 | query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data ); |
---|
[b7d3cc34] | 525 | } |
---|
| 526 | |
---|
| 527 | |
---|
| 528 | /* server.c */ |
---|
| 529 | |
---|
[6bbb939] | 530 | void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ) |
---|
[b7d3cc34] | 531 | { |
---|
| 532 | user_t *u; |
---|
| 533 | int oa, oo; |
---|
| 534 | |
---|
[6bbb939] | 535 | u = user_findhandle( ic, (char*) handle ); |
---|
[b7d3cc34] | 536 | |
---|
| 537 | if( !u ) |
---|
| 538 | { |
---|
[0da65d5] | 539 | if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 ) |
---|
[b7d3cc34] | 540 | { |
---|
[f0cb961] | 541 | imcb_add_buddy( ic, (char*) handle, NULL ); |
---|
[6bbb939] | 542 | u = user_findhandle( ic, (char*) handle ); |
---|
[b7d3cc34] | 543 | } |
---|
| 544 | else |
---|
| 545 | { |
---|
[0da65d5] | 546 | if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 ) |
---|
[b7d3cc34] | 547 | { |
---|
[6bbb939] | 548 | imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle ); |
---|
| 549 | imcb_log( ic, "flags = %d, state = %s, message = %s", flags, |
---|
| 550 | state ? state : "NULL", message ? message : "NULL" ); |
---|
[b7d3cc34] | 551 | } |
---|
| 552 | |
---|
| 553 | return; |
---|
| 554 | } |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | oa = u->away != NULL; |
---|
| 558 | oo = u->online; |
---|
| 559 | |
---|
| 560 | if( u->away ) |
---|
| 561 | { |
---|
| 562 | g_free( u->away ); |
---|
| 563 | u->away = NULL; |
---|
| 564 | } |
---|
| 565 | |
---|
[6bbb939] | 566 | if( ( flags & OPT_LOGGED_IN ) && !u->online ) |
---|
[b7d3cc34] | 567 | { |
---|
[0da65d5] | 568 | irc_spawn( ic->irc, u ); |
---|
[b7d3cc34] | 569 | u->online = 1; |
---|
| 570 | } |
---|
[6bbb939] | 571 | else if( !( flags & OPT_LOGGED_IN ) && u->online ) |
---|
[b7d3cc34] | 572 | { |
---|
[0da65d5] | 573 | struct groupchat *c; |
---|
[b7d3cc34] | 574 | |
---|
[0da65d5] | 575 | irc_kill( ic->irc, u ); |
---|
[b7d3cc34] | 576 | u->online = 0; |
---|
| 577 | |
---|
[e35d1a1] | 578 | /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ |
---|
| 579 | for( c = ic->groupchats; c; c = c->next ) |
---|
[764b163d] | 580 | remove_chat_buddy_silent( c, handle ); |
---|
[b7d3cc34] | 581 | } |
---|
| 582 | |
---|
[6bbb939] | 583 | if( flags & OPT_AWAY ) |
---|
[b7d3cc34] | 584 | { |
---|
[6bbb939] | 585 | if( state && message ) |
---|
| 586 | { |
---|
| 587 | u->away = g_strdup_printf( "%s (%s)", state, message ); |
---|
| 588 | } |
---|
| 589 | else if( state ) |
---|
| 590 | { |
---|
| 591 | u->away = g_strdup( state ); |
---|
| 592 | } |
---|
| 593 | else if( message ) |
---|
| 594 | { |
---|
| 595 | u->away = g_strdup( message ); |
---|
| 596 | } |
---|
| 597 | else |
---|
| 598 | { |
---|
| 599 | u->away = g_strdup( "Away" ); |
---|
| 600 | } |
---|
[b7d3cc34] | 601 | } |
---|
[6bbb939] | 602 | /* else waste_any_state_information_for_now(); */ |
---|
[b7d3cc34] | 603 | |
---|
| 604 | /* LISPy... */ |
---|
[0da65d5] | 605 | if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ |
---|
[b7d3cc34] | 606 | ( u->online ) && /* Don't touch offline people */ |
---|
| 607 | ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ |
---|
| 608 | ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ |
---|
| 609 | { |
---|
[1186382] | 610 | char *from; |
---|
| 611 | |
---|
| 612 | if( set_getbool( &ic->irc->set, "simulate_netsplit" ) ) |
---|
| 613 | { |
---|
| 614 | from = g_strdup( ic->irc->myhost ); |
---|
| 615 | } |
---|
| 616 | else |
---|
| 617 | { |
---|
| 618 | from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick, |
---|
| 619 | ic->irc->myhost ); |
---|
| 620 | } |
---|
| 621 | irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, |
---|
| 622 | u->away?'-':'+', u->nick ); |
---|
| 623 | g_free( from ); |
---|
[b7d3cc34] | 624 | } |
---|
| 625 | } |
---|
| 626 | |
---|
[52744f8] | 627 | void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at ) |
---|
[b7d3cc34] | 628 | { |
---|
[0da65d5] | 629 | irc_t *irc = ic->irc; |
---|
[d444c09] | 630 | char *wrapped; |
---|
[b7d3cc34] | 631 | user_t *u; |
---|
| 632 | |
---|
[0da65d5] | 633 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 634 | |
---|
| 635 | if( !u ) |
---|
| 636 | { |
---|
[5c9512f] | 637 | char *h = set_getstr( &irc->set, "handle_unknown" ); |
---|
[b7d3cc34] | 638 | |
---|
| 639 | if( g_strcasecmp( h, "ignore" ) == 0 ) |
---|
| 640 | { |
---|
[d5ccd83] | 641 | if( set_getbool( &irc->set, "debug" ) ) |
---|
[84b045d] | 642 | imcb_log( ic, "Ignoring message from unknown handle %s", handle ); |
---|
[b7d3cc34] | 643 | |
---|
| 644 | return; |
---|
| 645 | } |
---|
| 646 | else if( g_strncasecmp( h, "add", 3 ) == 0 ) |
---|
| 647 | { |
---|
[d5ccd83] | 648 | int private = set_getbool( &irc->set, "private" ); |
---|
[b7d3cc34] | 649 | |
---|
| 650 | if( h[3] ) |
---|
| 651 | { |
---|
| 652 | if( g_strcasecmp( h + 3, "_private" ) == 0 ) |
---|
| 653 | private = 1; |
---|
| 654 | else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) |
---|
| 655 | private = 0; |
---|
| 656 | } |
---|
| 657 | |
---|
[f0cb961] | 658 | imcb_add_buddy( ic, handle, NULL ); |
---|
[0da65d5] | 659 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 660 | u->is_private = private; |
---|
| 661 | } |
---|
| 662 | else |
---|
| 663 | { |
---|
[84b045d] | 664 | imcb_log( ic, "Message from unknown handle %s:", handle ); |
---|
[b7d3cc34] | 665 | u = user_find( irc, irc->mynick ); |
---|
| 666 | } |
---|
| 667 | } |
---|
| 668 | |
---|
[0da65d5] | 669 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 670 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[b7d3cc34] | 671 | strip_html( msg ); |
---|
| 672 | |
---|
[d444c09] | 673 | wrapped = word_wrap( msg, 425 ); |
---|
| 674 | irc_msgfrom( irc, u->nick, wrapped ); |
---|
| 675 | g_free( wrapped ); |
---|
[b7d3cc34] | 676 | } |
---|
| 677 | |
---|
[52744f8] | 678 | void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags ) |
---|
[b7d3cc34] | 679 | { |
---|
| 680 | user_t *u; |
---|
| 681 | |
---|
[0da65d5] | 682 | if( !set_getbool( &ic->irc->set, "typing_notice" ) ) |
---|
[b7d3cc34] | 683 | return; |
---|
| 684 | |
---|
[9624fdf] | 685 | if( ( u = user_findhandle( ic, handle ) ) ) |
---|
| 686 | { |
---|
| 687 | char buf[256]; |
---|
| 688 | |
---|
| 689 | g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 ); |
---|
| 690 | irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf ); |
---|
[e7f46c5] | 691 | } |
---|
[b7d3cc34] | 692 | } |
---|
| 693 | |
---|
[83ba3e5] | 694 | struct groupchat *imcb_chat_new( struct im_connection *ic, char *handle ) |
---|
| 695 | { |
---|
| 696 | struct groupchat *c; |
---|
| 697 | |
---|
| 698 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
| 699 | |
---|
| 700 | if( ic->groupchats ) |
---|
| 701 | { |
---|
| 702 | for( c = ic->groupchats; c->next; c = c->next ); |
---|
| 703 | c = c->next = g_new0( struct groupchat, 1 ); |
---|
| 704 | } |
---|
| 705 | else |
---|
| 706 | ic->groupchats = c = g_new0( struct groupchat, 1 ); |
---|
| 707 | |
---|
| 708 | c->ic = ic; |
---|
| 709 | c->title = g_strdup( handle ); |
---|
| 710 | c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ ); |
---|
| 711 | c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
| 712 | |
---|
| 713 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
| 714 | imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle ); |
---|
| 715 | |
---|
| 716 | return c; |
---|
| 717 | } |
---|
| 718 | |
---|
[e35d1a1] | 719 | void imcb_chat_free( struct groupchat *c ) |
---|
[b7d3cc34] | 720 | { |
---|
[0da65d5] | 721 | struct im_connection *ic = c->ic; |
---|
[e35d1a1] | 722 | struct groupchat *l; |
---|
[b7d3cc34] | 723 | GList *ir; |
---|
| 724 | |
---|
[0da65d5] | 725 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
[56f260a] | 726 | imcb_log( ic, "You were removed from conversation %p", c ); |
---|
[b7d3cc34] | 727 | |
---|
| 728 | if( c ) |
---|
| 729 | { |
---|
| 730 | if( c->joined ) |
---|
| 731 | { |
---|
| 732 | user_t *u, *r; |
---|
| 733 | |
---|
[0da65d5] | 734 | r = user_find( ic->irc, ic->irc->mynick ); |
---|
| 735 | irc_privmsg( ic->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
[b7d3cc34] | 736 | |
---|
[0da65d5] | 737 | u = user_find( ic->irc, ic->irc->nick ); |
---|
| 738 | irc_kick( ic->irc, u, c->channel, r ); |
---|
| 739 | /* irc_part( ic->irc, u, c->channel ); */ |
---|
[b7d3cc34] | 740 | } |
---|
| 741 | |
---|
[e35d1a1] | 742 | /* Find the previous chat in the linked list. */ |
---|
| 743 | for( l = ic->groupchats; l && l->next != c; l = l->next ); |
---|
| 744 | |
---|
[b7d3cc34] | 745 | if( l ) |
---|
| 746 | l->next = c->next; |
---|
| 747 | else |
---|
[e35d1a1] | 748 | ic->groupchats = c->next; |
---|
[b7d3cc34] | 749 | |
---|
| 750 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
| 751 | g_free( ir->data ); |
---|
| 752 | g_list_free( c->in_room ); |
---|
| 753 | g_free( c->channel ); |
---|
| 754 | g_free( c->title ); |
---|
[83ba3e5] | 755 | g_free( c->topic ); |
---|
[b7d3cc34] | 756 | g_free( c ); |
---|
| 757 | } |
---|
| 758 | } |
---|
| 759 | |
---|
[52744f8] | 760 | void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at ) |
---|
[b7d3cc34] | 761 | { |
---|
[0da65d5] | 762 | struct im_connection *ic = c->ic; |
---|
[d444c09] | 763 | char *wrapped; |
---|
[b7d3cc34] | 764 | user_t *u; |
---|
| 765 | |
---|
| 766 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
[c2fb3809] | 767 | if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 768 | return; |
---|
| 769 | |
---|
[0da65d5] | 770 | u = user_findhandle( ic, who ); |
---|
[b7d3cc34] | 771 | |
---|
[0da65d5] | 772 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 773 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[b7d3cc34] | 774 | strip_html( msg ); |
---|
| 775 | |
---|
[d444c09] | 776 | wrapped = word_wrap( msg, 425 ); |
---|
[b7d3cc34] | 777 | if( c && u ) |
---|
[d444c09] | 778 | { |
---|
| 779 | irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped ); |
---|
| 780 | } |
---|
[b7d3cc34] | 781 | else |
---|
[d444c09] | 782 | { |
---|
[56f260a] | 783 | imcb_log( ic, "Message from/to conversation %s@%p (unknown conv/user): %s", who, c, wrapped ); |
---|
[d444c09] | 784 | } |
---|
| 785 | g_free( wrapped ); |
---|
[b7d3cc34] | 786 | } |
---|
| 787 | |
---|
[31e5846] | 788 | void imcb_chat_log( struct groupchat *c, char *format, ... ) |
---|
| 789 | { |
---|
| 790 | irc_t *irc = c->ic->irc; |
---|
| 791 | va_list params; |
---|
| 792 | char *text; |
---|
| 793 | user_t *u; |
---|
| 794 | |
---|
| 795 | va_start( params, format ); |
---|
| 796 | text = g_strdup_vprintf( format, params ); |
---|
| 797 | va_end( params ); |
---|
| 798 | |
---|
| 799 | u = user_find( irc, irc->mynick ); |
---|
| 800 | |
---|
| 801 | irc_privmsg( irc, u, "PRIVMSG", c->channel, "System message: ", text ); |
---|
| 802 | |
---|
| 803 | g_free( text ); |
---|
| 804 | } |
---|
| 805 | |
---|
[ef5c185] | 806 | void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at ) |
---|
[50e1776] | 807 | { |
---|
| 808 | struct im_connection *ic = c->ic; |
---|
| 809 | user_t *u = NULL; |
---|
| 810 | |
---|
| 811 | if( who == NULL) |
---|
[ef5c185] | 812 | u = user_find( ic->irc, ic->irc->mynick ); |
---|
[50e1776] | 813 | else if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
[ef5c185] | 814 | u = user_find( ic->irc, ic->irc->nick ); |
---|
[50e1776] | 815 | else |
---|
| 816 | u = user_findhandle( ic, who ); |
---|
| 817 | |
---|
| 818 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
| 819 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
| 820 | strip_html( topic ); |
---|
| 821 | |
---|
| 822 | g_free( c->topic ); |
---|
| 823 | c->topic = g_strdup( topic ); |
---|
| 824 | |
---|
| 825 | if( c->joined && u ) |
---|
| 826 | irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic ); |
---|
| 827 | } |
---|
| 828 | |
---|
[b7d3cc34] | 829 | |
---|
| 830 | /* buddy_chat.c */ |
---|
| 831 | |
---|
[61ae52c] | 832 | void imcb_chat_add_buddy( struct groupchat *b, char *handle ) |
---|
[b7d3cc34] | 833 | { |
---|
[0da65d5] | 834 | user_t *u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 835 | int me = 0; |
---|
| 836 | |
---|
[0da65d5] | 837 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
[56f260a] | 838 | imcb_log( b->ic, "User %s added to conversation %p", handle, b ); |
---|
[b7d3cc34] | 839 | |
---|
| 840 | /* It might be yourself! */ |
---|
[c2fb3809] | 841 | if( b->ic->acc->prpl->handle_cmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 842 | { |
---|
[0da65d5] | 843 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 844 | if( !b->joined ) |
---|
[0da65d5] | 845 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 846 | b->joined = me = 1; |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | /* Most protocols allow people to join, even when they're not in |
---|
| 850 | your contact list. Try to handle that here */ |
---|
| 851 | if( !u ) |
---|
| 852 | { |
---|
[f0cb961] | 853 | imcb_add_buddy( b->ic, handle, NULL ); |
---|
[0da65d5] | 854 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 855 | } |
---|
| 856 | |
---|
| 857 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
| 858 | if( !me ) |
---|
| 859 | { |
---|
| 860 | if( b->joined ) |
---|
[0da65d5] | 861 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 862 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
| 863 | } |
---|
| 864 | } |
---|
| 865 | |
---|
[2d317bb] | 866 | /* This function is one BIG hack... :-( EREWRITE */ |
---|
[61ae52c] | 867 | void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason ) |
---|
[b7d3cc34] | 868 | { |
---|
| 869 | user_t *u; |
---|
| 870 | int me = 0; |
---|
| 871 | |
---|
[0da65d5] | 872 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
[56f260a] | 873 | imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" ); |
---|
[b7d3cc34] | 874 | |
---|
| 875 | /* It might be yourself! */ |
---|
[c2fb3809] | 876 | if( g_strcasecmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 877 | { |
---|
[2d317bb] | 878 | if( b->joined == 0 ) |
---|
| 879 | return; |
---|
| 880 | |
---|
[0da65d5] | 881 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 882 | b->joined = 0; |
---|
| 883 | me = 1; |
---|
| 884 | } |
---|
| 885 | else |
---|
| 886 | { |
---|
[0da65d5] | 887 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 888 | } |
---|
| 889 | |
---|
[2d317bb] | 890 | if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) ) |
---|
| 891 | irc_part( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 892 | } |
---|
| 893 | |
---|
[764b163d] | 894 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ) |
---|
[b7d3cc34] | 895 | { |
---|
| 896 | GList *i; |
---|
| 897 | |
---|
| 898 | /* Find the handle in the room userlist and shoot it */ |
---|
| 899 | i = b->in_room; |
---|
| 900 | while( i ) |
---|
| 901 | { |
---|
| 902 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
| 903 | { |
---|
| 904 | g_free( i->data ); |
---|
| 905 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
| 906 | return( 1 ); |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | i = i->next; |
---|
| 910 | } |
---|
| 911 | |
---|
| 912 | return( 0 ); |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | |
---|
| 916 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
| 917 | |
---|
[5c9512f] | 918 | char *set_eval_away_devoice( set_t *set, char *value ) |
---|
[b7d3cc34] | 919 | { |
---|
[5c9512f] | 920 | irc_t *irc = set->data; |
---|
[b7d3cc34] | 921 | int st; |
---|
| 922 | |
---|
| 923 | if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) |
---|
| 924 | st = 1; |
---|
| 925 | else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) |
---|
| 926 | st = 0; |
---|
| 927 | else if( sscanf( value, "%d", &st ) != 1 ) |
---|
| 928 | return( NULL ); |
---|
| 929 | |
---|
| 930 | st = st != 0; |
---|
| 931 | |
---|
| 932 | /* Horror.... */ |
---|
| 933 | |
---|
[d5ccd83] | 934 | if( st != set_getbool( &irc->set, "away_devoice" ) ) |
---|
[b7d3cc34] | 935 | { |
---|
| 936 | char list[80] = ""; |
---|
| 937 | user_t *u = irc->users; |
---|
| 938 | int i = 0, count = 0; |
---|
| 939 | char pm; |
---|
| 940 | char v[80]; |
---|
| 941 | |
---|
| 942 | if( st ) |
---|
| 943 | pm = '+'; |
---|
| 944 | else |
---|
| 945 | pm = '-'; |
---|
| 946 | |
---|
| 947 | while( u ) |
---|
| 948 | { |
---|
[0da65d5] | 949 | if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 950 | { |
---|
| 951 | if( ( strlen( list ) + strlen( u->nick ) ) >= 79 ) |
---|
| 952 | { |
---|
| 953 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 954 | irc_write( irc, ":%s MODE %s %c%s%s", |
---|
| 955 | irc->myhost, |
---|
[b7d3cc34] | 956 | irc->channel, pm, v, list ); |
---|
| 957 | |
---|
| 958 | *list = 0; |
---|
| 959 | count = 0; |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | sprintf( list + strlen( list ), " %s", u->nick ); |
---|
| 963 | count ++; |
---|
| 964 | } |
---|
| 965 | u = u->next; |
---|
| 966 | } |
---|
| 967 | |
---|
| 968 | /* $v = 'v' x $i */ |
---|
| 969 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 970 | irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost, |
---|
[b7d3cc34] | 971 | irc->channel, pm, v, list ); |
---|
| 972 | } |
---|
| 973 | |
---|
[5c9512f] | 974 | return( set_eval_bool( set, value ) ); |
---|
[b7d3cc34] | 975 | } |
---|
| 976 | |
---|
[226fce1] | 977 | |
---|
| 978 | |
---|
| 979 | |
---|
| 980 | /* The plan is to not allow straight calls to prpl functions anymore, but do |
---|
| 981 | them all from some wrappers. We'll start to define some down here: */ |
---|
| 982 | |
---|
[84b045d] | 983 | int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags ) |
---|
[b7d3cc34] | 984 | { |
---|
[e27661d] | 985 | char *buf = NULL; |
---|
| 986 | int st; |
---|
[b7d3cc34] | 987 | |
---|
[6bbb939] | 988 | if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[c572dd6] | 989 | { |
---|
[e27661d] | 990 | buf = escape_html( msg ); |
---|
[c572dd6] | 991 | msg = buf; |
---|
[b7d3cc34] | 992 | } |
---|
| 993 | |
---|
[f6c963b] | 994 | st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags ); |
---|
[e27661d] | 995 | g_free( buf ); |
---|
| 996 | |
---|
| 997 | return st; |
---|
[b7d3cc34] | 998 | } |
---|
| 999 | |
---|
[84b045d] | 1000 | int imc_chat_msg( struct groupchat *c, char *msg, int flags ) |
---|
[b7d3cc34] | 1001 | { |
---|
[e27661d] | 1002 | char *buf = NULL; |
---|
[b7d3cc34] | 1003 | |
---|
[6bbb939] | 1004 | if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[e27661d] | 1005 | { |
---|
| 1006 | buf = escape_html( msg ); |
---|
[b7d3cc34] | 1007 | msg = buf; |
---|
| 1008 | } |
---|
| 1009 | |
---|
[f6c963b] | 1010 | c->ic->acc->prpl->chat_msg( c, msg, flags ); |
---|
[e27661d] | 1011 | g_free( buf ); |
---|
| 1012 | |
---|
[0da65d5] | 1013 | return 1; |
---|
[b7d3cc34] | 1014 | } |
---|
[226fce1] | 1015 | |
---|
[84b045d] | 1016 | static char *imc_away_alias_find( GList *gcm, char *away ); |
---|
[226fce1] | 1017 | |
---|
[84b045d] | 1018 | int imc_set_away( struct im_connection *ic, char *away ) |
---|
[226fce1] | 1019 | { |
---|
| 1020 | GList *m, *ms; |
---|
| 1021 | char *s; |
---|
| 1022 | |
---|
| 1023 | if( !away ) away = ""; |
---|
[0da65d5] | 1024 | ms = m = ic->acc->prpl->away_states( ic ); |
---|
[226fce1] | 1025 | |
---|
| 1026 | while( m ) |
---|
| 1027 | { |
---|
| 1028 | if( *away ) |
---|
| 1029 | { |
---|
| 1030 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
| 1031 | break; |
---|
| 1032 | } |
---|
| 1033 | else |
---|
| 1034 | { |
---|
| 1035 | if( g_strcasecmp( m->data, "Available" ) == 0 ) |
---|
| 1036 | break; |
---|
| 1037 | if( g_strcasecmp( m->data, "Online" ) == 0 ) |
---|
| 1038 | break; |
---|
| 1039 | } |
---|
| 1040 | m = m->next; |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | if( m ) |
---|
| 1044 | { |
---|
[0da65d5] | 1045 | ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL ); |
---|
[226fce1] | 1046 | } |
---|
| 1047 | else |
---|
| 1048 | { |
---|
[84b045d] | 1049 | s = imc_away_alias_find( ms, away ); |
---|
[226fce1] | 1050 | if( s ) |
---|
| 1051 | { |
---|
[0da65d5] | 1052 | ic->acc->prpl->set_away( ic, s, away ); |
---|
| 1053 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
[84b045d] | 1054 | imcb_log( ic, "Setting away state to %s", s ); |
---|
[226fce1] | 1055 | } |
---|
| 1056 | else |
---|
[0da65d5] | 1057 | ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away ); |
---|
[226fce1] | 1058 | } |
---|
| 1059 | |
---|
| 1060 | return( 1 ); |
---|
| 1061 | } |
---|
| 1062 | |
---|
[84b045d] | 1063 | static char *imc_away_alias_list[8][5] = |
---|
[226fce1] | 1064 | { |
---|
| 1065 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
| 1066 | { "NA", "N/A", "Not available", NULL }, |
---|
| 1067 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
| 1068 | { "Be right back", "BRB", NULL }, |
---|
| 1069 | { "On the phone", "Phone", "On phone", NULL }, |
---|
| 1070 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
| 1071 | { "Invisible", "Hidden" }, |
---|
| 1072 | { NULL } |
---|
| 1073 | }; |
---|
| 1074 | |
---|
[84b045d] | 1075 | static char *imc_away_alias_find( GList *gcm, char *away ) |
---|
[226fce1] | 1076 | { |
---|
| 1077 | GList *m; |
---|
| 1078 | int i, j; |
---|
| 1079 | |
---|
[84b045d] | 1080 | for( i = 0; *imc_away_alias_list[i]; i ++ ) |
---|
[226fce1] | 1081 | { |
---|
[84b045d] | 1082 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
| 1083 | if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) |
---|
[226fce1] | 1084 | break; |
---|
| 1085 | |
---|
[84b045d] | 1086 | if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ |
---|
[226fce1] | 1087 | continue; /* is not what we want. Next! */ |
---|
| 1088 | |
---|
| 1089 | /* Now find an entry in this row which exists in gcm */ |
---|
[84b045d] | 1090 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
[226fce1] | 1091 | { |
---|
| 1092 | m = gcm; |
---|
| 1093 | while( m ) |
---|
| 1094 | { |
---|
[84b045d] | 1095 | if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) |
---|
| 1096 | return( imc_away_alias_list[i][j] ); |
---|
[226fce1] | 1097 | m = m->next; |
---|
| 1098 | } |
---|
| 1099 | } |
---|
| 1100 | } |
---|
| 1101 | |
---|
| 1102 | return( NULL ); |
---|
| 1103 | } |
---|
[da3b536] | 1104 | |
---|
[84b045d] | 1105 | void imc_add_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1106 | { |
---|
[0da65d5] | 1107 | if( g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 1108 | { |
---|
[0da65d5] | 1109 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
[da3b536] | 1110 | } |
---|
| 1111 | |
---|
[0da65d5] | 1112 | ic->acc->prpl->add_permit( ic, handle ); |
---|
[da3b536] | 1113 | } |
---|
| 1114 | |
---|
[84b045d] | 1115 | void imc_rem_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1116 | { |
---|
| 1117 | GSList *l; |
---|
| 1118 | |
---|
[0da65d5] | 1119 | if( ( l = g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 1120 | { |
---|
| 1121 | g_free( l->data ); |
---|
[0da65d5] | 1122 | ic->permit = g_slist_delete_link( ic->permit, l ); |
---|
[da3b536] | 1123 | } |
---|
| 1124 | |
---|
[0da65d5] | 1125 | ic->acc->prpl->rem_permit( ic, handle ); |
---|
[da3b536] | 1126 | } |
---|
| 1127 | |
---|
[84b045d] | 1128 | void imc_add_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1129 | { |
---|
[0da65d5] | 1130 | if( g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 1131 | { |
---|
[0da65d5] | 1132 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
[da3b536] | 1133 | } |
---|
| 1134 | |
---|
[0da65d5] | 1135 | ic->acc->prpl->add_deny( ic, handle ); |
---|
[da3b536] | 1136 | } |
---|
| 1137 | |
---|
[84b045d] | 1138 | void imc_rem_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1139 | { |
---|
| 1140 | GSList *l; |
---|
| 1141 | |
---|
[0da65d5] | 1142 | if( ( l = g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 1143 | { |
---|
| 1144 | g_free( l->data ); |
---|
[0da65d5] | 1145 | ic->deny = g_slist_delete_link( ic->deny, l ); |
---|
[da3b536] | 1146 | } |
---|
| 1147 | |
---|
[0da65d5] | 1148 | ic->acc->prpl->rem_deny( ic, handle ); |
---|
[da3b536] | 1149 | } |
---|
[85023c6] | 1150 | |
---|
| 1151 | void imcb_clean_handle( struct im_connection *ic, char *handle ) |
---|
| 1152 | { |
---|
| 1153 | /* Accepts a handle and does whatever is necessary to make it |
---|
| 1154 | BitlBee-friendly. Currently this means removing everything |
---|
| 1155 | outside 33-127 (ASCII printable excl spaces), @ (only one |
---|
| 1156 | is allowed) and ! and : */ |
---|
| 1157 | char out[strlen(handle)+1]; |
---|
| 1158 | int s, d; |
---|
| 1159 | |
---|
| 1160 | s = d = 0; |
---|
| 1161 | while( handle[s] ) |
---|
| 1162 | { |
---|
| 1163 | if( handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' && |
---|
| 1164 | ( handle[s] & 0x80 ) == 0 ) |
---|
| 1165 | { |
---|
| 1166 | if( handle[s] == '@' ) |
---|
| 1167 | { |
---|
| 1168 | /* See if we got an @ already? */ |
---|
| 1169 | out[d] = 0; |
---|
| 1170 | if( strchr( out, '@' ) ) |
---|
| 1171 | continue; |
---|
| 1172 | } |
---|
| 1173 | |
---|
| 1174 | out[d++] = handle[s]; |
---|
| 1175 | } |
---|
| 1176 | s ++; |
---|
| 1177 | } |
---|
| 1178 | out[d] = handle[s]; |
---|
| 1179 | |
---|
| 1180 | strcpy( handle, out ); |
---|
| 1181 | } |
---|