[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 | |
---|
[0da65d5] | 38 | static int remove_chat_buddy_silent( struct groupchat *b, 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) { |
---|
| 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 | { |
---|
[0da65d5] | 117 | extern void msn_initmodule(); |
---|
| 118 | extern void oscar_initmodule(); |
---|
| 119 | extern void byahoo_initmodule(); |
---|
| 120 | extern void jabber_initmodule(); |
---|
[7b23afd] | 121 | |
---|
[b7d3cc34] | 122 | #ifdef WITH_MSN |
---|
[0da65d5] | 123 | msn_initmodule(); |
---|
[b7d3cc34] | 124 | #endif |
---|
| 125 | |
---|
| 126 | #ifdef WITH_OSCAR |
---|
[0da65d5] | 127 | oscar_initmodule(); |
---|
[b7d3cc34] | 128 | #endif |
---|
| 129 | |
---|
| 130 | #ifdef WITH_YAHOO |
---|
[0da65d5] | 131 | byahoo_initmodule(); |
---|
[b7d3cc34] | 132 | #endif |
---|
| 133 | |
---|
| 134 | #ifdef WITH_JABBER |
---|
[0da65d5] | 135 | jabber_initmodule(); |
---|
[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 | |
---|
[84b045d] | 147 | struct im_connection *imcb_new( account_t *acc ) |
---|
[b7d3cc34] | 148 | { |
---|
[0da65d5] | 149 | struct im_connection *ic; |
---|
[b7d3cc34] | 150 | |
---|
[0da65d5] | 151 | ic = g_new0( struct im_connection, 1 ); |
---|
[b7d3cc34] | 152 | |
---|
[0da65d5] | 153 | ic->irc = acc->irc; |
---|
| 154 | ic->acc = acc; |
---|
| 155 | acc->ic = ic; |
---|
[b7d3cc34] | 156 | |
---|
[0da65d5] | 157 | connections = g_slist_append( connections, ic ); |
---|
[b7d3cc34] | 158 | |
---|
[0da65d5] | 159 | return( ic ); |
---|
[b7d3cc34] | 160 | } |
---|
| 161 | |
---|
[aef4828] | 162 | void imc_free( struct im_connection *ic ) |
---|
[b7d3cc34] | 163 | { |
---|
| 164 | account_t *a; |
---|
| 165 | |
---|
| 166 | /* Destroy the pointer to this connection from the account list */ |
---|
[0da65d5] | 167 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
| 168 | if( a->ic == ic ) |
---|
[b7d3cc34] | 169 | { |
---|
[0da65d5] | 170 | a->ic = NULL; |
---|
[b7d3cc34] | 171 | break; |
---|
| 172 | } |
---|
| 173 | |
---|
[0da65d5] | 174 | connections = g_slist_remove( connections, ic ); |
---|
| 175 | g_free( ic ); |
---|
[b7d3cc34] | 176 | } |
---|
| 177 | |
---|
[aef4828] | 178 | static void serv_got_crap( struct im_connection *ic, char *format, ... ) |
---|
[b7d3cc34] | 179 | { |
---|
| 180 | va_list params; |
---|
[e27661d] | 181 | char *text; |
---|
[dfde8e0] | 182 | account_t *a; |
---|
[b7d3cc34] | 183 | |
---|
| 184 | va_start( params, format ); |
---|
[e27661d] | 185 | text = g_strdup_vprintf( format, params ); |
---|
[b7d3cc34] | 186 | va_end( params ); |
---|
| 187 | |
---|
[0da65d5] | 188 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 189 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[e27661d] | 190 | strip_html( text ); |
---|
[b7d3cc34] | 191 | |
---|
[dfde8e0] | 192 | /* Try to find a different connection on the same protocol. */ |
---|
[0da65d5] | 193 | for( a = ic->irc->accounts; a; a = a->next ) |
---|
| 194 | if( a->prpl == ic->acc->prpl && a->ic != ic ) |
---|
[dfde8e0] | 195 | break; |
---|
| 196 | |
---|
[e27661d] | 197 | /* If we found one, include the screenname in the message. */ |
---|
[dfde8e0] | 198 | if( a ) |
---|
[c2fb3809] | 199 | irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); |
---|
[dfde8e0] | 200 | else |
---|
[0da65d5] | 201 | irc_usermsg( ic->irc, "%s - %s", ic->acc->prpl->name, text ); |
---|
[7b07dc6] | 202 | |
---|
[e27661d] | 203 | g_free( text ); |
---|
[b7d3cc34] | 204 | } |
---|
| 205 | |
---|
[84b045d] | 206 | void imcb_log( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 207 | { |
---|
| 208 | va_list params; |
---|
| 209 | char *text; |
---|
| 210 | |
---|
| 211 | va_start( params, format ); |
---|
| 212 | text = g_strdup_vprintf( format, params ); |
---|
| 213 | va_end( params ); |
---|
| 214 | |
---|
| 215 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 216 | serv_got_crap( ic, "%s", text ); |
---|
| 217 | else |
---|
| 218 | serv_got_crap( ic, "Logging in: %s", text ); |
---|
| 219 | |
---|
| 220 | g_free( text ); |
---|
| 221 | } |
---|
| 222 | |
---|
[84b045d] | 223 | void imcb_error( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 224 | { |
---|
| 225 | va_list params; |
---|
| 226 | char *text; |
---|
| 227 | |
---|
| 228 | va_start( params, format ); |
---|
| 229 | text = g_strdup_vprintf( format, params ); |
---|
| 230 | va_end( params ); |
---|
| 231 | |
---|
| 232 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 233 | serv_got_crap( ic, "Error: %s", text ); |
---|
| 234 | else |
---|
| 235 | serv_got_crap( ic, "Couldn't log in: %s", text ); |
---|
| 236 | |
---|
| 237 | g_free( text ); |
---|
| 238 | } |
---|
| 239 | |
---|
[ba9edaa] | 240 | static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 241 | { |
---|
[0da65d5] | 242 | struct im_connection *ic = d; |
---|
[b7d3cc34] | 243 | |
---|
[0da65d5] | 244 | if( ic->acc->prpl->keepalive ) |
---|
| 245 | ic->acc->prpl->keepalive( ic ); |
---|
[b7d3cc34] | 246 | |
---|
| 247 | return TRUE; |
---|
| 248 | } |
---|
| 249 | |
---|
[84b045d] | 250 | void imcb_connected( struct im_connection *ic ) |
---|
[b7d3cc34] | 251 | { |
---|
| 252 | user_t *u; |
---|
| 253 | |
---|
| 254 | /* MSN servers sometimes redirect you to a different server and do |
---|
[84c1a0a] | 255 | the whole login sequence again, so these "late" calls to this |
---|
[b7d3cc34] | 256 | function should be handled correctly. (IOW, ignored) */ |
---|
[0da65d5] | 257 | if( ic->flags & OPT_LOGGED_IN ) |
---|
[b7d3cc34] | 258 | return; |
---|
| 259 | |
---|
[0da65d5] | 260 | u = user_find( ic->irc, ic->irc->nick ); |
---|
[b7d3cc34] | 261 | |
---|
[84b045d] | 262 | imcb_log( ic, "Logged in" ); |
---|
[b7d3cc34] | 263 | |
---|
[0da65d5] | 264 | ic->keepalive = b_timeout_add( 60000, send_keepalive, ic ); |
---|
| 265 | ic->flags |= OPT_LOGGED_IN; |
---|
[b7d3cc34] | 266 | |
---|
[61dddd0] | 267 | /* Also necessary when we're not away, at least for some of the |
---|
| 268 | protocols. */ |
---|
[84b045d] | 269 | imc_set_away( ic, u->away ); |
---|
[b7d3cc34] | 270 | } |
---|
| 271 | |
---|
[ba9edaa] | 272 | gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 273 | { |
---|
| 274 | account_t *a = data; |
---|
| 275 | |
---|
| 276 | a->reconnect = 0; |
---|
| 277 | account_on( a->irc, a ); |
---|
| 278 | |
---|
| 279 | return( FALSE ); /* Only have to run the timeout once */ |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | void cancel_auto_reconnect( account_t *a ) |
---|
| 283 | { |
---|
[c98be00] | 284 | b_event_remove( a->reconnect ); |
---|
[b7d3cc34] | 285 | a->reconnect = 0; |
---|
| 286 | } |
---|
| 287 | |
---|
[c2fb3809] | 288 | void imc_logout( struct im_connection *ic, int allow_reconnect ) |
---|
[b7d3cc34] | 289 | { |
---|
[0da65d5] | 290 | irc_t *irc = ic->irc; |
---|
[b7d3cc34] | 291 | user_t *t, *u = irc->users; |
---|
| 292 | account_t *a; |
---|
| 293 | |
---|
[8d74291] | 294 | /* Nested calls might happen sometimes, this is probably the best |
---|
| 295 | place to catch them. */ |
---|
[0da65d5] | 296 | if( ic->flags & OPT_LOGGING_OUT ) |
---|
[8d74291] | 297 | return; |
---|
[66f783f] | 298 | else |
---|
[0da65d5] | 299 | ic->flags |= OPT_LOGGING_OUT; |
---|
[8d74291] | 300 | |
---|
[84b045d] | 301 | imcb_log( ic, "Signing off.." ); |
---|
[fb62f81f] | 302 | |
---|
[0da65d5] | 303 | b_event_remove( ic->keepalive ); |
---|
| 304 | ic->keepalive = 0; |
---|
| 305 | ic->acc->prpl->logout( ic ); |
---|
| 306 | b_event_remove( ic->inpa ); |
---|
[b7d3cc34] | 307 | |
---|
| 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 | |
---|
| 473 | nick_dedupe( ic->acc, handle, newnick ); |
---|
| 474 | |
---|
[43d8cc5] | 475 | /* u->nick will be freed halfway the process, so it can't be |
---|
| 476 | passed as an argument. */ |
---|
| 477 | orig_nick = g_strdup( u->nick ); |
---|
| 478 | user_rename( ic->irc, orig_nick, newnick ); |
---|
| 479 | g_free( orig_nick ); |
---|
[d06eabf] | 480 | } |
---|
| 481 | } |
---|
[b7d3cc34] | 482 | |
---|
| 483 | /* prpl.c */ |
---|
| 484 | |
---|
[7bf0f5f0] | 485 | struct show_got_added_data |
---|
| 486 | { |
---|
[0da65d5] | 487 | struct im_connection *ic; |
---|
[7bf0f5f0] | 488 | char *handle; |
---|
| 489 | }; |
---|
| 490 | |
---|
| 491 | void show_got_added_no( gpointer w, struct show_got_added_data *data ) |
---|
| 492 | { |
---|
| 493 | g_free( data->handle ); |
---|
| 494 | g_free( data ); |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | void show_got_added_yes( gpointer w, struct show_got_added_data *data ) |
---|
| 498 | { |
---|
[0da65d5] | 499 | data->ic->acc->prpl->add_buddy( data->ic, data->handle, NULL ); |
---|
[f0cb961] | 500 | /* imcb_add_buddy( data->ic, NULL, data->handle, data->handle ); */ |
---|
[7bf0f5f0] | 501 | |
---|
| 502 | return show_got_added_no( w, data ); |
---|
| 503 | } |
---|
| 504 | |
---|
[84b045d] | 505 | void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname ) |
---|
[b7d3cc34] | 506 | { |
---|
[7bf0f5f0] | 507 | struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); |
---|
| 508 | char *s; |
---|
| 509 | |
---|
| 510 | /* TODO: Make a setting for this! */ |
---|
[0da65d5] | 511 | if( user_findhandle( ic, handle ) != NULL ) |
---|
[7bf0f5f0] | 512 | return; |
---|
| 513 | |
---|
| 514 | s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); |
---|
| 515 | |
---|
[0da65d5] | 516 | data->ic = ic; |
---|
[7bf0f5f0] | 517 | data->handle = g_strdup( handle ); |
---|
[0da65d5] | 518 | query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data ); |
---|
[b7d3cc34] | 519 | } |
---|
| 520 | |
---|
| 521 | |
---|
| 522 | /* server.c */ |
---|
| 523 | |
---|
[6bbb939] | 524 | void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ) |
---|
[b7d3cc34] | 525 | { |
---|
| 526 | user_t *u; |
---|
| 527 | int oa, oo; |
---|
| 528 | |
---|
[6bbb939] | 529 | u = user_findhandle( ic, (char*) handle ); |
---|
[b7d3cc34] | 530 | |
---|
| 531 | if( !u ) |
---|
| 532 | { |
---|
[0da65d5] | 533 | if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 ) |
---|
[b7d3cc34] | 534 | { |
---|
[f0cb961] | 535 | imcb_add_buddy( ic, (char*) handle, NULL ); |
---|
[6bbb939] | 536 | u = user_findhandle( ic, (char*) handle ); |
---|
[b7d3cc34] | 537 | } |
---|
| 538 | else |
---|
| 539 | { |
---|
[0da65d5] | 540 | if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 ) |
---|
[b7d3cc34] | 541 | { |
---|
[6bbb939] | 542 | imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle ); |
---|
| 543 | imcb_log( ic, "flags = %d, state = %s, message = %s", flags, |
---|
| 544 | state ? state : "NULL", message ? message : "NULL" ); |
---|
[b7d3cc34] | 545 | } |
---|
| 546 | |
---|
| 547 | return; |
---|
| 548 | } |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | oa = u->away != NULL; |
---|
| 552 | oo = u->online; |
---|
| 553 | |
---|
| 554 | if( u->away ) |
---|
| 555 | { |
---|
| 556 | g_free( u->away ); |
---|
| 557 | u->away = NULL; |
---|
| 558 | } |
---|
| 559 | |
---|
[6bbb939] | 560 | if( ( flags & OPT_LOGGED_IN ) && !u->online ) |
---|
[b7d3cc34] | 561 | { |
---|
[0da65d5] | 562 | irc_spawn( ic->irc, u ); |
---|
[b7d3cc34] | 563 | u->online = 1; |
---|
| 564 | } |
---|
[6bbb939] | 565 | else if( !( flags & OPT_LOGGED_IN ) && u->online ) |
---|
[b7d3cc34] | 566 | { |
---|
[0da65d5] | 567 | struct groupchat *c; |
---|
[b7d3cc34] | 568 | |
---|
[0da65d5] | 569 | irc_kill( ic->irc, u ); |
---|
[b7d3cc34] | 570 | u->online = 0; |
---|
| 571 | |
---|
[e35d1a1] | 572 | /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ |
---|
| 573 | for( c = ic->groupchats; c; c = c->next ) |
---|
[6bbb939] | 574 | remove_chat_buddy_silent( c, (char*) handle ); |
---|
[b7d3cc34] | 575 | } |
---|
| 576 | |
---|
[6bbb939] | 577 | if( flags & OPT_AWAY ) |
---|
[b7d3cc34] | 578 | { |
---|
[6bbb939] | 579 | if( state && message ) |
---|
| 580 | { |
---|
| 581 | u->away = g_strdup_printf( "%s (%s)", state, message ); |
---|
| 582 | } |
---|
| 583 | else if( state ) |
---|
| 584 | { |
---|
| 585 | u->away = g_strdup( state ); |
---|
| 586 | } |
---|
| 587 | else if( message ) |
---|
| 588 | { |
---|
| 589 | u->away = g_strdup( message ); |
---|
| 590 | } |
---|
| 591 | else |
---|
| 592 | { |
---|
| 593 | u->away = g_strdup( "Away" ); |
---|
| 594 | } |
---|
[b7d3cc34] | 595 | } |
---|
[6bbb939] | 596 | /* else waste_any_state_information_for_now(); */ |
---|
[b7d3cc34] | 597 | |
---|
| 598 | /* LISPy... */ |
---|
[0da65d5] | 599 | if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ |
---|
[b7d3cc34] | 600 | ( u->online ) && /* Don't touch offline people */ |
---|
| 601 | ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ |
---|
| 602 | ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ |
---|
| 603 | { |
---|
[0da65d5] | 604 | irc_write( ic->irc, ":%s MODE %s %cv %s", ic->irc->myhost, |
---|
[9624fdf] | 605 | ic->irc->channel, u->away?'-':'+', u->nick ); |
---|
[b7d3cc34] | 606 | } |
---|
| 607 | } |
---|
| 608 | |
---|
[9624fdf] | 609 | void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, u_int32_t flags, time_t sent_at ) |
---|
[b7d3cc34] | 610 | { |
---|
[0da65d5] | 611 | irc_t *irc = ic->irc; |
---|
[b7d3cc34] | 612 | user_t *u; |
---|
| 613 | |
---|
[0da65d5] | 614 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 615 | |
---|
| 616 | if( !u ) |
---|
| 617 | { |
---|
[5c9512f] | 618 | char *h = set_getstr( &irc->set, "handle_unknown" ); |
---|
[b7d3cc34] | 619 | |
---|
| 620 | if( g_strcasecmp( h, "ignore" ) == 0 ) |
---|
| 621 | { |
---|
[d5ccd83] | 622 | if( set_getbool( &irc->set, "debug" ) ) |
---|
[84b045d] | 623 | imcb_log( ic, "Ignoring message from unknown handle %s", handle ); |
---|
[b7d3cc34] | 624 | |
---|
| 625 | return; |
---|
| 626 | } |
---|
| 627 | else if( g_strncasecmp( h, "add", 3 ) == 0 ) |
---|
| 628 | { |
---|
[d5ccd83] | 629 | int private = set_getbool( &irc->set, "private" ); |
---|
[b7d3cc34] | 630 | |
---|
| 631 | if( h[3] ) |
---|
| 632 | { |
---|
| 633 | if( g_strcasecmp( h + 3, "_private" ) == 0 ) |
---|
| 634 | private = 1; |
---|
| 635 | else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) |
---|
| 636 | private = 0; |
---|
| 637 | } |
---|
| 638 | |
---|
[f0cb961] | 639 | imcb_add_buddy( ic, handle, NULL ); |
---|
[0da65d5] | 640 | u = user_findhandle( ic, handle ); |
---|
[b7d3cc34] | 641 | u->is_private = private; |
---|
| 642 | } |
---|
| 643 | else |
---|
| 644 | { |
---|
[84b045d] | 645 | imcb_log( ic, "Message from unknown handle %s:", handle ); |
---|
[b7d3cc34] | 646 | u = user_find( irc, irc->mynick ); |
---|
| 647 | } |
---|
| 648 | } |
---|
| 649 | |
---|
[0da65d5] | 650 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 651 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[b7d3cc34] | 652 | strip_html( msg ); |
---|
| 653 | |
---|
[30f248a] | 654 | while( strlen( msg ) > 425 ) |
---|
[b7d3cc34] | 655 | { |
---|
| 656 | char tmp, *nl; |
---|
| 657 | |
---|
[30f248a] | 658 | tmp = msg[425]; |
---|
| 659 | msg[425] = 0; |
---|
[b7d3cc34] | 660 | |
---|
[30f248a] | 661 | /* If there's a newline/space in this string, split up there, |
---|
| 662 | looks a bit prettier. */ |
---|
[f1df064] | 663 | if( ( nl = strrchr( msg, '\n' ) ) || ( nl = strrchr( msg, ' ' ) ) ) |
---|
[30f248a] | 664 | { |
---|
| 665 | msg[425] = tmp; |
---|
| 666 | tmp = *nl; |
---|
[b7d3cc34] | 667 | *nl = 0; |
---|
[30f248a] | 668 | } |
---|
[b7d3cc34] | 669 | |
---|
| 670 | irc_msgfrom( irc, u->nick, msg ); |
---|
| 671 | |
---|
| 672 | /* Move on. */ |
---|
| 673 | if( nl ) |
---|
| 674 | { |
---|
[30f248a] | 675 | *nl = tmp; |
---|
[b7d3cc34] | 676 | msg = nl + 1; |
---|
| 677 | } |
---|
| 678 | else |
---|
| 679 | { |
---|
[30f248a] | 680 | msg[425] = tmp; |
---|
| 681 | msg += 425; |
---|
[b7d3cc34] | 682 | } |
---|
| 683 | } |
---|
| 684 | irc_msgfrom( irc, u->nick, msg ); |
---|
| 685 | } |
---|
| 686 | |
---|
[9624fdf] | 687 | void imcb_buddy_typing( struct im_connection *ic, char *handle, u_int32_t flags ) |
---|
[b7d3cc34] | 688 | { |
---|
| 689 | user_t *u; |
---|
| 690 | |
---|
[0da65d5] | 691 | if( !set_getbool( &ic->irc->set, "typing_notice" ) ) |
---|
[b7d3cc34] | 692 | return; |
---|
| 693 | |
---|
[9624fdf] | 694 | if( ( u = user_findhandle( ic, handle ) ) ) |
---|
| 695 | { |
---|
| 696 | char buf[256]; |
---|
| 697 | |
---|
| 698 | g_snprintf( buf, 256, "\1TYPING %d\1", ( flags >> 8 ) & 3 ); |
---|
| 699 | irc_privmsg( ic->irc, u, "PRIVMSG", ic->irc->nick, NULL, buf ); |
---|
[e7f46c5] | 700 | } |
---|
[b7d3cc34] | 701 | } |
---|
| 702 | |
---|
[e35d1a1] | 703 | void imcb_chat_free( struct groupchat *c ) |
---|
[b7d3cc34] | 704 | { |
---|
[0da65d5] | 705 | struct im_connection *ic = c->ic; |
---|
[e35d1a1] | 706 | struct groupchat *l; |
---|
[b7d3cc34] | 707 | GList *ir; |
---|
| 708 | |
---|
[0da65d5] | 709 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
[84b045d] | 710 | imcb_log( ic, "You were removed from conversation 0x%x", (int) c ); |
---|
[b7d3cc34] | 711 | |
---|
| 712 | if( c ) |
---|
| 713 | { |
---|
| 714 | if( c->joined ) |
---|
| 715 | { |
---|
| 716 | user_t *u, *r; |
---|
| 717 | |
---|
[0da65d5] | 718 | r = user_find( ic->irc, ic->irc->mynick ); |
---|
| 719 | irc_privmsg( ic->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
[b7d3cc34] | 720 | |
---|
[0da65d5] | 721 | u = user_find( ic->irc, ic->irc->nick ); |
---|
| 722 | irc_kick( ic->irc, u, c->channel, r ); |
---|
| 723 | /* irc_part( ic->irc, u, c->channel ); */ |
---|
[b7d3cc34] | 724 | } |
---|
| 725 | |
---|
[e35d1a1] | 726 | /* Find the previous chat in the linked list. */ |
---|
| 727 | for( l = ic->groupchats; l && l->next != c; l = l->next ); |
---|
| 728 | |
---|
[b7d3cc34] | 729 | if( l ) |
---|
| 730 | l->next = c->next; |
---|
| 731 | else |
---|
[e35d1a1] | 732 | ic->groupchats = c->next; |
---|
[b7d3cc34] | 733 | |
---|
| 734 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
| 735 | g_free( ir->data ); |
---|
| 736 | g_list_free( c->in_room ); |
---|
| 737 | g_free( c->channel ); |
---|
| 738 | g_free( c->title ); |
---|
| 739 | g_free( c ); |
---|
| 740 | } |
---|
| 741 | } |
---|
| 742 | |
---|
[61ae52c] | 743 | void imcb_chat_msg( struct groupchat *c, char *who, char *msg, u_int32_t flags, time_t sent_at ) |
---|
[b7d3cc34] | 744 | { |
---|
[0da65d5] | 745 | struct im_connection *ic = c->ic; |
---|
[b7d3cc34] | 746 | user_t *u; |
---|
| 747 | |
---|
| 748 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
[c2fb3809] | 749 | if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 750 | return; |
---|
| 751 | |
---|
[0da65d5] | 752 | u = user_findhandle( ic, who ); |
---|
[b7d3cc34] | 753 | |
---|
[0da65d5] | 754 | if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) || |
---|
[6bbb939] | 755 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) |
---|
[b7d3cc34] | 756 | strip_html( msg ); |
---|
| 757 | |
---|
| 758 | if( c && u ) |
---|
[0da65d5] | 759 | irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", msg ); |
---|
[b7d3cc34] | 760 | else |
---|
[84b045d] | 761 | imcb_log( ic, "Message from/to conversation %s@0x%x (unknown conv/user): %s", who, (int) c, msg ); |
---|
[b7d3cc34] | 762 | } |
---|
| 763 | |
---|
[61ae52c] | 764 | struct groupchat *imcb_chat_new( struct im_connection *ic, char *handle ) |
---|
[b7d3cc34] | 765 | { |
---|
[0da65d5] | 766 | struct groupchat *c; |
---|
[b7d3cc34] | 767 | |
---|
| 768 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
| 769 | |
---|
[e35d1a1] | 770 | if( ic->groupchats ) |
---|
[b7d3cc34] | 771 | { |
---|
[e35d1a1] | 772 | for( c = ic->groupchats; c->next; c = c->next ); |
---|
[0da65d5] | 773 | c = c->next = g_new0( struct groupchat, 1 ); |
---|
[b7d3cc34] | 774 | } |
---|
| 775 | else |
---|
[e35d1a1] | 776 | ic->groupchats = c = g_new0( struct groupchat, 1 ); |
---|
[b7d3cc34] | 777 | |
---|
[0da65d5] | 778 | c->ic = ic; |
---|
[b7d3cc34] | 779 | c->title = g_strdup( handle ); |
---|
[0da65d5] | 780 | c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ ); |
---|
[b7d3cc34] | 781 | |
---|
[0da65d5] | 782 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
[84b045d] | 783 | imcb_log( ic, "Creating new conversation: (id=0x%x,handle=%s)", (int) c, handle ); |
---|
[b7d3cc34] | 784 | |
---|
[fa29d093] | 785 | return c; |
---|
[b7d3cc34] | 786 | } |
---|
| 787 | |
---|
| 788 | |
---|
| 789 | /* buddy_chat.c */ |
---|
| 790 | |
---|
[61ae52c] | 791 | void imcb_chat_add_buddy( struct groupchat *b, char *handle ) |
---|
[b7d3cc34] | 792 | { |
---|
[0da65d5] | 793 | user_t *u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 794 | int me = 0; |
---|
| 795 | |
---|
[0da65d5] | 796 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
[84b045d] | 797 | imcb_log( b->ic, "User %s added to conversation 0x%x", handle, (int) b ); |
---|
[b7d3cc34] | 798 | |
---|
| 799 | /* It might be yourself! */ |
---|
[c2fb3809] | 800 | if( b->ic->acc->prpl->handle_cmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 801 | { |
---|
[0da65d5] | 802 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 803 | if( !b->joined ) |
---|
[0da65d5] | 804 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 805 | b->joined = me = 1; |
---|
| 806 | } |
---|
| 807 | |
---|
| 808 | /* Most protocols allow people to join, even when they're not in |
---|
| 809 | your contact list. Try to handle that here */ |
---|
| 810 | if( !u ) |
---|
| 811 | { |
---|
[f0cb961] | 812 | imcb_add_buddy( b->ic, handle, NULL ); |
---|
[0da65d5] | 813 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 814 | } |
---|
| 815 | |
---|
| 816 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
| 817 | if( !me ) |
---|
| 818 | { |
---|
| 819 | if( b->joined ) |
---|
[0da65d5] | 820 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 821 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
| 822 | } |
---|
| 823 | } |
---|
| 824 | |
---|
[2d317bb] | 825 | /* This function is one BIG hack... :-( EREWRITE */ |
---|
[61ae52c] | 826 | void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason ) |
---|
[b7d3cc34] | 827 | { |
---|
| 828 | user_t *u; |
---|
| 829 | int me = 0; |
---|
| 830 | |
---|
[0da65d5] | 831 | if( set_getbool( &b->ic->irc->set, "debug" ) ) |
---|
[84b045d] | 832 | imcb_log( b->ic, "User %s removed from conversation 0x%x (%s)", handle, (int) b, reason ? reason : "" ); |
---|
[b7d3cc34] | 833 | |
---|
| 834 | /* It might be yourself! */ |
---|
[c2fb3809] | 835 | if( g_strcasecmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 836 | { |
---|
[2d317bb] | 837 | if( b->joined == 0 ) |
---|
| 838 | return; |
---|
| 839 | |
---|
[0da65d5] | 840 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 841 | b->joined = 0; |
---|
| 842 | me = 1; |
---|
| 843 | } |
---|
| 844 | else |
---|
| 845 | { |
---|
[0da65d5] | 846 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 847 | } |
---|
| 848 | |
---|
[2d317bb] | 849 | if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) ) |
---|
| 850 | irc_part( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 851 | } |
---|
| 852 | |
---|
[0da65d5] | 853 | static int remove_chat_buddy_silent( struct groupchat *b, char *handle ) |
---|
[b7d3cc34] | 854 | { |
---|
| 855 | GList *i; |
---|
| 856 | |
---|
| 857 | /* Find the handle in the room userlist and shoot it */ |
---|
| 858 | i = b->in_room; |
---|
| 859 | while( i ) |
---|
| 860 | { |
---|
| 861 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
| 862 | { |
---|
| 863 | g_free( i->data ); |
---|
| 864 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
| 865 | return( 1 ); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | i = i->next; |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | return( 0 ); |
---|
| 872 | } |
---|
| 873 | |
---|
| 874 | |
---|
| 875 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
| 876 | |
---|
[5c9512f] | 877 | char *set_eval_away_devoice( set_t *set, char *value ) |
---|
[b7d3cc34] | 878 | { |
---|
[5c9512f] | 879 | irc_t *irc = set->data; |
---|
[b7d3cc34] | 880 | int st; |
---|
| 881 | |
---|
| 882 | if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) |
---|
| 883 | st = 1; |
---|
| 884 | else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) |
---|
| 885 | st = 0; |
---|
| 886 | else if( sscanf( value, "%d", &st ) != 1 ) |
---|
| 887 | return( NULL ); |
---|
| 888 | |
---|
| 889 | st = st != 0; |
---|
| 890 | |
---|
| 891 | /* Horror.... */ |
---|
| 892 | |
---|
[d5ccd83] | 893 | if( st != set_getbool( &irc->set, "away_devoice" ) ) |
---|
[b7d3cc34] | 894 | { |
---|
| 895 | char list[80] = ""; |
---|
| 896 | user_t *u = irc->users; |
---|
| 897 | int i = 0, count = 0; |
---|
| 898 | char pm; |
---|
| 899 | char v[80]; |
---|
| 900 | |
---|
| 901 | if( st ) |
---|
| 902 | pm = '+'; |
---|
| 903 | else |
---|
| 904 | pm = '-'; |
---|
| 905 | |
---|
| 906 | while( u ) |
---|
| 907 | { |
---|
[0da65d5] | 908 | if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 909 | { |
---|
| 910 | if( ( strlen( list ) + strlen( u->nick ) ) >= 79 ) |
---|
| 911 | { |
---|
| 912 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 913 | irc_write( irc, ":%s MODE %s %c%s%s", |
---|
| 914 | irc->myhost, |
---|
[b7d3cc34] | 915 | irc->channel, pm, v, list ); |
---|
| 916 | |
---|
| 917 | *list = 0; |
---|
| 918 | count = 0; |
---|
| 919 | } |
---|
| 920 | |
---|
| 921 | sprintf( list + strlen( list ), " %s", u->nick ); |
---|
| 922 | count ++; |
---|
| 923 | } |
---|
| 924 | u = u->next; |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | /* $v = 'v' x $i */ |
---|
| 928 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 929 | irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost, |
---|
[b7d3cc34] | 930 | irc->channel, pm, v, list ); |
---|
| 931 | } |
---|
| 932 | |
---|
[5c9512f] | 933 | return( set_eval_bool( set, value ) ); |
---|
[b7d3cc34] | 934 | } |
---|
| 935 | |
---|
[226fce1] | 936 | |
---|
| 937 | |
---|
| 938 | |
---|
| 939 | /* The plan is to not allow straight calls to prpl functions anymore, but do |
---|
| 940 | them all from some wrappers. We'll start to define some down here: */ |
---|
| 941 | |
---|
[84b045d] | 942 | int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags ) |
---|
[b7d3cc34] | 943 | { |
---|
[e27661d] | 944 | char *buf = NULL; |
---|
| 945 | int st; |
---|
[b7d3cc34] | 946 | |
---|
[6bbb939] | 947 | if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[c572dd6] | 948 | { |
---|
[e27661d] | 949 | buf = escape_html( msg ); |
---|
[c572dd6] | 950 | msg = buf; |
---|
[b7d3cc34] | 951 | } |
---|
| 952 | |
---|
[f6c963b] | 953 | st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags ); |
---|
[e27661d] | 954 | g_free( buf ); |
---|
| 955 | |
---|
| 956 | return st; |
---|
[b7d3cc34] | 957 | } |
---|
| 958 | |
---|
[84b045d] | 959 | int imc_chat_msg( struct groupchat *c, char *msg, int flags ) |
---|
[b7d3cc34] | 960 | { |
---|
[e27661d] | 961 | char *buf = NULL; |
---|
[b7d3cc34] | 962 | |
---|
[6bbb939] | 963 | if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[e27661d] | 964 | { |
---|
| 965 | buf = escape_html( msg ); |
---|
[b7d3cc34] | 966 | msg = buf; |
---|
| 967 | } |
---|
| 968 | |
---|
[f6c963b] | 969 | c->ic->acc->prpl->chat_msg( c, msg, flags ); |
---|
[e27661d] | 970 | g_free( buf ); |
---|
| 971 | |
---|
[0da65d5] | 972 | return 1; |
---|
[b7d3cc34] | 973 | } |
---|
[226fce1] | 974 | |
---|
[84b045d] | 975 | static char *imc_away_alias_find( GList *gcm, char *away ); |
---|
[226fce1] | 976 | |
---|
[84b045d] | 977 | int imc_set_away( struct im_connection *ic, char *away ) |
---|
[226fce1] | 978 | { |
---|
| 979 | GList *m, *ms; |
---|
| 980 | char *s; |
---|
| 981 | |
---|
| 982 | if( !away ) away = ""; |
---|
[0da65d5] | 983 | ms = m = ic->acc->prpl->away_states( ic ); |
---|
[226fce1] | 984 | |
---|
| 985 | while( m ) |
---|
| 986 | { |
---|
| 987 | if( *away ) |
---|
| 988 | { |
---|
| 989 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
| 990 | break; |
---|
| 991 | } |
---|
| 992 | else |
---|
| 993 | { |
---|
| 994 | if( g_strcasecmp( m->data, "Available" ) == 0 ) |
---|
| 995 | break; |
---|
| 996 | if( g_strcasecmp( m->data, "Online" ) == 0 ) |
---|
| 997 | break; |
---|
| 998 | } |
---|
| 999 | m = m->next; |
---|
| 1000 | } |
---|
| 1001 | |
---|
| 1002 | if( m ) |
---|
| 1003 | { |
---|
[0da65d5] | 1004 | ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL ); |
---|
[226fce1] | 1005 | } |
---|
| 1006 | else |
---|
| 1007 | { |
---|
[84b045d] | 1008 | s = imc_away_alias_find( ms, away ); |
---|
[226fce1] | 1009 | if( s ) |
---|
| 1010 | { |
---|
[0da65d5] | 1011 | ic->acc->prpl->set_away( ic, s, away ); |
---|
| 1012 | if( set_getbool( &ic->irc->set, "debug" ) ) |
---|
[84b045d] | 1013 | imcb_log( ic, "Setting away state to %s", s ); |
---|
[226fce1] | 1014 | } |
---|
| 1015 | else |
---|
[0da65d5] | 1016 | ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away ); |
---|
[226fce1] | 1017 | } |
---|
| 1018 | |
---|
| 1019 | return( 1 ); |
---|
| 1020 | } |
---|
| 1021 | |
---|
[84b045d] | 1022 | static char *imc_away_alias_list[8][5] = |
---|
[226fce1] | 1023 | { |
---|
| 1024 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
| 1025 | { "NA", "N/A", "Not available", NULL }, |
---|
| 1026 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
| 1027 | { "Be right back", "BRB", NULL }, |
---|
| 1028 | { "On the phone", "Phone", "On phone", NULL }, |
---|
| 1029 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
| 1030 | { "Invisible", "Hidden" }, |
---|
| 1031 | { NULL } |
---|
| 1032 | }; |
---|
| 1033 | |
---|
[84b045d] | 1034 | static char *imc_away_alias_find( GList *gcm, char *away ) |
---|
[226fce1] | 1035 | { |
---|
| 1036 | GList *m; |
---|
| 1037 | int i, j; |
---|
| 1038 | |
---|
[84b045d] | 1039 | for( i = 0; *imc_away_alias_list[i]; i ++ ) |
---|
[226fce1] | 1040 | { |
---|
[84b045d] | 1041 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
| 1042 | if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) |
---|
[226fce1] | 1043 | break; |
---|
| 1044 | |
---|
[84b045d] | 1045 | if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ |
---|
[226fce1] | 1046 | continue; /* is not what we want. Next! */ |
---|
| 1047 | |
---|
| 1048 | /* Now find an entry in this row which exists in gcm */ |
---|
[84b045d] | 1049 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
[226fce1] | 1050 | { |
---|
| 1051 | m = gcm; |
---|
| 1052 | while( m ) |
---|
| 1053 | { |
---|
[84b045d] | 1054 | if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) |
---|
| 1055 | return( imc_away_alias_list[i][j] ); |
---|
[226fce1] | 1056 | m = m->next; |
---|
| 1057 | } |
---|
| 1058 | } |
---|
| 1059 | } |
---|
| 1060 | |
---|
| 1061 | return( NULL ); |
---|
| 1062 | } |
---|
[da3b536] | 1063 | |
---|
[84b045d] | 1064 | void imc_add_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1065 | { |
---|
[0da65d5] | 1066 | if( g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 1067 | { |
---|
[0da65d5] | 1068 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
[da3b536] | 1069 | } |
---|
| 1070 | |
---|
[0da65d5] | 1071 | ic->acc->prpl->add_permit( ic, handle ); |
---|
[da3b536] | 1072 | } |
---|
| 1073 | |
---|
[84b045d] | 1074 | void imc_rem_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1075 | { |
---|
| 1076 | GSList *l; |
---|
| 1077 | |
---|
[0da65d5] | 1078 | if( ( l = g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 1079 | { |
---|
| 1080 | g_free( l->data ); |
---|
[0da65d5] | 1081 | ic->permit = g_slist_delete_link( ic->permit, l ); |
---|
[da3b536] | 1082 | } |
---|
| 1083 | |
---|
[0da65d5] | 1084 | ic->acc->prpl->rem_permit( ic, handle ); |
---|
[da3b536] | 1085 | } |
---|
| 1086 | |
---|
[84b045d] | 1087 | void imc_add_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1088 | { |
---|
[0da65d5] | 1089 | if( g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 1090 | { |
---|
[0da65d5] | 1091 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
[da3b536] | 1092 | } |
---|
| 1093 | |
---|
[0da65d5] | 1094 | ic->acc->prpl->add_deny( ic, handle ); |
---|
[da3b536] | 1095 | } |
---|
| 1096 | |
---|
[84b045d] | 1097 | void imc_rem_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1098 | { |
---|
| 1099 | GSList *l; |
---|
| 1100 | |
---|
[0da65d5] | 1101 | if( ( l = g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 1102 | { |
---|
| 1103 | g_free( l->data ); |
---|
[0da65d5] | 1104 | ic->deny = g_slist_delete_link( ic->deny, l ); |
---|
[da3b536] | 1105 | } |
---|
| 1106 | |
---|
[0da65d5] | 1107 | ic->acc->prpl->rem_deny( ic, handle ); |
---|
[da3b536] | 1108 | } |
---|