[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 | |
---|
[b7d3cc34] | 40 | GSList *connections; |
---|
| 41 | |
---|
[65e2ce1] | 42 | #ifdef WITH_PLUGINS |
---|
[7b23afd] | 43 | gboolean load_plugin(char *path) |
---|
| 44 | { |
---|
| 45 | void (*init_function) (void); |
---|
| 46 | |
---|
| 47 | GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); |
---|
| 48 | |
---|
| 49 | if(!mod) { |
---|
[8ad90fb] | 50 | log_message(LOGLVL_ERROR, "Can't find `%s', not loading (%s)\n", path, g_module_error()); |
---|
[7b23afd] | 51 | return FALSE; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) { |
---|
| 55 | log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path); |
---|
| 56 | return FALSE; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | init_function(); |
---|
| 60 | |
---|
| 61 | return TRUE; |
---|
| 62 | } |
---|
[b7d3cc34] | 63 | |
---|
[65e2ce1] | 64 | void load_plugins(void) |
---|
| 65 | { |
---|
| 66 | GDir *dir; |
---|
| 67 | GError *error = NULL; |
---|
| 68 | |
---|
[4bfca70] | 69 | dir = g_dir_open(global.conf->plugindir, 0, &error); |
---|
[65e2ce1] | 70 | |
---|
| 71 | if (dir) { |
---|
| 72 | const gchar *entry; |
---|
| 73 | char *path; |
---|
| 74 | |
---|
| 75 | while ((entry = g_dir_read_name(dir))) { |
---|
[4bfca70] | 76 | path = g_build_filename(global.conf->plugindir, entry, NULL); |
---|
[65e2ce1] | 77 | if(!path) { |
---|
| 78 | log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); |
---|
| 79 | continue; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | load_plugin(path); |
---|
| 83 | |
---|
| 84 | g_free(path); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | g_dir_close(dir); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | #endif |
---|
[b7d3cc34] | 91 | |
---|
[7b23afd] | 92 | GList *protocols = NULL; |
---|
| 93 | |
---|
| 94 | void register_protocol (struct prpl *p) |
---|
| 95 | { |
---|
[90cd6c4] | 96 | int i; |
---|
| 97 | gboolean refused = global.conf->protocols != NULL; |
---|
| 98 | |
---|
| 99 | for (i = 0; global.conf->protocols && global.conf->protocols[i]; i++) |
---|
| 100 | { |
---|
| 101 | if (g_strcasecmp(p->name, global.conf->protocols[i]) == 0) |
---|
| 102 | refused = FALSE; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | if (refused) |
---|
| 106 | log_message(LOGLVL_WARNING, "Protocol %s disabled\n", p->name); |
---|
| 107 | else |
---|
| 108 | protocols = g_list_append(protocols, p); |
---|
[7b23afd] | 109 | } |
---|
| 110 | |
---|
| 111 | struct prpl *find_protocol(const char *name) |
---|
| 112 | { |
---|
| 113 | GList *gl; |
---|
| 114 | for (gl = protocols; gl; gl = gl->next) |
---|
| 115 | { |
---|
| 116 | struct prpl *proto = gl->data; |
---|
| 117 | if(!g_strcasecmp(proto->name, name)) |
---|
| 118 | return proto; |
---|
| 119 | } |
---|
| 120 | return NULL; |
---|
| 121 | } |
---|
| 122 | |
---|
[b7d3cc34] | 123 | void nogaim_init() |
---|
| 124 | { |
---|
[0da65d5] | 125 | extern void msn_initmodule(); |
---|
| 126 | extern void oscar_initmodule(); |
---|
| 127 | extern void byahoo_initmodule(); |
---|
| 128 | extern void jabber_initmodule(); |
---|
[1b221e0] | 129 | extern void twitter_initmodule(); |
---|
[7b23afd] | 130 | |
---|
[b7d3cc34] | 131 | #ifdef WITH_MSN |
---|
[0da65d5] | 132 | msn_initmodule(); |
---|
[b7d3cc34] | 133 | #endif |
---|
| 134 | |
---|
| 135 | #ifdef WITH_OSCAR |
---|
[0da65d5] | 136 | oscar_initmodule(); |
---|
[b7d3cc34] | 137 | #endif |
---|
| 138 | |
---|
| 139 | #ifdef WITH_YAHOO |
---|
[0da65d5] | 140 | byahoo_initmodule(); |
---|
[b7d3cc34] | 141 | #endif |
---|
| 142 | |
---|
| 143 | #ifdef WITH_JABBER |
---|
[0da65d5] | 144 | jabber_initmodule(); |
---|
[b7d3cc34] | 145 | #endif |
---|
[7b23afd] | 146 | |
---|
[1b221e0] | 147 | #ifdef WITH_TWITTER |
---|
| 148 | twitter_initmodule(); |
---|
| 149 | #endif |
---|
| 150 | |
---|
[65e2ce1] | 151 | #ifdef WITH_PLUGINS |
---|
| 152 | load_plugins(); |
---|
[b7d3cc34] | 153 | #endif |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | GSList *get_connections() { return connections; } |
---|
| 157 | |
---|
[84b045d] | 158 | struct im_connection *imcb_new( account_t *acc ) |
---|
[b7d3cc34] | 159 | { |
---|
[0da65d5] | 160 | struct im_connection *ic; |
---|
[b7d3cc34] | 161 | |
---|
[0da65d5] | 162 | ic = g_new0( struct im_connection, 1 ); |
---|
[b7d3cc34] | 163 | |
---|
[81e04e1] | 164 | ic->bee = acc->bee; |
---|
[0da65d5] | 165 | ic->acc = acc; |
---|
| 166 | acc->ic = ic; |
---|
[b7d3cc34] | 167 | |
---|
[0da65d5] | 168 | connections = g_slist_append( connections, ic ); |
---|
[b7d3cc34] | 169 | |
---|
[0da65d5] | 170 | return( ic ); |
---|
[b7d3cc34] | 171 | } |
---|
| 172 | |
---|
[aef4828] | 173 | void imc_free( struct im_connection *ic ) |
---|
[b7d3cc34] | 174 | { |
---|
| 175 | account_t *a; |
---|
| 176 | |
---|
| 177 | /* Destroy the pointer to this connection from the account list */ |
---|
[81e04e1] | 178 | for( a = ic->bee->accounts; a; a = a->next ) |
---|
[0da65d5] | 179 | if( a->ic == ic ) |
---|
[b7d3cc34] | 180 | { |
---|
[0da65d5] | 181 | a->ic = NULL; |
---|
[b7d3cc34] | 182 | break; |
---|
| 183 | } |
---|
| 184 | |
---|
[0da65d5] | 185 | connections = g_slist_remove( connections, ic ); |
---|
| 186 | g_free( ic ); |
---|
[b7d3cc34] | 187 | } |
---|
| 188 | |
---|
[aef4828] | 189 | static void serv_got_crap( struct im_connection *ic, char *format, ... ) |
---|
[b7d3cc34] | 190 | { |
---|
| 191 | va_list params; |
---|
[e27661d] | 192 | char *text; |
---|
[dfde8e0] | 193 | account_t *a; |
---|
[b7d3cc34] | 194 | |
---|
| 195 | va_start( params, format ); |
---|
[e27661d] | 196 | text = g_strdup_vprintf( format, params ); |
---|
[b7d3cc34] | 197 | va_end( params ); |
---|
| 198 | |
---|
[81e04e1] | 199 | if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) || |
---|
| 200 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) ) |
---|
[e27661d] | 201 | strip_html( text ); |
---|
[b7d3cc34] | 202 | |
---|
[dfde8e0] | 203 | /* Try to find a different connection on the same protocol. */ |
---|
[81e04e1] | 204 | for( a = ic->bee->accounts; a; a = a->next ) |
---|
[0da65d5] | 205 | if( a->prpl == ic->acc->prpl && a->ic != ic ) |
---|
[dfde8e0] | 206 | break; |
---|
| 207 | |
---|
[e27661d] | 208 | /* If we found one, include the screenname in the message. */ |
---|
[dfde8e0] | 209 | if( a ) |
---|
[81e04e1] | 210 | /* FIXME(wilmer): ui_log callback or so */ |
---|
| 211 | irc_usermsg( ic->bee->ui_data, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); |
---|
[dfde8e0] | 212 | else |
---|
[81e04e1] | 213 | irc_usermsg( ic->bee->ui_data, "%s - %s", ic->acc->prpl->name, text ); |
---|
[7b07dc6] | 214 | |
---|
[e27661d] | 215 | g_free( text ); |
---|
[b7d3cc34] | 216 | } |
---|
| 217 | |
---|
[84b045d] | 218 | void imcb_log( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 219 | { |
---|
| 220 | va_list params; |
---|
| 221 | char *text; |
---|
| 222 | |
---|
| 223 | va_start( params, format ); |
---|
| 224 | text = g_strdup_vprintf( format, params ); |
---|
| 225 | va_end( params ); |
---|
| 226 | |
---|
| 227 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 228 | serv_got_crap( ic, "%s", text ); |
---|
| 229 | else |
---|
| 230 | serv_got_crap( ic, "Logging in: %s", text ); |
---|
| 231 | |
---|
| 232 | g_free( text ); |
---|
| 233 | } |
---|
| 234 | |
---|
[84b045d] | 235 | void imcb_error( struct im_connection *ic, char *format, ... ) |
---|
[aef4828] | 236 | { |
---|
| 237 | va_list params; |
---|
| 238 | char *text; |
---|
| 239 | |
---|
| 240 | va_start( params, format ); |
---|
| 241 | text = g_strdup_vprintf( format, params ); |
---|
| 242 | va_end( params ); |
---|
| 243 | |
---|
| 244 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 245 | serv_got_crap( ic, "Error: %s", text ); |
---|
| 246 | else |
---|
| 247 | serv_got_crap( ic, "Couldn't log in: %s", text ); |
---|
| 248 | |
---|
| 249 | g_free( text ); |
---|
| 250 | } |
---|
| 251 | |
---|
[ba9edaa] | 252 | static gboolean send_keepalive( gpointer d, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 253 | { |
---|
[0da65d5] | 254 | struct im_connection *ic = d; |
---|
[b7d3cc34] | 255 | |
---|
[0da65d5] | 256 | if( ic->acc->prpl->keepalive ) |
---|
| 257 | ic->acc->prpl->keepalive( ic ); |
---|
[b7d3cc34] | 258 | |
---|
| 259 | return TRUE; |
---|
| 260 | } |
---|
| 261 | |
---|
[84b045d] | 262 | void imcb_connected( struct im_connection *ic ) |
---|
[b7d3cc34] | 263 | { |
---|
| 264 | /* MSN servers sometimes redirect you to a different server and do |
---|
[84c1a0a] | 265 | the whole login sequence again, so these "late" calls to this |
---|
[b7d3cc34] | 266 | function should be handled correctly. (IOW, ignored) */ |
---|
[0da65d5] | 267 | if( ic->flags & OPT_LOGGED_IN ) |
---|
[b7d3cc34] | 268 | return; |
---|
| 269 | |
---|
[84b045d] | 270 | imcb_log( ic, "Logged in" ); |
---|
[b7d3cc34] | 271 | |
---|
[0da65d5] | 272 | ic->keepalive = b_timeout_add( 60000, send_keepalive, ic ); |
---|
| 273 | ic->flags |= OPT_LOGGED_IN; |
---|
[b7d3cc34] | 274 | |
---|
[58adb7e] | 275 | /* Necessary to send initial presence status, even if we're not away. */ |
---|
| 276 | imc_away_send_update( ic ); |
---|
[280e655] | 277 | |
---|
| 278 | /* Apparently we're connected successfully, so reset the |
---|
| 279 | exponential backoff timer. */ |
---|
| 280 | ic->acc->auto_reconnect_delay = 0; |
---|
[3611717] | 281 | |
---|
[10a96f4] | 282 | /* |
---|
[3611717] | 283 | for( c = irc->chatrooms; c; c = c->next ) |
---|
| 284 | { |
---|
| 285 | if( c->acc != ic->acc ) |
---|
| 286 | continue; |
---|
| 287 | |
---|
| 288 | if( set_getbool( &c->set, "auto_join" ) ) |
---|
[94acdd0] | 289 | chat_join( irc, c, NULL ); |
---|
[3611717] | 290 | } |
---|
[10a96f4] | 291 | */ |
---|
[b7d3cc34] | 292 | } |
---|
| 293 | |
---|
[ba9edaa] | 294 | gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond ) |
---|
[b7d3cc34] | 295 | { |
---|
| 296 | account_t *a = data; |
---|
| 297 | |
---|
| 298 | a->reconnect = 0; |
---|
[81e04e1] | 299 | account_on( a->bee, a ); |
---|
[b7d3cc34] | 300 | |
---|
| 301 | return( FALSE ); /* Only have to run the timeout once */ |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | void cancel_auto_reconnect( account_t *a ) |
---|
| 305 | { |
---|
[c98be00] | 306 | b_event_remove( a->reconnect ); |
---|
[b7d3cc34] | 307 | a->reconnect = 0; |
---|
| 308 | } |
---|
| 309 | |
---|
[c2fb3809] | 310 | void imc_logout( struct im_connection *ic, int allow_reconnect ) |
---|
[b7d3cc34] | 311 | { |
---|
[81e04e1] | 312 | bee_t *bee = ic->bee; |
---|
[b7d3cc34] | 313 | account_t *a; |
---|
[81e04e1] | 314 | GSList *l; |
---|
[4230221] | 315 | int delay; |
---|
[b7d3cc34] | 316 | |
---|
[8d74291] | 317 | /* Nested calls might happen sometimes, this is probably the best |
---|
| 318 | place to catch them. */ |
---|
[0da65d5] | 319 | if( ic->flags & OPT_LOGGING_OUT ) |
---|
[8d74291] | 320 | return; |
---|
[66f783f] | 321 | else |
---|
[0da65d5] | 322 | ic->flags |= OPT_LOGGING_OUT; |
---|
[8d74291] | 323 | |
---|
[84b045d] | 324 | imcb_log( ic, "Signing off.." ); |
---|
[fb62f81f] | 325 | |
---|
[0da65d5] | 326 | b_event_remove( ic->keepalive ); |
---|
| 327 | ic->keepalive = 0; |
---|
| 328 | ic->acc->prpl->logout( ic ); |
---|
| 329 | b_event_remove( ic->inpa ); |
---|
[b7d3cc34] | 330 | |
---|
[c0c43fb] | 331 | g_free( ic->away ); |
---|
| 332 | ic->away = NULL; |
---|
| 333 | |
---|
[eabc9d2] | 334 | for( l = bee->users; l; ) |
---|
[b7d3cc34] | 335 | { |
---|
[81e04e1] | 336 | bee_user_t *bu = l->data; |
---|
[eabc9d2] | 337 | GSList *next = l->next; |
---|
[81e04e1] | 338 | |
---|
| 339 | if( bu->ic == ic ) |
---|
[eabc9d2] | 340 | bee_user_free( bee, bu ); |
---|
| 341 | |
---|
| 342 | l = next; |
---|
[b7d3cc34] | 343 | } |
---|
| 344 | |
---|
[81e04e1] | 345 | //query_del_by_conn( ic->irc, ic ); |
---|
[b7d3cc34] | 346 | |
---|
[81e04e1] | 347 | for( a = bee->accounts; a; a = a->next ) |
---|
[0da65d5] | 348 | if( a->ic == ic ) |
---|
[b7d3cc34] | 349 | break; |
---|
| 350 | |
---|
| 351 | if( !a ) |
---|
| 352 | { |
---|
| 353 | /* Uhm... This is very sick. */ |
---|
| 354 | } |
---|
[81e04e1] | 355 | else if( allow_reconnect && set_getbool( &bee->set, "auto_reconnect" ) && |
---|
[4230221] | 356 | set_getbool( &a->set, "auto_reconnect" ) && |
---|
| 357 | ( delay = account_reconnect_delay( a ) ) > 0 ) |
---|
[b7d3cc34] | 358 | { |
---|
[84b045d] | 359 | imcb_log( ic, "Reconnecting in %d seconds..", delay ); |
---|
[c98be00] | 360 | a->reconnect = b_timeout_add( delay * 1000, auto_reconnect, a ); |
---|
[b7d3cc34] | 361 | } |
---|
| 362 | |
---|
[aef4828] | 363 | imc_free( ic ); |
---|
[b7d3cc34] | 364 | } |
---|
| 365 | |
---|
[9143aeb] | 366 | void imcb_ask( struct im_connection *ic, char *msg, void *data, |
---|
| 367 | query_callback doit, query_callback dont ) |
---|
[b7d3cc34] | 368 | { |
---|
[e00da63] | 369 | query_add( (irc_t *) ic->bee->ui_data, ic, msg, doit, dont, data ); |
---|
[b7d3cc34] | 370 | } |
---|
| 371 | |
---|
[c6ca3ee] | 372 | void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group ) |
---|
[b7d3cc34] | 373 | { |
---|
[81e04e1] | 374 | bee_user_t *bu; |
---|
| 375 | bee_t *bee = ic->bee; |
---|
[b7d3cc34] | 376 | |
---|
[81e04e1] | 377 | if( bee_user_by_handle( bee, ic, handle ) ) |
---|
[b7d3cc34] | 378 | { |
---|
[81e04e1] | 379 | if( set_getbool( &bee->set, "debug" ) ) |
---|
[84b045d] | 380 | imcb_log( ic, "User already exists, ignoring add request: %s", handle ); |
---|
[b7d3cc34] | 381 | |
---|
| 382 | return; |
---|
| 383 | |
---|
[f0cb961] | 384 | /* Buddy seems to exist already. Let's ignore this request then... |
---|
| 385 | Eventually subsequent calls to this function *should* be possible |
---|
| 386 | when a buddy is in multiple groups. But for now BitlBee doesn't |
---|
| 387 | even support groups so let's silently ignore this for now. */ |
---|
[b7d3cc34] | 388 | } |
---|
| 389 | |
---|
[81e04e1] | 390 | bu = bee_user_new( bee, ic, handle ); |
---|
| 391 | bu->group = g_strdup( group ); |
---|
[b7d3cc34] | 392 | } |
---|
| 393 | |
---|
[1d39159] | 394 | void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *fullname ) |
---|
[b7d3cc34] | 395 | { |
---|
[1d39159] | 396 | bee_t *bee = ic->bee; |
---|
| 397 | bee_user_t *bu = bee_user_by_handle( bee, ic, handle ); |
---|
[b7d3cc34] | 398 | |
---|
[1d39159] | 399 | if( !bu || !fullname ) return; |
---|
[b7d3cc34] | 400 | |
---|
[17a6ee9] | 401 | if( !bu->fullname || strcmp( bu->fullname, fullname ) != 0 ) |
---|
[b7d3cc34] | 402 | { |
---|
[1d39159] | 403 | g_free( bu->fullname ); |
---|
| 404 | bu->fullname = g_strdup( fullname ); |
---|
[b7d3cc34] | 405 | |
---|
[1d39159] | 406 | if( bee->ui->user_fullname ) |
---|
| 407 | bee->ui->user_fullname( bee, bu ); |
---|
[b7d3cc34] | 408 | } |
---|
| 409 | } |
---|
| 410 | |
---|
[c6ca3ee] | 411 | void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group ) |
---|
[998b103] | 412 | { |
---|
[eabc9d2] | 413 | bee_user_free( ic->bee, bee_user_by_handle( ic->bee, ic, handle ) ); |
---|
[998b103] | 414 | } |
---|
| 415 | |
---|
[d06eabf] | 416 | /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM |
---|
| 417 | modules to suggest a nickname for a handle. */ |
---|
[fb00989] | 418 | void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick ) |
---|
[d06eabf] | 419 | { |
---|
[81e04e1] | 420 | #if 0 |
---|
[d06eabf] | 421 | user_t *u = user_findhandle( ic, handle ); |
---|
[43d8cc5] | 422 | char newnick[MAX_NICK_LENGTH+1], *orig_nick; |
---|
[d06eabf] | 423 | |
---|
[e0e2a71] | 424 | if( u && !u->online && !nick_saved( ic->acc, handle ) ) |
---|
[d06eabf] | 425 | { |
---|
| 426 | /* Only do this if the person isn't online yet (which should |
---|
| 427 | be the case if we just added it) and if the user hasn't |
---|
| 428 | assigned a nickname to this buddy already. */ |
---|
| 429 | |
---|
[e0e2a71] | 430 | strncpy( newnick, nick, MAX_NICK_LENGTH ); |
---|
| 431 | newnick[MAX_NICK_LENGTH] = 0; |
---|
[d06eabf] | 432 | |
---|
| 433 | /* Some processing to make sure this string is a valid IRC nickname. */ |
---|
| 434 | nick_strip( newnick ); |
---|
[81e04e1] | 435 | if( set_getbool( &ic->bee->set, "lcnicks" ) ) |
---|
[d06eabf] | 436 | nick_lc( newnick ); |
---|
| 437 | |
---|
[1962ac1] | 438 | if( strcmp( u->nick, newnick ) != 0 ) |
---|
| 439 | { |
---|
| 440 | /* Only do this if newnick is different from the current one. |
---|
| 441 | If rejoining a channel, maybe we got this nick already |
---|
| 442 | (and dedupe would only add an underscore. */ |
---|
| 443 | nick_dedupe( ic->acc, handle, newnick ); |
---|
| 444 | |
---|
| 445 | /* u->nick will be freed halfway the process, so it can't be |
---|
| 446 | passed as an argument. */ |
---|
| 447 | orig_nick = g_strdup( u->nick ); |
---|
| 448 | user_rename( ic->irc, orig_nick, newnick ); |
---|
| 449 | g_free( orig_nick ); |
---|
| 450 | } |
---|
[d06eabf] | 451 | } |
---|
[81e04e1] | 452 | #endif |
---|
[d06eabf] | 453 | } |
---|
[b7d3cc34] | 454 | |
---|
| 455 | |
---|
[fa295e36] | 456 | struct imcb_ask_cb_data |
---|
[7bf0f5f0] | 457 | { |
---|
[0da65d5] | 458 | struct im_connection *ic; |
---|
[7bf0f5f0] | 459 | char *handle; |
---|
| 460 | }; |
---|
| 461 | |
---|
[fa295e36] | 462 | static void imcb_ask_auth_cb_no( void *data ) |
---|
[7bf0f5f0] | 463 | { |
---|
[fa295e36] | 464 | struct imcb_ask_cb_data *cbd = data; |
---|
| 465 | |
---|
| 466 | cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle ); |
---|
| 467 | |
---|
| 468 | g_free( cbd->handle ); |
---|
| 469 | g_free( cbd ); |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | static void imcb_ask_auth_cb_yes( void *data ) |
---|
| 473 | { |
---|
| 474 | struct imcb_ask_cb_data *cbd = data; |
---|
| 475 | |
---|
| 476 | cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle ); |
---|
| 477 | |
---|
| 478 | g_free( cbd->handle ); |
---|
| 479 | g_free( cbd ); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname ) |
---|
| 483 | { |
---|
| 484 | struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); |
---|
| 485 | char *s, *realname_ = NULL; |
---|
| 486 | |
---|
| 487 | if( realname != NULL ) |
---|
| 488 | realname_ = g_strdup_printf( " (%s)", realname ); |
---|
| 489 | |
---|
| 490 | s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.", |
---|
| 491 | handle, realname_ ?: "" ); |
---|
| 492 | |
---|
| 493 | g_free( realname_ ); |
---|
| 494 | |
---|
| 495 | data->ic = ic; |
---|
| 496 | data->handle = g_strdup( handle ); |
---|
[e00da63] | 497 | query_add( (irc_t *) ic->bee->ui_data, ic, s, |
---|
| 498 | imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data ); |
---|
[fa295e36] | 499 | } |
---|
| 500 | |
---|
| 501 | |
---|
| 502 | static void imcb_ask_add_cb_no( void *data ) |
---|
| 503 | { |
---|
| 504 | g_free( ((struct imcb_ask_cb_data*)data)->handle ); |
---|
[7bf0f5f0] | 505 | g_free( data ); |
---|
| 506 | } |
---|
| 507 | |
---|
[fa295e36] | 508 | static void imcb_ask_add_cb_yes( void *data ) |
---|
[7bf0f5f0] | 509 | { |
---|
[fa295e36] | 510 | struct imcb_ask_cb_data *cbd = data; |
---|
[7bf0f5f0] | 511 | |
---|
[fa295e36] | 512 | cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL ); |
---|
[9143aeb] | 513 | |
---|
[fa295e36] | 514 | return imcb_ask_add_cb_no( data ); |
---|
[7bf0f5f0] | 515 | } |
---|
| 516 | |
---|
[fa295e36] | 517 | void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname ) |
---|
[b7d3cc34] | 518 | { |
---|
[fa295e36] | 519 | struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); |
---|
[7bf0f5f0] | 520 | char *s; |
---|
| 521 | |
---|
| 522 | /* TODO: Make a setting for this! */ |
---|
[e00da63] | 523 | if( bee_user_by_handle( ic->bee, ic, handle ) != NULL ) |
---|
[7bf0f5f0] | 524 | return; |
---|
| 525 | |
---|
| 526 | s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); |
---|
| 527 | |
---|
[0da65d5] | 528 | data->ic = ic; |
---|
[7bf0f5f0] | 529 | data->handle = g_strdup( handle ); |
---|
[e00da63] | 530 | query_add( (irc_t *) ic->bee->ui_data, ic, s, |
---|
| 531 | imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data ); |
---|
[b7d3cc34] | 532 | } |
---|
| 533 | |
---|
[81e04e1] | 534 | struct bee_user *imcb_buddy_by_handle( struct im_connection *ic, const char *handle ) |
---|
| 535 | { |
---|
| 536 | return bee_user_by_handle( ic->bee, ic, handle ); |
---|
[b7d3cc34] | 537 | } |
---|
| 538 | |
---|
[94acdd0] | 539 | struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle ) |
---|
[83ba3e5] | 540 | { |
---|
[81e04e1] | 541 | #if 0 |
---|
[83ba3e5] | 542 | struct groupchat *c; |
---|
| 543 | |
---|
| 544 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
| 545 | |
---|
| 546 | if( ic->groupchats ) |
---|
| 547 | { |
---|
| 548 | for( c = ic->groupchats; c->next; c = c->next ); |
---|
| 549 | c = c->next = g_new0( struct groupchat, 1 ); |
---|
| 550 | } |
---|
| 551 | else |
---|
| 552 | ic->groupchats = c = g_new0( struct groupchat, 1 ); |
---|
| 553 | |
---|
| 554 | c->ic = ic; |
---|
| 555 | c->title = g_strdup( handle ); |
---|
| 556 | c->channel = g_strdup_printf( "&chat_%03d", ic->irc->c_id++ ); |
---|
| 557 | c->topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
| 558 | |
---|
[81e04e1] | 559 | if( set_getbool( &ic->bee->set, "debug" ) ) |
---|
[83ba3e5] | 560 | imcb_log( ic, "Creating new conversation: (id=%p,handle=%s)", c, handle ); |
---|
| 561 | |
---|
| 562 | return c; |
---|
[81e04e1] | 563 | #endif |
---|
[fb117aee] | 564 | return NULL; |
---|
[83ba3e5] | 565 | } |
---|
| 566 | |
---|
[cca0692] | 567 | void imcb_chat_name_hint( struct groupchat *c, const char *name ) |
---|
| 568 | { |
---|
[21c87a7] | 569 | #if 0 |
---|
[cca0692] | 570 | if( !c->joined ) |
---|
| 571 | { |
---|
| 572 | struct im_connection *ic = c->ic; |
---|
| 573 | char stripped[MAX_NICK_LENGTH+1], *full_name; |
---|
| 574 | |
---|
| 575 | strncpy( stripped, name, MAX_NICK_LENGTH ); |
---|
| 576 | stripped[MAX_NICK_LENGTH] = '\0'; |
---|
| 577 | nick_strip( stripped ); |
---|
| 578 | if( set_getbool( &ic->irc->set, "lcnicks" ) ) |
---|
| 579 | nick_lc( stripped ); |
---|
| 580 | |
---|
| 581 | full_name = g_strdup_printf( "&%s", stripped ); |
---|
| 582 | |
---|
| 583 | if( stripped[0] && |
---|
| 584 | nick_cmp( stripped, ic->irc->channel + 1 ) != 0 && |
---|
| 585 | irc_chat_by_channel( ic->irc, full_name ) == NULL ) |
---|
| 586 | { |
---|
| 587 | g_free( c->channel ); |
---|
| 588 | c->channel = full_name; |
---|
| 589 | } |
---|
| 590 | else |
---|
| 591 | { |
---|
| 592 | g_free( full_name ); |
---|
| 593 | } |
---|
| 594 | } |
---|
[21c87a7] | 595 | #endif |
---|
[cca0692] | 596 | } |
---|
| 597 | |
---|
[e35d1a1] | 598 | void imcb_chat_free( struct groupchat *c ) |
---|
[b7d3cc34] | 599 | { |
---|
[81e04e1] | 600 | #if 0 |
---|
[0da65d5] | 601 | struct im_connection *ic = c->ic; |
---|
[e35d1a1] | 602 | struct groupchat *l; |
---|
[b7d3cc34] | 603 | GList *ir; |
---|
| 604 | |
---|
[81e04e1] | 605 | if( set_getbool( &ic->bee->set, "debug" ) ) |
---|
[56f260a] | 606 | imcb_log( ic, "You were removed from conversation %p", c ); |
---|
[b7d3cc34] | 607 | |
---|
| 608 | if( c ) |
---|
| 609 | { |
---|
| 610 | if( c->joined ) |
---|
| 611 | { |
---|
| 612 | user_t *u, *r; |
---|
| 613 | |
---|
[0da65d5] | 614 | r = user_find( ic->irc, ic->irc->mynick ); |
---|
| 615 | irc_privmsg( ic->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
[b7d3cc34] | 616 | |
---|
[0da65d5] | 617 | u = user_find( ic->irc, ic->irc->nick ); |
---|
| 618 | irc_kick( ic->irc, u, c->channel, r ); |
---|
| 619 | /* irc_part( ic->irc, u, c->channel ); */ |
---|
[b7d3cc34] | 620 | } |
---|
| 621 | |
---|
[e35d1a1] | 622 | /* Find the previous chat in the linked list. */ |
---|
| 623 | for( l = ic->groupchats; l && l->next != c; l = l->next ); |
---|
| 624 | |
---|
[b7d3cc34] | 625 | if( l ) |
---|
| 626 | l->next = c->next; |
---|
| 627 | else |
---|
[e35d1a1] | 628 | ic->groupchats = c->next; |
---|
[b7d3cc34] | 629 | |
---|
| 630 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
| 631 | g_free( ir->data ); |
---|
| 632 | g_list_free( c->in_room ); |
---|
| 633 | g_free( c->channel ); |
---|
| 634 | g_free( c->title ); |
---|
[83ba3e5] | 635 | g_free( c->topic ); |
---|
[b7d3cc34] | 636 | g_free( c ); |
---|
| 637 | } |
---|
[81e04e1] | 638 | #endif |
---|
[b7d3cc34] | 639 | } |
---|
| 640 | |
---|
[c6ca3ee] | 641 | void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at ) |
---|
[b7d3cc34] | 642 | { |
---|
[81e04e1] | 643 | #if 0 |
---|
[0da65d5] | 644 | struct im_connection *ic = c->ic; |
---|
[d444c09] | 645 | char *wrapped; |
---|
[b7d3cc34] | 646 | user_t *u; |
---|
| 647 | |
---|
| 648 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
[c2fb3809] | 649 | if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 650 | return; |
---|
| 651 | |
---|
[0da65d5] | 652 | u = user_findhandle( ic, who ); |
---|
[b7d3cc34] | 653 | |
---|
[81e04e1] | 654 | if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) || |
---|
| 655 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) ) |
---|
[b7d3cc34] | 656 | strip_html( msg ); |
---|
| 657 | |
---|
[d444c09] | 658 | wrapped = word_wrap( msg, 425 ); |
---|
[b7d3cc34] | 659 | if( c && u ) |
---|
[d444c09] | 660 | { |
---|
[5b9b2b6] | 661 | char *ts = NULL; |
---|
| 662 | if( set_getbool( &ic->irc->set, "display_timestamps" ) ) |
---|
| 663 | ts = format_timestamp( ic->irc, sent_at ); |
---|
[3e57660] | 664 | irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped ); |
---|
| 665 | g_free( ts ); |
---|
[d444c09] | 666 | } |
---|
[b7d3cc34] | 667 | else |
---|
[d444c09] | 668 | { |
---|
[56f260a] | 669 | imcb_log( ic, "Message from/to conversation %s@%p (unknown conv/user): %s", who, c, wrapped ); |
---|
[d444c09] | 670 | } |
---|
| 671 | g_free( wrapped ); |
---|
[81e04e1] | 672 | #endif |
---|
[b7d3cc34] | 673 | } |
---|
| 674 | |
---|
[31e5846] | 675 | void imcb_chat_log( struct groupchat *c, char *format, ... ) |
---|
| 676 | { |
---|
[81e04e1] | 677 | #if 0 |
---|
[31e5846] | 678 | irc_t *irc = c->ic->irc; |
---|
| 679 | va_list params; |
---|
| 680 | char *text; |
---|
| 681 | user_t *u; |
---|
| 682 | |
---|
| 683 | va_start( params, format ); |
---|
| 684 | text = g_strdup_vprintf( format, params ); |
---|
| 685 | va_end( params ); |
---|
| 686 | |
---|
| 687 | u = user_find( irc, irc->mynick ); |
---|
| 688 | |
---|
| 689 | irc_privmsg( irc, u, "PRIVMSG", c->channel, "System message: ", text ); |
---|
| 690 | |
---|
| 691 | g_free( text ); |
---|
[81e04e1] | 692 | #endif |
---|
[31e5846] | 693 | } |
---|
| 694 | |
---|
[ef5c185] | 695 | void imcb_chat_topic( struct groupchat *c, char *who, char *topic, time_t set_at ) |
---|
[50e1776] | 696 | { |
---|
[81e04e1] | 697 | #if 0 |
---|
[50e1776] | 698 | struct im_connection *ic = c->ic; |
---|
| 699 | user_t *u = NULL; |
---|
| 700 | |
---|
| 701 | if( who == NULL) |
---|
[ef5c185] | 702 | u = user_find( ic->irc, ic->irc->mynick ); |
---|
[50e1776] | 703 | else if( g_strcasecmp( who, ic->acc->user ) == 0 ) |
---|
[ef5c185] | 704 | u = user_find( ic->irc, ic->irc->nick ); |
---|
[50e1776] | 705 | else |
---|
| 706 | u = user_findhandle( ic, who ); |
---|
| 707 | |
---|
[81e04e1] | 708 | if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) || |
---|
| 709 | ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) ) |
---|
[50e1776] | 710 | strip_html( topic ); |
---|
| 711 | |
---|
| 712 | g_free( c->topic ); |
---|
| 713 | c->topic = g_strdup( topic ); |
---|
| 714 | |
---|
| 715 | if( c->joined && u ) |
---|
| 716 | irc_write( ic->irc, ":%s!%s@%s TOPIC %s :%s", u->nick, u->user, u->host, c->channel, topic ); |
---|
[81e04e1] | 717 | #endif |
---|
[50e1776] | 718 | } |
---|
| 719 | |
---|
[c6ca3ee] | 720 | void imcb_chat_add_buddy( struct groupchat *b, const char *handle ) |
---|
[b7d3cc34] | 721 | { |
---|
[81e04e1] | 722 | #if 0 |
---|
[0da65d5] | 723 | user_t *u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 724 | int me = 0; |
---|
| 725 | |
---|
[81e04e1] | 726 | if( set_getbool( &b->ic->bee->set, "debug" ) ) |
---|
[56f260a] | 727 | imcb_log( b->ic, "User %s added to conversation %p", handle, b ); |
---|
[b7d3cc34] | 728 | |
---|
| 729 | /* It might be yourself! */ |
---|
[c2fb3809] | 730 | if( b->ic->acc->prpl->handle_cmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 731 | { |
---|
[0da65d5] | 732 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 733 | if( !b->joined ) |
---|
[0da65d5] | 734 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 735 | b->joined = me = 1; |
---|
| 736 | } |
---|
| 737 | |
---|
| 738 | /* Most protocols allow people to join, even when they're not in |
---|
| 739 | your contact list. Try to handle that here */ |
---|
| 740 | if( !u ) |
---|
| 741 | { |
---|
[f0cb961] | 742 | imcb_add_buddy( b->ic, handle, NULL ); |
---|
[0da65d5] | 743 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 744 | } |
---|
| 745 | |
---|
| 746 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
| 747 | if( !me ) |
---|
| 748 | { |
---|
| 749 | if( b->joined ) |
---|
[0da65d5] | 750 | irc_join( b->ic->irc, u, b->channel ); |
---|
[b7d3cc34] | 751 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
| 752 | } |
---|
[81e04e1] | 753 | #endif |
---|
[b7d3cc34] | 754 | } |
---|
| 755 | |
---|
[2d317bb] | 756 | /* This function is one BIG hack... :-( EREWRITE */ |
---|
[c6ca3ee] | 757 | void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason ) |
---|
[b7d3cc34] | 758 | { |
---|
[81e04e1] | 759 | #if 0 |
---|
[b7d3cc34] | 760 | user_t *u; |
---|
| 761 | int me = 0; |
---|
| 762 | |
---|
[81e04e1] | 763 | if( set_getbool( &b->ic->bee->set, "debug" ) ) |
---|
[56f260a] | 764 | imcb_log( b->ic, "User %s removed from conversation %p (%s)", handle, b, reason ? reason : "" ); |
---|
[b7d3cc34] | 765 | |
---|
| 766 | /* It might be yourself! */ |
---|
[c2fb3809] | 767 | if( g_strcasecmp( handle, b->ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 768 | { |
---|
[2d317bb] | 769 | if( b->joined == 0 ) |
---|
| 770 | return; |
---|
| 771 | |
---|
[0da65d5] | 772 | u = user_find( b->ic->irc, b->ic->irc->nick ); |
---|
[b7d3cc34] | 773 | b->joined = 0; |
---|
| 774 | me = 1; |
---|
| 775 | } |
---|
| 776 | else |
---|
| 777 | { |
---|
[0da65d5] | 778 | u = user_findhandle( b->ic, handle ); |
---|
[b7d3cc34] | 779 | } |
---|
| 780 | |
---|
[2d317bb] | 781 | if( me || ( remove_chat_buddy_silent( b, handle ) && b->joined && u ) ) |
---|
| 782 | irc_part( b->ic->irc, u, b->channel ); |
---|
[81e04e1] | 783 | #endif |
---|
[b7d3cc34] | 784 | } |
---|
| 785 | |
---|
[fb117aee] | 786 | #if 0 |
---|
[764b163d] | 787 | static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ) |
---|
[b7d3cc34] | 788 | { |
---|
| 789 | GList *i; |
---|
| 790 | |
---|
| 791 | /* Find the handle in the room userlist and shoot it */ |
---|
| 792 | i = b->in_room; |
---|
| 793 | while( i ) |
---|
| 794 | { |
---|
| 795 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
| 796 | { |
---|
| 797 | g_free( i->data ); |
---|
| 798 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
| 799 | return( 1 ); |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | i = i->next; |
---|
| 803 | } |
---|
| 804 | |
---|
[81e04e1] | 805 | return 0; |
---|
[b7d3cc34] | 806 | } |
---|
[fb117aee] | 807 | #endif |
---|
[b7d3cc34] | 808 | |
---|
| 809 | |
---|
| 810 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
[81e04e1] | 811 | #if 0 |
---|
[5c9512f] | 812 | char *set_eval_away_devoice( set_t *set, char *value ) |
---|
[b7d3cc34] | 813 | { |
---|
[5c9512f] | 814 | irc_t *irc = set->data; |
---|
[b7d3cc34] | 815 | int st; |
---|
| 816 | |
---|
[7125cb3] | 817 | if( !is_bool( value ) ) |
---|
| 818 | return SET_INVALID; |
---|
[b7d3cc34] | 819 | |
---|
[7125cb3] | 820 | st = bool2int( value ); |
---|
[b7d3cc34] | 821 | |
---|
| 822 | /* Horror.... */ |
---|
| 823 | |
---|
[10a96f4] | 824 | if( st != set_getbool( &irc->b->set, "away_devoice" ) ) |
---|
[b7d3cc34] | 825 | { |
---|
| 826 | char list[80] = ""; |
---|
| 827 | user_t *u = irc->users; |
---|
| 828 | int i = 0, count = 0; |
---|
| 829 | char pm; |
---|
| 830 | char v[80]; |
---|
| 831 | |
---|
| 832 | if( st ) |
---|
| 833 | pm = '+'; |
---|
| 834 | else |
---|
| 835 | pm = '-'; |
---|
| 836 | |
---|
| 837 | while( u ) |
---|
| 838 | { |
---|
[0da65d5] | 839 | if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 840 | { |
---|
| 841 | if( ( strlen( list ) + strlen( u->nick ) ) >= 79 ) |
---|
| 842 | { |
---|
| 843 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 844 | irc_write( irc, ":%s MODE %s %c%s%s", |
---|
| 845 | irc->myhost, |
---|
[b7d3cc34] | 846 | irc->channel, pm, v, list ); |
---|
| 847 | |
---|
| 848 | *list = 0; |
---|
| 849 | count = 0; |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | sprintf( list + strlen( list ), " %s", u->nick ); |
---|
| 853 | count ++; |
---|
| 854 | } |
---|
| 855 | u = u->next; |
---|
| 856 | } |
---|
| 857 | |
---|
| 858 | /* $v = 'v' x $i */ |
---|
| 859 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
[2087159] | 860 | irc_write( irc, ":%s MODE %s %c%s%s", irc->myhost, |
---|
[b7d3cc34] | 861 | irc->channel, pm, v, list ); |
---|
| 862 | } |
---|
| 863 | |
---|
[7125cb3] | 864 | return value; |
---|
[b7d3cc34] | 865 | } |
---|
[81e04e1] | 866 | #endif |
---|
[226fce1] | 867 | |
---|
| 868 | /* The plan is to not allow straight calls to prpl functions anymore, but do |
---|
| 869 | them all from some wrappers. We'll start to define some down here: */ |
---|
| 870 | |
---|
[84b045d] | 871 | int imc_chat_msg( struct groupchat *c, char *msg, int flags ) |
---|
[b7d3cc34] | 872 | { |
---|
[e27661d] | 873 | char *buf = NULL; |
---|
[b7d3cc34] | 874 | |
---|
[6bbb939] | 875 | if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
[e27661d] | 876 | { |
---|
| 877 | buf = escape_html( msg ); |
---|
[b7d3cc34] | 878 | msg = buf; |
---|
| 879 | } |
---|
| 880 | |
---|
[f6c963b] | 881 | c->ic->acc->prpl->chat_msg( c, msg, flags ); |
---|
[e27661d] | 882 | g_free( buf ); |
---|
| 883 | |
---|
[0da65d5] | 884 | return 1; |
---|
[b7d3cc34] | 885 | } |
---|
[226fce1] | 886 | |
---|
[34fbbf9] | 887 | static char *imc_away_state_find( GList *gcm, char *away, char **message ); |
---|
[226fce1] | 888 | |
---|
[58adb7e] | 889 | int imc_away_send_update( struct im_connection *ic ) |
---|
[226fce1] | 890 | { |
---|
[3e1ef92c] | 891 | char *away, *msg = NULL; |
---|
[226fce1] | 892 | |
---|
[91cec2f] | 893 | if( ic->acc->prpl->away_states == NULL || |
---|
| 894 | ic->acc->prpl->set_away == NULL ) |
---|
| 895 | return 0; |
---|
| 896 | |
---|
[58adb7e] | 897 | away = set_getstr( &ic->acc->set, "away" ) ? |
---|
[81e04e1] | 898 | : set_getstr( &ic->bee->set, "away" ); |
---|
[34fbbf9] | 899 | if( away && *away ) |
---|
[226fce1] | 900 | { |
---|
[34fbbf9] | 901 | GList *m = ic->acc->prpl->away_states( ic ); |
---|
[58adb7e] | 902 | msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL; |
---|
| 903 | away = imc_away_state_find( m, away, &msg ) ? : m->data; |
---|
| 904 | } |
---|
| 905 | else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE ) |
---|
| 906 | { |
---|
| 907 | away = NULL; |
---|
| 908 | msg = set_getstr( &ic->acc->set, "status" ) ? |
---|
[81e04e1] | 909 | : set_getstr( &ic->bee->set, "status" ); |
---|
[226fce1] | 910 | } |
---|
| 911 | |
---|
[58adb7e] | 912 | ic->acc->prpl->set_away( ic, away, msg ); |
---|
[226fce1] | 913 | |
---|
[34fbbf9] | 914 | return 1; |
---|
[226fce1] | 915 | } |
---|
| 916 | |
---|
[84b045d] | 917 | static char *imc_away_alias_list[8][5] = |
---|
[226fce1] | 918 | { |
---|
| 919 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
| 920 | { "NA", "N/A", "Not available", NULL }, |
---|
| 921 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
| 922 | { "Be right back", "BRB", NULL }, |
---|
| 923 | { "On the phone", "Phone", "On phone", NULL }, |
---|
| 924 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
| 925 | { "Invisible", "Hidden" }, |
---|
| 926 | { NULL } |
---|
| 927 | }; |
---|
| 928 | |
---|
[34fbbf9] | 929 | static char *imc_away_state_find( GList *gcm, char *away, char **message ) |
---|
[226fce1] | 930 | { |
---|
| 931 | GList *m; |
---|
| 932 | int i, j; |
---|
| 933 | |
---|
[34fbbf9] | 934 | for( m = gcm; m; m = m->next ) |
---|
| 935 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
| 936 | { |
---|
| 937 | /* At least the Yahoo! module works better if message |
---|
| 938 | contains no data unless it adds something to what |
---|
| 939 | we have in state already. */ |
---|
| 940 | if( strlen( m->data ) == strlen( away ) ) |
---|
| 941 | *message = NULL; |
---|
| 942 | |
---|
| 943 | return m->data; |
---|
| 944 | } |
---|
| 945 | |
---|
[84b045d] | 946 | for( i = 0; *imc_away_alias_list[i]; i ++ ) |
---|
[226fce1] | 947 | { |
---|
[34fbbf9] | 948 | int keep_message; |
---|
| 949 | |
---|
[84b045d] | 950 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
| 951 | if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) |
---|
[34fbbf9] | 952 | { |
---|
| 953 | keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] ); |
---|
[226fce1] | 954 | break; |
---|
[34fbbf9] | 955 | } |
---|
[226fce1] | 956 | |
---|
[84b045d] | 957 | if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ |
---|
[226fce1] | 958 | continue; /* is not what we want. Next! */ |
---|
| 959 | |
---|
| 960 | /* Now find an entry in this row which exists in gcm */ |
---|
[84b045d] | 961 | for( j = 0; imc_away_alias_list[i][j]; j ++ ) |
---|
[226fce1] | 962 | { |
---|
[34fbbf9] | 963 | for( m = gcm; m; m = m->next ) |
---|
[84b045d] | 964 | if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) |
---|
[34fbbf9] | 965 | { |
---|
| 966 | if( !keep_message ) |
---|
| 967 | *message = NULL; |
---|
| 968 | |
---|
| 969 | return imc_away_alias_list[i][j]; |
---|
| 970 | } |
---|
[226fce1] | 971 | } |
---|
[34fbbf9] | 972 | |
---|
| 973 | /* No need to look further, apparently this state doesn't |
---|
| 974 | have any good alias for this protocol. */ |
---|
| 975 | break; |
---|
[226fce1] | 976 | } |
---|
| 977 | |
---|
[34fbbf9] | 978 | return NULL; |
---|
[226fce1] | 979 | } |
---|
[da3b536] | 980 | |
---|
[84b045d] | 981 | void imc_add_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 982 | { |
---|
[0da65d5] | 983 | if( g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 984 | { |
---|
[0da65d5] | 985 | ic->permit = g_slist_prepend( ic->permit, g_strdup( handle ) ); |
---|
[da3b536] | 986 | } |
---|
| 987 | |
---|
[0da65d5] | 988 | ic->acc->prpl->add_permit( ic, handle ); |
---|
[da3b536] | 989 | } |
---|
| 990 | |
---|
[84b045d] | 991 | void imc_rem_allow( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 992 | { |
---|
| 993 | GSList *l; |
---|
| 994 | |
---|
[0da65d5] | 995 | if( ( l = g_slist_find_custom( ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 996 | { |
---|
| 997 | g_free( l->data ); |
---|
[0da65d5] | 998 | ic->permit = g_slist_delete_link( ic->permit, l ); |
---|
[da3b536] | 999 | } |
---|
| 1000 | |
---|
[0da65d5] | 1001 | ic->acc->prpl->rem_permit( ic, handle ); |
---|
[da3b536] | 1002 | } |
---|
| 1003 | |
---|
[84b045d] | 1004 | void imc_add_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1005 | { |
---|
[0da65d5] | 1006 | if( g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) == NULL ) |
---|
[da3b536] | 1007 | { |
---|
[0da65d5] | 1008 | ic->deny = g_slist_prepend( ic->deny, g_strdup( handle ) ); |
---|
[da3b536] | 1009 | } |
---|
| 1010 | |
---|
[0da65d5] | 1011 | ic->acc->prpl->add_deny( ic, handle ); |
---|
[da3b536] | 1012 | } |
---|
| 1013 | |
---|
[84b045d] | 1014 | void imc_rem_block( struct im_connection *ic, char *handle ) |
---|
[da3b536] | 1015 | { |
---|
| 1016 | GSList *l; |
---|
| 1017 | |
---|
[0da65d5] | 1018 | if( ( l = g_slist_find_custom( ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp ) ) ) |
---|
[da3b536] | 1019 | { |
---|
| 1020 | g_free( l->data ); |
---|
[0da65d5] | 1021 | ic->deny = g_slist_delete_link( ic->deny, l ); |
---|
[da3b536] | 1022 | } |
---|
| 1023 | |
---|
[0da65d5] | 1024 | ic->acc->prpl->rem_deny( ic, handle ); |
---|
[da3b536] | 1025 | } |
---|
[85023c6] | 1026 | |
---|
| 1027 | void imcb_clean_handle( struct im_connection *ic, char *handle ) |
---|
| 1028 | { |
---|
| 1029 | /* Accepts a handle and does whatever is necessary to make it |
---|
| 1030 | BitlBee-friendly. Currently this means removing everything |
---|
| 1031 | outside 33-127 (ASCII printable excl spaces), @ (only one |
---|
| 1032 | is allowed) and ! and : */ |
---|
| 1033 | char out[strlen(handle)+1]; |
---|
| 1034 | int s, d; |
---|
| 1035 | |
---|
| 1036 | s = d = 0; |
---|
| 1037 | while( handle[s] ) |
---|
| 1038 | { |
---|
| 1039 | if( handle[s] > ' ' && handle[s] != '!' && handle[s] != ':' && |
---|
| 1040 | ( handle[s] & 0x80 ) == 0 ) |
---|
| 1041 | { |
---|
| 1042 | if( handle[s] == '@' ) |
---|
| 1043 | { |
---|
| 1044 | /* See if we got an @ already? */ |
---|
| 1045 | out[d] = 0; |
---|
| 1046 | if( strchr( out, '@' ) ) |
---|
| 1047 | continue; |
---|
| 1048 | } |
---|
| 1049 | |
---|
| 1050 | out[d++] = handle[s]; |
---|
| 1051 | } |
---|
| 1052 | s ++; |
---|
| 1053 | } |
---|
| 1054 | out[d] = handle[s]; |
---|
| 1055 | |
---|
| 1056 | strcpy( handle, out ); |
---|
| 1057 | } |
---|