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