[5ebff60] | 1 | /********************************************************************\ |
---|
[b7d3cc34] | 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[0e788f5] | 4 | * Copyright 2002-2012 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; |
---|
[6f10697] | 30 | if not, write to the Free Software Foundation, Inc., 51 Franklin St., |
---|
| 31 | Fifth Floor, Boston, MA 02110-1301 USA |
---|
[b7d3cc34] | 32 | */ |
---|
| 33 | |
---|
| 34 | #define BITLBEE_CORE |
---|
| 35 | #include <ctype.h> |
---|
| 36 | |
---|
[4cf80bb] | 37 | #include "nogaim.h" |
---|
| 38 | |
---|
[b7d3cc34] | 39 | GSList *connections; |
---|
| 40 | |
---|
[65e2ce1] | 41 | #ifdef WITH_PLUGINS |
---|
[d28fe1c4] | 42 | GList *plugins = NULL; |
---|
| 43 | |
---|
| 44 | static gint pluginscmp(gconstpointer a, gconstpointer b, gpointer data) |
---|
| 45 | { |
---|
| 46 | const struct plugin_info *ia = a; |
---|
| 47 | const struct plugin_info *ib = b; |
---|
| 48 | |
---|
| 49 | return g_strcasecmp(ia->name, ib->name); |
---|
| 50 | } |
---|
| 51 | |
---|
[7486853] | 52 | /* semi-private */ |
---|
| 53 | gboolean plugin_info_validate(struct plugin_info *info, const char *path) |
---|
[7b23afd] | 54 | { |
---|
[d28fe1c4] | 55 | GList *l; |
---|
[7486853] | 56 | gboolean loaded = FALSE; |
---|
| 57 | |
---|
| 58 | if (!path) { |
---|
| 59 | path = "(null)"; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | if (info->abiver != BITLBEE_ABI_VERSION_CODE) { |
---|
| 63 | log_message(LOGLVL_ERROR, |
---|
| 64 | "`%s' uses ABI %u but %u is required\n", |
---|
| 65 | path, info->abiver, |
---|
| 66 | BITLBEE_ABI_VERSION_CODE); |
---|
| 67 | return FALSE; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | if (!info->name || !info->version) { |
---|
| 71 | log_message(LOGLVL_ERROR, |
---|
| 72 | "Name or version missing from the " |
---|
| 73 | "plugin info in `%s'\n", path); |
---|
| 74 | return FALSE; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | for (l = plugins; l; l = l->next) { |
---|
| 78 | struct plugin_info *i = l->data; |
---|
| 79 | |
---|
| 80 | if (g_strcasecmp(i->name, info->name) == 0) { |
---|
| 81 | loaded = TRUE; |
---|
| 82 | break; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if (loaded) { |
---|
| 87 | log_message(LOGLVL_WARNING, |
---|
| 88 | "%s plugin already loaded\n", |
---|
| 89 | info->name); |
---|
| 90 | return FALSE; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | return TRUE; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /* semi-private */ |
---|
| 97 | gboolean plugin_info_add(struct plugin_info *info) |
---|
| 98 | { |
---|
| 99 | plugins = g_list_insert_sorted_with_data(plugins, info, pluginscmp, NULL); |
---|
| 100 | return TRUE; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | gboolean load_plugin(char *path) |
---|
| 104 | { |
---|
[0483e1e] | 105 | struct plugin_info *info = NULL; |
---|
[d28fe1c4] | 106 | struct plugin_info * (*info_function) (void) = NULL; |
---|
[7b23afd] | 107 | void (*init_function) (void); |
---|
[5ebff60] | 108 | |
---|
[7b23afd] | 109 | GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); |
---|
| 110 | |
---|
[5ebff60] | 111 | if (!mod) { |
---|
[4fe91a1] | 112 | log_message(LOGLVL_ERROR, "Error loading plugin `%s': %s\n", path, g_module_error()); |
---|
[7b23afd] | 113 | return FALSE; |
---|
| 114 | } |
---|
| 115 | |
---|
[d28fe1c4] | 116 | if (g_module_symbol(mod, "init_plugin_info", (gpointer *) &info_function)) { |
---|
| 117 | info = info_function(); |
---|
| 118 | |
---|
[7486853] | 119 | if (!plugin_info_validate(info, path)) { |
---|
[d28fe1c4] | 120 | g_module_close(mod); |
---|
| 121 | return FALSE; |
---|
| 122 | } |
---|
| 123 | } else { |
---|
| 124 | log_message(LOGLVL_WARNING, "Can't find function `init_plugin_info' in `%s'\n", path); |
---|
| 125 | } |
---|
| 126 | |
---|
[5ebff60] | 127 | if (!g_module_symbol(mod, "init_plugin", (gpointer *) &init_function)) { |
---|
[7b23afd] | 128 | log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path); |
---|
[d28fe1c4] | 129 | g_module_close(mod); |
---|
[7b23afd] | 130 | return FALSE; |
---|
| 131 | } |
---|
| 132 | |
---|
[d28fe1c4] | 133 | if (info_function) { |
---|
[7486853] | 134 | plugin_info_add(info); |
---|
[d28fe1c4] | 135 | } |
---|
[7b23afd] | 136 | |
---|
[d28fe1c4] | 137 | init_function(); |
---|
[7b23afd] | 138 | return TRUE; |
---|
| 139 | } |
---|
[b7d3cc34] | 140 | |
---|
[65e2ce1] | 141 | void load_plugins(void) |
---|
| 142 | { |
---|
| 143 | GDir *dir; |
---|
| 144 | GError *error = NULL; |
---|
| 145 | |
---|
[4bfca70] | 146 | dir = g_dir_open(global.conf->plugindir, 0, &error); |
---|
[65e2ce1] | 147 | |
---|
| 148 | if (dir) { |
---|
| 149 | const gchar *entry; |
---|
| 150 | char *path; |
---|
| 151 | |
---|
| 152 | while ((entry = g_dir_read_name(dir))) { |
---|
[35712b7] | 153 | if (!g_str_has_suffix(entry, "." G_MODULE_SUFFIX)) { |
---|
| 154 | continue; |
---|
| 155 | } |
---|
| 156 | |
---|
[4bfca70] | 157 | path = g_build_filename(global.conf->plugindir, entry, NULL); |
---|
[5ebff60] | 158 | if (!path) { |
---|
[65e2ce1] | 159 | log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); |
---|
| 160 | continue; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | load_plugin(path); |
---|
| 164 | |
---|
| 165 | g_free(path); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | g_dir_close(dir); |
---|
| 169 | } |
---|
| 170 | } |
---|
[d28fe1c4] | 171 | |
---|
| 172 | GList *get_plugins() |
---|
| 173 | { |
---|
| 174 | return plugins; |
---|
| 175 | } |
---|
[65e2ce1] | 176 | #endif |
---|
[b7d3cc34] | 177 | |
---|
[7b23afd] | 178 | GList *protocols = NULL; |
---|
[ad9ac5d] | 179 | GList *disabled_protocols = NULL; |
---|
[5ebff60] | 180 | |
---|
| 181 | void register_protocol(struct prpl *p) |
---|
[7b23afd] | 182 | { |
---|
[90cd6c4] | 183 | int i; |
---|
| 184 | gboolean refused = global.conf->protocols != NULL; |
---|
[5ebff60] | 185 | |
---|
| 186 | for (i = 0; global.conf->protocols && global.conf->protocols[i]; i++) { |
---|
| 187 | if (g_strcasecmp(p->name, global.conf->protocols[i]) == 0) { |
---|
[90cd6c4] | 188 | refused = FALSE; |
---|
[5ebff60] | 189 | } |
---|
| 190 | } |
---|
[90cd6c4] | 191 | |
---|
[5ebff60] | 192 | if (refused) { |
---|
[ad9ac5d] | 193 | disabled_protocols = g_list_append(disabled_protocols, p); |
---|
[5ebff60] | 194 | } else { |
---|
[90cd6c4] | 195 | protocols = g_list_append(protocols, p); |
---|
[5ebff60] | 196 | } |
---|
[7b23afd] | 197 | } |
---|
| 198 | |
---|
[ad9ac5d] | 199 | static int proto_name_cmp(const void *proto_, const void *name) |
---|
[7b23afd] | 200 | { |
---|
[ad9ac5d] | 201 | const struct prpl *proto = proto_; |
---|
| 202 | return g_strcasecmp(proto->name, name); |
---|
| 203 | } |
---|
[5ebff60] | 204 | |
---|
[ad9ac5d] | 205 | struct prpl *find_protocol(const char *name) |
---|
| 206 | { |
---|
| 207 | GList *gl = g_list_find_custom(protocols, name, proto_name_cmp); |
---|
| 208 | return gl ? gl->data: NULL; |
---|
| 209 | } |
---|
[5ebff60] | 210 | |
---|
[ad9ac5d] | 211 | gboolean is_protocol_disabled(const char *name) |
---|
| 212 | { |
---|
| 213 | return g_list_find_custom(disabled_protocols, name, proto_name_cmp) != NULL; |
---|
[7b23afd] | 214 | } |
---|
| 215 | |
---|
[b4f496e] | 216 | /* Returns heap allocated string with text attempting to explain why a protocol is missing |
---|
| 217 | * Free the return value with g_free() */ |
---|
| 218 | char *explain_unknown_protocol(const char *name) |
---|
| 219 | { |
---|
| 220 | char *extramsg = NULL; |
---|
| 221 | |
---|
| 222 | if (is_protocol_disabled(name)) { |
---|
| 223 | return g_strdup("Protocol disabled in the global config (bitlbee.conf)"); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | if (strcmp(name, "yahoo") == 0) { |
---|
| 227 | return g_strdup("The old yahoo protocol is gone, try the funyahoo++ libpurple plugin instead."); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | #ifdef WITH_PURPLE |
---|
| 231 | if ((strcmp(name, "msn") == 0) || |
---|
| 232 | (strcmp(name, "loubserp-mxit") == 0) || |
---|
| 233 | (strcmp(name, "myspace") == 0)) { |
---|
| 234 | return g_strdup("This protocol has been removed from your libpurple version."); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | if (strcmp(name, "hipchat") == 0) { |
---|
| 238 | return g_strdup("This account type isn't supported by libpurple's jabber."); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | #else |
---|
| 242 | extramsg = "If this is a libpurple plugin, you might need to install bitlbee-libpurple instead."; |
---|
| 243 | #endif |
---|
| 244 | return g_strconcat("The protocol plugin is not installed or could not be loaded. " |
---|
| 245 | "Use the `plugins' command to list available protocols. ", |
---|
| 246 | extramsg, NULL); |
---|
| 247 | } |
---|
| 248 | |
---|
[b7d3cc34] | 249 | void nogaim_init() |
---|
| 250 | { |
---|
[0da65d5] | 251 | extern void jabber_initmodule(); |
---|
[1b221e0] | 252 | extern void twitter_initmodule(); |
---|
[796da03] | 253 | extern void purple_initmodule(); |
---|
[7b23afd] | 254 | |
---|
[b7d3cc34] | 255 | #ifdef WITH_JABBER |
---|
[0da65d5] | 256 | jabber_initmodule(); |
---|
[b7d3cc34] | 257 | #endif |
---|
[7b23afd] | 258 | |
---|
[1b221e0] | 259 | #ifdef WITH_TWITTER |
---|
| 260 | twitter_initmodule(); |
---|
| 261 | #endif |
---|
| 262 | |
---|
[796da03] | 263 | #ifdef WITH_PURPLE |
---|
| 264 | purple_initmodule(); |
---|
| 265 | #endif |
---|
[7b23afd] | 266 | |
---|
[65e2ce1] | 267 | #ifdef WITH_PLUGINS |
---|
| 268 | load_plugins(); |
---|
[b7d3cc34] | 269 | #endif |
---|
| 270 | } |
---|
| 271 | |
---|
[808825e] | 272 | GList *get_protocols() |
---|
| 273 | { |
---|
| 274 | return protocols; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | GList *get_protocols_disabled() |
---|
| 278 | { |
---|
| 279 | return disabled_protocols; |
---|
| 280 | } |
---|
| 281 | |
---|
[5ebff60] | 282 | GSList *get_connections() |
---|
| 283 | { |
---|
| 284 | return connections; |
---|
| 285 | } |
---|
[b7d3cc34] | 286 | |
---|
[5ebff60] | 287 | struct im_connection *imcb_new(account_t *acc) |
---|
[b7d3cc34] | 288 | { |
---|
[0da65d5] | 289 | struct im_connection *ic; |
---|
[9e83b15] | 290 | GHashFunc fn_hash = NULL; |
---|
| 291 | GEqualFunc fn_equal = NULL; |
---|
[5ebff60] | 292 | |
---|
| 293 | ic = g_new0(struct im_connection, 1); |
---|
| 294 | |
---|
[81e04e1] | 295 | ic->bee = acc->bee; |
---|
[0da65d5] | 296 | ic->acc = acc; |
---|
| 297 | acc->ic = ic; |
---|
[5ebff60] | 298 | |
---|
[9e83b15] | 299 | /* figure out if we have hashing functions compatible with handle_cmp */ |
---|
| 300 | if (acc->prpl->handle_cmp == g_ascii_strcasecmp) { |
---|
| 301 | fn_hash = b_istr_hash; |
---|
| 302 | fn_equal = b_istr_equal; |
---|
| 303 | } else if (acc->prpl->handle_cmp == g_strcmp0 || acc->prpl->handle_cmp == strcmp) { |
---|
| 304 | fn_hash = g_str_hash; |
---|
| 305 | fn_equal = g_str_equal; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | /* only create the hash table if we found them */ |
---|
| 309 | if (fn_hash && fn_equal) { |
---|
| 310 | ic->bee_users = g_hash_table_new_full(fn_hash, fn_equal, NULL, NULL); |
---|
| 311 | } |
---|
| 312 | |
---|
[5ebff60] | 313 | connections = g_slist_append(connections, ic); |
---|
| 314 | |
---|
| 315 | return(ic); |
---|
[b7d3cc34] | 316 | } |
---|
| 317 | |
---|
[5ebff60] | 318 | void imc_free(struct im_connection *ic) |
---|
[b7d3cc34] | 319 | { |
---|
| 320 | account_t *a; |
---|
[5ebff60] | 321 | |
---|
[b7d3cc34] | 322 | /* Destroy the pointer to this connection from the account list */ |
---|
[5ebff60] | 323 | for (a = ic->bee->accounts; a; a = a->next) { |
---|
| 324 | if (a->ic == ic) { |
---|
[0da65d5] | 325 | a->ic = NULL; |
---|
[b7d3cc34] | 326 | break; |
---|
| 327 | } |
---|
[5ebff60] | 328 | } |
---|
| 329 | |
---|
[9e83b15] | 330 | if (ic->bee_users) { |
---|
| 331 | g_hash_table_destroy(ic->bee_users); |
---|
| 332 | } |
---|
| 333 | |
---|
[5ebff60] | 334 | connections = g_slist_remove(connections, ic); |
---|
| 335 | g_free(ic); |
---|
[b7d3cc34] | 336 | } |
---|
| 337 | |
---|
[5ebff60] | 338 | static void serv_got_crap(struct im_connection *ic, char *format, ...) |
---|
[b7d3cc34] | 339 | { |
---|
| 340 | va_list params; |
---|
[e27661d] | 341 | char *text; |
---|
[dfde8e0] | 342 | account_t *a; |
---|
[5ebff60] | 343 | |
---|
[03df717] | 344 | if (!ic->bee->ui->log) { |
---|
| 345 | return; |
---|
| 346 | } |
---|
| 347 | |
---|
[5ebff60] | 348 | va_start(params, format); |
---|
| 349 | text = g_strdup_vprintf(format, params); |
---|
| 350 | va_end(params); |
---|
| 351 | |
---|
| 352 | if ((g_strcasecmp(set_getstr(&ic->bee->set, "strip_html"), "always") == 0) || |
---|
| 353 | ((ic->flags & OPT_DOES_HTML) && set_getbool(&ic->bee->set, "strip_html"))) { |
---|
| 354 | strip_html(text); |
---|
| 355 | } |
---|
| 356 | |
---|
[dfde8e0] | 357 | /* Try to find a different connection on the same protocol. */ |
---|
[5ebff60] | 358 | for (a = ic->bee->accounts; a; a = a->next) { |
---|
| 359 | if (a->prpl == ic->acc->prpl && a->ic != ic) { |
---|
[dfde8e0] | 360 | break; |
---|
[5ebff60] | 361 | } |
---|
| 362 | } |
---|
| 363 | |
---|
[e27661d] | 364 | /* If we found one, include the screenname in the message. */ |
---|
[5ebff60] | 365 | if (a) { |
---|
[03df717] | 366 | ic->bee->ui->log(ic->bee, ic->acc->tag, text); |
---|
[5ebff60] | 367 | } else { |
---|
[03df717] | 368 | ic->bee->ui->log(ic->bee, ic->acc->prpl->name, text); |
---|
[5ebff60] | 369 | } |
---|
| 370 | |
---|
| 371 | g_free(text); |
---|
[b7d3cc34] | 372 | } |
---|
| 373 | |
---|
[5ebff60] | 374 | void imcb_log(struct im_connection *ic, char *format, ...) |
---|
[aef4828] | 375 | { |
---|
| 376 | va_list params; |
---|
| 377 | char *text; |
---|
[5ebff60] | 378 | |
---|
| 379 | va_start(params, format); |
---|
| 380 | text = g_strdup_vprintf(format, params); |
---|
| 381 | va_end(params); |
---|
| 382 | |
---|
| 383 | if (ic->flags & OPT_LOGGED_IN) { |
---|
| 384 | serv_got_crap(ic, "%s", text); |
---|
| 385 | } else { |
---|
| 386 | serv_got_crap(ic, "Logging in: %s", text); |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | g_free(text); |
---|
[aef4828] | 390 | } |
---|
| 391 | |
---|
[5ebff60] | 392 | void imcb_error(struct im_connection *ic, char *format, ...) |
---|
[aef4828] | 393 | { |
---|
| 394 | va_list params; |
---|
| 395 | char *text; |
---|
[5ebff60] | 396 | |
---|
| 397 | va_start(params, format); |
---|
| 398 | text = g_strdup_vprintf(format, params); |
---|
| 399 | va_end(params); |
---|
| 400 | |
---|
| 401 | if (ic->flags & OPT_LOGGED_IN) { |
---|
| 402 | serv_got_crap(ic, "Error: %s", text); |
---|
| 403 | } else { |
---|
| 404 | serv_got_crap(ic, "Login error: %s", text); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | g_free(text); |
---|
[aef4828] | 408 | } |
---|
| 409 | |
---|
[5ebff60] | 410 | static gboolean send_keepalive(gpointer d, gint fd, b_input_condition cond) |
---|
[b7d3cc34] | 411 | { |
---|
[0da65d5] | 412 | struct im_connection *ic = d; |
---|
[5ebff60] | 413 | |
---|
| 414 | if ((ic->flags & OPT_PONGS) && !(ic->flags & OPT_PONGED)) { |
---|
[e132b60] | 415 | /* This protocol is expected to ack keepalives and hasn't |
---|
| 416 | since the last time we were here. */ |
---|
[5ebff60] | 417 | imcb_error(ic, "Connection timeout"); |
---|
| 418 | imc_logout(ic, TRUE); |
---|
[e132b60] | 419 | return FALSE; |
---|
| 420 | } |
---|
| 421 | ic->flags &= ~OPT_PONGED; |
---|
[5ebff60] | 422 | |
---|
| 423 | if (ic->acc->prpl->keepalive) { |
---|
| 424 | ic->acc->prpl->keepalive(ic); |
---|
| 425 | } |
---|
| 426 | |
---|
[b7d3cc34] | 427 | return TRUE; |
---|
| 428 | } |
---|
| 429 | |
---|
[5ebff60] | 430 | void start_keepalives(struct im_connection *ic, int interval) |
---|
[e132b60] | 431 | { |
---|
[5ebff60] | 432 | b_event_remove(ic->keepalive); |
---|
| 433 | ic->keepalive = b_timeout_add(interval, send_keepalive, ic); |
---|
| 434 | |
---|
[e132b60] | 435 | /* Connecting successfully counts as a first successful pong. */ |
---|
[5ebff60] | 436 | if (ic->flags & OPT_PONGS) { |
---|
[e132b60] | 437 | ic->flags |= OPT_PONGED; |
---|
[5ebff60] | 438 | } |
---|
[e132b60] | 439 | } |
---|
| 440 | |
---|
[5ebff60] | 441 | void imcb_connected(struct im_connection *ic) |
---|
[b7d3cc34] | 442 | { |
---|
| 443 | /* MSN servers sometimes redirect you to a different server and do |
---|
[84c1a0a] | 444 | the whole login sequence again, so these "late" calls to this |
---|
[b7d3cc34] | 445 | function should be handled correctly. (IOW, ignored) */ |
---|
[5ebff60] | 446 | if (ic->flags & OPT_LOGGED_IN) { |
---|
[b7d3cc34] | 447 | return; |
---|
[5ebff60] | 448 | } |
---|
[11e7828] | 449 | |
---|
[5ebff60] | 450 | if (ic->acc->flags & ACC_FLAG_LOCAL) { |
---|
[11e7828] | 451 | GHashTableIter nicks; |
---|
| 452 | gpointer k, v; |
---|
[5ebff60] | 453 | g_hash_table_iter_init(&nicks, ic->acc->nicks); |
---|
| 454 | while (g_hash_table_iter_next(&nicks, &k, &v)) { |
---|
| 455 | ic->acc->prpl->add_buddy(ic, (char *) k, NULL); |
---|
[11e7828] | 456 | } |
---|
| 457 | } |
---|
[5ebff60] | 458 | |
---|
| 459 | imcb_log(ic, "Logged in"); |
---|
| 460 | |
---|
[0da65d5] | 461 | ic->flags |= OPT_LOGGED_IN; |
---|
[5ebff60] | 462 | start_keepalives(ic, 60000); |
---|
| 463 | |
---|
[58adb7e] | 464 | /* Necessary to send initial presence status, even if we're not away. */ |
---|
[5ebff60] | 465 | imc_away_send_update(ic); |
---|
| 466 | |
---|
[280e655] | 467 | /* Apparently we're connected successfully, so reset the |
---|
| 468 | exponential backoff timer. */ |
---|
| 469 | ic->acc->auto_reconnect_delay = 0; |
---|
[5ebff60] | 470 | |
---|
| 471 | if (ic->bee->ui->imc_connected) { |
---|
| 472 | ic->bee->ui->imc_connected(ic); |
---|
| 473 | } |
---|
[b7d3cc34] | 474 | } |
---|
| 475 | |
---|
[5ebff60] | 476 | gboolean auto_reconnect(gpointer data, gint fd, b_input_condition cond) |
---|
[b7d3cc34] | 477 | { |
---|
| 478 | account_t *a = data; |
---|
[5ebff60] | 479 | |
---|
[b7d3cc34] | 480 | a->reconnect = 0; |
---|
[5ebff60] | 481 | account_on(a->bee, a); |
---|
| 482 | |
---|
| 483 | return(FALSE); /* Only have to run the timeout once */ |
---|
[b7d3cc34] | 484 | } |
---|
| 485 | |
---|
[5ebff60] | 486 | void cancel_auto_reconnect(account_t *a) |
---|
[b7d3cc34] | 487 | { |
---|
[5ebff60] | 488 | b_event_remove(a->reconnect); |
---|
[b7d3cc34] | 489 | a->reconnect = 0; |
---|
| 490 | } |
---|
| 491 | |
---|
[5ebff60] | 492 | void imc_logout(struct im_connection *ic, int allow_reconnect) |
---|
[b7d3cc34] | 493 | { |
---|
[81e04e1] | 494 | bee_t *bee = ic->bee; |
---|
[b7d3cc34] | 495 | account_t *a; |
---|
[81e04e1] | 496 | GSList *l; |
---|
[4230221] | 497 | int delay; |
---|
[5ebff60] | 498 | |
---|
[8d74291] | 499 | /* Nested calls might happen sometimes, this is probably the best |
---|
| 500 | place to catch them. */ |
---|
[5ebff60] | 501 | if (ic->flags & OPT_LOGGING_OUT) { |
---|
[8d74291] | 502 | return; |
---|
[5ebff60] | 503 | } else { |
---|
[0da65d5] | 504 | ic->flags |= OPT_LOGGING_OUT; |
---|
[5ebff60] | 505 | } |
---|
| 506 | |
---|
| 507 | if (ic->bee->ui->imc_disconnected) { |
---|
| 508 | ic->bee->ui->imc_disconnected(ic); |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | imcb_log(ic, "Signing off.."); |
---|
| 512 | |
---|
[0dd6570] | 513 | /* TBH I don't remember anymore why I didn't just use ic->acc... */ |
---|
[5ebff60] | 514 | for (a = bee->accounts; a; a = a->next) { |
---|
| 515 | if (a->ic == ic) { |
---|
[0dd6570] | 516 | break; |
---|
[5ebff60] | 517 | } |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | if (a && !allow_reconnect && !(ic->flags & OPT_LOGGED_IN) && |
---|
| 521 | set_getbool(&a->set, "oauth")) { |
---|
[0dd6570] | 522 | /* If this account supports OAuth, we're not logged in yet and |
---|
| 523 | not allowed to retry, assume there were auth issues. Give a |
---|
| 524 | helpful message on what might be necessary to fix this. */ |
---|
[5ebff60] | 525 | imcb_log(ic, "If you're having problems logging in, try re-requesting " |
---|
| 526 | "an OAuth token: account %s set password \"\"", a->tag); |
---|
[0dd6570] | 527 | } |
---|
[5ebff60] | 528 | |
---|
| 529 | for (l = bee->users; l; ) { |
---|
[81e04e1] | 530 | bee_user_t *bu = l->data; |
---|
[eabc9d2] | 531 | GSList *next = l->next; |
---|
[5ebff60] | 532 | |
---|
| 533 | if (bu->ic == ic) { |
---|
| 534 | bee_user_free(bee, bu); |
---|
| 535 | } |
---|
| 536 | |
---|
[eabc9d2] | 537 | l = next; |
---|
[b7d3cc34] | 538 | } |
---|
[5ebff60] | 539 | |
---|
| 540 | b_event_remove(ic->keepalive); |
---|
[be7a180] | 541 | ic->keepalive = 0; |
---|
[5ebff60] | 542 | ic->acc->prpl->logout(ic); |
---|
| 543 | b_event_remove(ic->inpa); |
---|
| 544 | |
---|
| 545 | g_free(ic->away); |
---|
[be7a180] | 546 | ic->away = NULL; |
---|
[5ebff60] | 547 | |
---|
| 548 | query_del_by_conn((irc_t *) ic->bee->ui_data, ic); |
---|
| 549 | |
---|
| 550 | if (!a) { |
---|
[b7d3cc34] | 551 | /* Uhm... This is very sick. */ |
---|
[5ebff60] | 552 | } else if (allow_reconnect && set_getbool(&bee->set, "auto_reconnect") && |
---|
| 553 | set_getbool(&a->set, "auto_reconnect") && |
---|
| 554 | (delay = account_reconnect_delay(a)) > 0) { |
---|
| 555 | imcb_log(ic, "Reconnecting in %d seconds..", delay); |
---|
| 556 | a->reconnect = b_timeout_add(delay * 1000, auto_reconnect, a); |
---|
[b7d3cc34] | 557 | } |
---|
[5ebff60] | 558 | |
---|
| 559 | imc_free(ic); |
---|
[b7d3cc34] | 560 | } |
---|
| 561 | |
---|
[5ebff60] | 562 | void imcb_ask(struct im_connection *ic, char *msg, void *data, |
---|
| 563 | query_callback doit, query_callback dont) |
---|
[b7d3cc34] | 564 | { |
---|
[5ebff60] | 565 | query_add((irc_t *) ic->bee->ui_data, ic, msg, doit, dont, g_free, data); |
---|
[b7d3cc34] | 566 | } |
---|
| 567 | |
---|
[5ebff60] | 568 | void imcb_ask_with_free(struct im_connection *ic, char *msg, void *data, |
---|
| 569 | query_callback doit, query_callback dont, query_callback myfree) |
---|
[d0527c1] | 570 | { |
---|
[5ebff60] | 571 | query_add((irc_t *) ic->bee->ui_data, ic, msg, doit, dont, myfree, data); |
---|
[d0527c1] | 572 | } |
---|
| 573 | |
---|
[5ebff60] | 574 | void imcb_add_buddy(struct im_connection *ic, const char *handle, const char *group) |
---|
[b7d3cc34] | 575 | { |
---|
[81e04e1] | 576 | bee_user_t *bu; |
---|
| 577 | bee_t *bee = ic->bee; |
---|
[8b61469] | 578 | bee_group_t *oldg; |
---|
[5ebff60] | 579 | |
---|
| 580 | if (!(bu = bee_user_by_handle(bee, ic, handle))) { |
---|
| 581 | bu = bee_user_new(bee, ic, handle, 0); |
---|
| 582 | } |
---|
| 583 | |
---|
[8b61469] | 584 | oldg = bu->group; |
---|
[5ebff60] | 585 | bu->group = bee_group_by_name(bee, group, TRUE); |
---|
| 586 | |
---|
| 587 | if (bee->ui->user_group && bu->group != oldg) { |
---|
| 588 | bee->ui->user_group(bee, bu); |
---|
| 589 | } |
---|
[b7d3cc34] | 590 | } |
---|
| 591 | |
---|
[5ebff60] | 592 | void imcb_rename_buddy(struct im_connection *ic, const char *handle, const char *fullname) |
---|
[b7d3cc34] | 593 | { |
---|
[1d39159] | 594 | bee_t *bee = ic->bee; |
---|
[5ebff60] | 595 | bee_user_t *bu = bee_user_by_handle(bee, ic, handle); |
---|
| 596 | |
---|
| 597 | if (!bu || !fullname) { |
---|
| 598 | return; |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | if (!bu->fullname || strcmp(bu->fullname, fullname) != 0) { |
---|
| 602 | g_free(bu->fullname); |
---|
| 603 | bu->fullname = g_strdup(fullname); |
---|
| 604 | |
---|
| 605 | if (bee->ui->user_fullname) { |
---|
| 606 | bee->ui->user_fullname(bee, bu); |
---|
| 607 | } |
---|
[b7d3cc34] | 608 | } |
---|
| 609 | } |
---|
| 610 | |
---|
[5ebff60] | 611 | void imcb_remove_buddy(struct im_connection *ic, const char *handle, char *group) |
---|
[998b103] | 612 | { |
---|
[5ebff60] | 613 | bee_user_free(ic->bee, bee_user_by_handle(ic->bee, ic, handle)); |
---|
[998b103] | 614 | } |
---|
| 615 | |
---|
[a42fda4] | 616 | /* Implements either imcb_buddy_nick_hint() or imcb_buddy_nick_change() depending on the value of 'change' */ |
---|
| 617 | static void buddy_nick_hint_or_change(struct im_connection *ic, const char *handle, const char *nick, gboolean change) |
---|
[d06eabf] | 618 | { |
---|
[6ef9065] | 619 | bee_t *bee = ic->bee; |
---|
[5ebff60] | 620 | bee_user_t *bu = bee_user_by_handle(bee, ic, handle); |
---|
| 621 | |
---|
| 622 | if (!bu || !nick) { |
---|
| 623 | return; |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | g_free(bu->nick); |
---|
| 627 | bu->nick = g_strdup(nick); |
---|
| 628 | |
---|
[a42fda4] | 629 | if (change && bee->ui->user_nick_change) { |
---|
| 630 | bee->ui->user_nick_change(bee, bu, nick); |
---|
| 631 | } else if (!change && bee->ui->user_nick_hint) { |
---|
[5ebff60] | 632 | bee->ui->user_nick_hint(bee, bu, nick); |
---|
| 633 | } |
---|
[d06eabf] | 634 | } |
---|
[b7d3cc34] | 635 | |
---|
[a42fda4] | 636 | /* Soft variant, for newly created users. Does nothing if it's already online */ |
---|
| 637 | void imcb_buddy_nick_hint(struct im_connection *ic, const char *handle, const char *nick) |
---|
| 638 | { |
---|
| 639 | buddy_nick_hint_or_change(ic, handle, nick, FALSE); |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | /* Hard variant, always changes the nick */ |
---|
| 643 | void imcb_buddy_nick_change(struct im_connection *ic, const char *handle, const char *nick) |
---|
| 644 | { |
---|
| 645 | buddy_nick_hint_or_change(ic, handle, nick, TRUE); |
---|
| 646 | } |
---|
[b7d3cc34] | 647 | |
---|
[5ebff60] | 648 | struct imcb_ask_cb_data { |
---|
[0da65d5] | 649 | struct im_connection *ic; |
---|
[7bf0f5f0] | 650 | char *handle; |
---|
| 651 | }; |
---|
| 652 | |
---|
[098a75b] | 653 | static void imcb_ask_cb_free(void *data) |
---|
| 654 | { |
---|
| 655 | struct imcb_ask_cb_data *cbd = data; |
---|
| 656 | |
---|
| 657 | g_free(cbd->handle); |
---|
| 658 | g_free(cbd); |
---|
| 659 | } |
---|
| 660 | |
---|
[5ebff60] | 661 | static void imcb_ask_auth_cb_no(void *data) |
---|
[7bf0f5f0] | 662 | { |
---|
[fa295e36] | 663 | struct imcb_ask_cb_data *cbd = data; |
---|
[5ebff60] | 664 | |
---|
| 665 | cbd->ic->acc->prpl->auth_deny(cbd->ic, cbd->handle); |
---|
| 666 | |
---|
[098a75b] | 667 | imcb_ask_cb_free(cbd); |
---|
[fa295e36] | 668 | } |
---|
| 669 | |
---|
[5ebff60] | 670 | static void imcb_ask_auth_cb_yes(void *data) |
---|
[fa295e36] | 671 | { |
---|
| 672 | struct imcb_ask_cb_data *cbd = data; |
---|
[5ebff60] | 673 | |
---|
| 674 | cbd->ic->acc->prpl->auth_allow(cbd->ic, cbd->handle); |
---|
| 675 | |
---|
[098a75b] | 676 | imcb_ask_cb_free(cbd); |
---|
[fa295e36] | 677 | } |
---|
| 678 | |
---|
[5ebff60] | 679 | void imcb_ask_auth(struct im_connection *ic, const char *handle, const char *realname) |
---|
[fa295e36] | 680 | { |
---|
[5ebff60] | 681 | struct imcb_ask_cb_data *data = g_new0(struct imcb_ask_cb_data, 1); |
---|
[fa295e36] | 682 | char *s, *realname_ = NULL; |
---|
[5ebff60] | 683 | |
---|
| 684 | if (realname != NULL) { |
---|
| 685 | realname_ = g_strdup_printf(" (%s)", realname); |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | s = g_strdup_printf("The user %s%s wants to add you to his/her buddy list.", |
---|
| 689 | handle, realname_ ? realname_ : ""); |
---|
| 690 | |
---|
| 691 | g_free(realname_); |
---|
| 692 | |
---|
[fa295e36] | 693 | data->ic = ic; |
---|
[5ebff60] | 694 | data->handle = g_strdup(handle); |
---|
| 695 | query_add((irc_t *) ic->bee->ui_data, ic, s, |
---|
[098a75b] | 696 | imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, imcb_ask_cb_free, data); |
---|
[fa295e36] | 697 | |
---|
[098a75b] | 698 | g_free(s); |
---|
[7bf0f5f0] | 699 | } |
---|
| 700 | |
---|
[5ebff60] | 701 | static void imcb_ask_add_cb_yes(void *data) |
---|
[7bf0f5f0] | 702 | { |
---|
[fa295e36] | 703 | struct imcb_ask_cb_data *cbd = data; |
---|
[5ebff60] | 704 | |
---|
| 705 | cbd->ic->acc->prpl->add_buddy(cbd->ic, cbd->handle, NULL); |
---|
| 706 | |
---|
[098a75b] | 707 | imcb_ask_cb_free(data); |
---|
[7bf0f5f0] | 708 | } |
---|
| 709 | |
---|
[5ebff60] | 710 | void imcb_ask_add(struct im_connection *ic, const char *handle, const char *realname) |
---|
[b7d3cc34] | 711 | { |
---|
[098a75b] | 712 | struct imcb_ask_cb_data *data; |
---|
[7bf0f5f0] | 713 | char *s; |
---|
[5ebff60] | 714 | |
---|
[7bf0f5f0] | 715 | /* TODO: Make a setting for this! */ |
---|
[5ebff60] | 716 | if (bee_user_by_handle(ic->bee, ic, handle) != NULL) { |
---|
[7bf0f5f0] | 717 | return; |
---|
[5ebff60] | 718 | } |
---|
| 719 | |
---|
[098a75b] | 720 | data = g_new0(struct imcb_ask_cb_data, 1); |
---|
| 721 | |
---|
[5ebff60] | 722 | s = g_strdup_printf("The user %s is not in your buddy list yet. Do you want to add him/her now?", handle); |
---|
| 723 | |
---|
[0da65d5] | 724 | data->ic = ic; |
---|
[5ebff60] | 725 | data->handle = g_strdup(handle); |
---|
| 726 | query_add((irc_t *) ic->bee->ui_data, ic, s, |
---|
[098a75b] | 727 | imcb_ask_add_cb_yes, imcb_ask_cb_free, imcb_ask_cb_free, data); |
---|
| 728 | |
---|
| 729 | g_free(s); |
---|
[b7d3cc34] | 730 | } |
---|
| 731 | |
---|
[5ebff60] | 732 | struct bee_user *imcb_buddy_by_handle(struct im_connection *ic, const char *handle) |
---|
[81e04e1] | 733 | { |
---|
[5ebff60] | 734 | return bee_user_by_handle(ic->bee, ic, handle); |
---|
[b7d3cc34] | 735 | } |
---|
| 736 | |
---|
[226fce1] | 737 | /* The plan is to not allow straight calls to prpl functions anymore, but do |
---|
| 738 | them all from some wrappers. We'll start to define some down here: */ |
---|
| 739 | |
---|
[5ebff60] | 740 | int imc_chat_msg(struct groupchat *c, char *msg, int flags) |
---|
[b7d3cc34] | 741 | { |
---|
[e27661d] | 742 | char *buf = NULL; |
---|
[5ebff60] | 743 | |
---|
| 744 | if ((c->ic->flags & OPT_DOES_HTML) && (g_strncasecmp(msg, "<html>", 6) != 0)) { |
---|
| 745 | buf = escape_html(msg); |
---|
[b7d3cc34] | 746 | msg = buf; |
---|
| 747 | } |
---|
[5ebff60] | 748 | |
---|
| 749 | c->ic->acc->prpl->chat_msg(c, msg, flags); |
---|
| 750 | g_free(buf); |
---|
| 751 | |
---|
[0da65d5] | 752 | return 1; |
---|
[b7d3cc34] | 753 | } |
---|
[226fce1] | 754 | |
---|
[5ebff60] | 755 | static char *imc_away_state_find(GList *gcm, char *away, char **message); |
---|
[226fce1] | 756 | |
---|
[5ebff60] | 757 | int imc_away_send_update(struct im_connection *ic) |
---|
[226fce1] | 758 | { |
---|
[3e1ef92c] | 759 | char *away, *msg = NULL; |
---|
[5ebff60] | 760 | |
---|
| 761 | if (ic->acc->prpl->away_states == NULL || |
---|
| 762 | ic->acc->prpl->set_away == NULL) { |
---|
[91cec2f] | 763 | return 0; |
---|
[58adb7e] | 764 | } |
---|
[5ebff60] | 765 | |
---|
| 766 | away = set_getstr(&ic->acc->set, "away") ? |
---|
| 767 | : set_getstr(&ic->bee->set, "away"); |
---|
| 768 | if (away && *away) { |
---|
[977a9d5] | 769 | GList *m = ic->acc->prpl->away_states(ic); |
---|
[ff468a7] | 770 | if (m == NULL) { |
---|
| 771 | return 0; |
---|
| 772 | } |
---|
[5ebff60] | 773 | msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL; |
---|
[ac68733a] | 774 | away = imc_away_state_find(m, away, &msg) ? : |
---|
[eb73d05] | 775 | (imc_away_state_find(m, "away", NULL) ? : m->data); |
---|
[5ebff60] | 776 | } else if (ic->acc->flags & ACC_FLAG_STATUS_MESSAGE) { |
---|
[58adb7e] | 777 | away = NULL; |
---|
[5ebff60] | 778 | msg = set_getstr(&ic->acc->set, "status") ? |
---|
| 779 | : set_getstr(&ic->bee->set, "status"); |
---|
[226fce1] | 780 | } |
---|
[5ebff60] | 781 | |
---|
| 782 | ic->acc->prpl->set_away(ic, away, msg); |
---|
| 783 | |
---|
[34fbbf9] | 784 | return 1; |
---|
[226fce1] | 785 | } |
---|
| 786 | |
---|
[84b045d] | 787 | static char *imc_away_alias_list[8][5] = |
---|
[226fce1] | 788 | { |
---|
| 789 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
| 790 | { "NA", "N/A", "Not available", NULL }, |
---|
| 791 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
| 792 | { "Be right back", "BRB", NULL }, |
---|
| 793 | { "On the phone", "Phone", "On phone", NULL }, |
---|
| 794 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
| 795 | { "Invisible", "Hidden" }, |
---|
| 796 | { NULL } |
---|
| 797 | }; |
---|
| 798 | |
---|
[5ebff60] | 799 | static char *imc_away_state_find(GList *gcm, char *away, char **message) |
---|
[226fce1] | 800 | { |
---|
| 801 | GList *m; |
---|
| 802 | int i, j; |
---|
[5ebff60] | 803 | |
---|
| 804 | for (m = gcm; m; m = m->next) { |
---|
| 805 | if (g_strncasecmp(m->data, away, strlen(m->data)) == 0) { |
---|
[34fbbf9] | 806 | /* At least the Yahoo! module works better if message |
---|
| 807 | contains no data unless it adds something to what |
---|
| 808 | we have in state already. */ |
---|
[eb73d05] | 809 | if (message && strlen(m->data) == strlen(away)) { |
---|
[34fbbf9] | 810 | *message = NULL; |
---|
[5ebff60] | 811 | } |
---|
| 812 | |
---|
[34fbbf9] | 813 | return m->data; |
---|
| 814 | } |
---|
[5ebff60] | 815 | } |
---|
| 816 | |
---|
| 817 | for (i = 0; *imc_away_alias_list[i]; i++) { |
---|
[34fbbf9] | 818 | int keep_message; |
---|
[5ebff60] | 819 | |
---|
| 820 | for (j = 0; imc_away_alias_list[i][j]; j++) { |
---|
| 821 | if (g_strncasecmp(away, imc_away_alias_list[i][j], strlen(imc_away_alias_list[i][j])) == 0) { |
---|
| 822 | keep_message = strlen(away) != strlen(imc_away_alias_list[i][j]); |
---|
[226fce1] | 823 | break; |
---|
[34fbbf9] | 824 | } |
---|
[5ebff60] | 825 | } |
---|
| 826 | |
---|
| 827 | if (!imc_away_alias_list[i][j]) { /* If we reach the end, this row */ |
---|
| 828 | continue; /* is not what we want. Next! */ |
---|
| 829 | |
---|
| 830 | } |
---|
[226fce1] | 831 | /* Now find an entry in this row which exists in gcm */ |
---|
[5ebff60] | 832 | for (j = 0; imc_away_alias_list[i][j]; j++) { |
---|
| 833 | for (m = gcm; m; m = m->next) { |
---|
| 834 | if (g_strcasecmp(imc_away_alias_list[i][j], m->data) == 0) { |
---|
[eb73d05] | 835 | if (!keep_message && message) { |
---|
[34fbbf9] | 836 | *message = NULL; |
---|
[5ebff60] | 837 | } |
---|
| 838 | |
---|
[34fbbf9] | 839 | return imc_away_alias_list[i][j]; |
---|
| 840 | } |
---|
[5ebff60] | 841 | } |
---|
[226fce1] | 842 | } |
---|
[5ebff60] | 843 | |
---|
[34fbbf9] | 844 | /* No need to look further, apparently this state doesn't |
---|
| 845 | have any good alias for this protocol. */ |
---|
| 846 | break; |
---|
[226fce1] | 847 | } |
---|
[5ebff60] | 848 | |
---|
[34fbbf9] | 849 | return NULL; |
---|
[226fce1] | 850 | } |
---|
[da3b536] | 851 | |
---|
[5ebff60] | 852 | void imc_add_allow(struct im_connection *ic, char *handle) |
---|
[da3b536] | 853 | { |
---|
[5ebff60] | 854 | if (g_slist_find_custom(ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp) == NULL) { |
---|
| 855 | ic->permit = g_slist_prepend(ic->permit, g_strdup(handle)); |
---|
[da3b536] | 856 | } |
---|
[5ebff60] | 857 | |
---|
| 858 | ic->acc->prpl->add_permit(ic, handle); |
---|
[da3b536] | 859 | } |
---|
| 860 | |
---|
[5ebff60] | 861 | void imc_rem_allow(struct im_connection *ic, char *handle) |
---|
[da3b536] | 862 | { |
---|
| 863 | GSList *l; |
---|
[5ebff60] | 864 | |
---|
| 865 | if ((l = g_slist_find_custom(ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp))) { |
---|
| 866 | g_free(l->data); |
---|
| 867 | ic->permit = g_slist_delete_link(ic->permit, l); |
---|
[da3b536] | 868 | } |
---|
[5ebff60] | 869 | |
---|
| 870 | ic->acc->prpl->rem_permit(ic, handle); |
---|
[da3b536] | 871 | } |
---|
| 872 | |
---|
[5ebff60] | 873 | void imc_add_block(struct im_connection *ic, char *handle) |
---|
[da3b536] | 874 | { |
---|
[5ebff60] | 875 | if (g_slist_find_custom(ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp) == NULL) { |
---|
| 876 | ic->deny = g_slist_prepend(ic->deny, g_strdup(handle)); |
---|
[da3b536] | 877 | } |
---|
[5ebff60] | 878 | |
---|
| 879 | ic->acc->prpl->add_deny(ic, handle); |
---|
[da3b536] | 880 | } |
---|
| 881 | |
---|
[5ebff60] | 882 | void imc_rem_block(struct im_connection *ic, char *handle) |
---|
[da3b536] | 883 | { |
---|
| 884 | GSList *l; |
---|
[5ebff60] | 885 | |
---|
| 886 | if ((l = g_slist_find_custom(ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp))) { |
---|
| 887 | g_free(l->data); |
---|
| 888 | ic->deny = g_slist_delete_link(ic->deny, l); |
---|
[da3b536] | 889 | } |
---|
[5ebff60] | 890 | |
---|
| 891 | ic->acc->prpl->rem_deny(ic, handle); |
---|
[da3b536] | 892 | } |
---|
[85023c6] | 893 | |
---|
[d6e2aa8] | 894 | /* Deprecated: using this function resulted in merging several handles accidentally |
---|
| 895 | * Also the irc layer handles this decently nowadays */ |
---|
[5ebff60] | 896 | void imcb_clean_handle(struct im_connection *ic, char *handle) |
---|
[85023c6] | 897 | { |
---|
| 898 | } |
---|