[796da03] | 1 | /***************************************************************************\ |
---|
| 2 | * * |
---|
| 3 | * BitlBee - An IRC to IM gateway * |
---|
| 4 | * libpurple module - Main file * |
---|
| 5 | * * |
---|
[0e788f5] | 6 | * Copyright 2009-2012 Wilmer van der Gaast <wilmer@gaast.net> * |
---|
[796da03] | 7 | * * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify * |
---|
| 9 | * it under the terms of the GNU General Public License as published by * |
---|
| 10 | * the Free Software Foundation; either version 2 of the License, or * |
---|
| 11 | * (at your option) any later version. * |
---|
| 12 | * * |
---|
| 13 | * This program is distributed in the hope that it will be useful, * |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
---|
| 16 | * GNU General Public License for more details. * |
---|
| 17 | * * |
---|
| 18 | * You should have received a copy of the GNU General Public License along * |
---|
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., * |
---|
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * |
---|
| 21 | * * |
---|
| 22 | \***************************************************************************/ |
---|
| 23 | |
---|
[b3117f2] | 24 | #include "bitlbee.h" |
---|
[d93c8beb] | 25 | #include "bpurple.h" |
---|
[e5d8d21] | 26 | #include "help.h" |
---|
[b3117f2] | 27 | |
---|
[0ac1a375] | 28 | #include <stdarg.h> |
---|
| 29 | |
---|
[796da03] | 30 | #include <glib.h> |
---|
| 31 | #include <purple.h> |
---|
| 32 | |
---|
| 33 | GSList *purple_connections; |
---|
| 34 | |
---|
[0ac1a375] | 35 | /* This makes me VERY sad... :-( But some libpurple callbacks come in without |
---|
| 36 | any context so this is the only way to get that. Don't want to support |
---|
| 37 | libpurple in daemon mode anyway. */ |
---|
[4aa0f6b] | 38 | static bee_t *local_bee; |
---|
[0ac1a375] | 39 | |
---|
[5ebff60] | 40 | static char *set_eval_display_name(set_t *set, char *value); |
---|
[f85e9d6] | 41 | |
---|
[6a48992] | 42 | void purple_request_input_callback(guint id, struct im_connection *ic, |
---|
| 43 | const char *message, const char *who); |
---|
| 44 | |
---|
[ea90275] | 45 | void purple_transfer_cancel_all(struct im_connection *ic); |
---|
| 46 | |
---|
[6a48992] | 47 | /* purple_request_input specific stuff */ |
---|
| 48 | typedef void (*ri_callback_t)(gpointer, const gchar *); |
---|
| 49 | |
---|
| 50 | struct request_input_data { |
---|
| 51 | ri_callback_t data_callback; |
---|
| 52 | void *user_data; |
---|
[2c5ab49] | 53 | struct im_connection *ic; |
---|
| 54 | char *buddy; |
---|
| 55 | guint id; |
---|
[6a48992] | 56 | }; |
---|
| 57 | |
---|
[01d56c0] | 58 | struct purple_roomlist_data { |
---|
| 59 | GSList *chats; |
---|
| 60 | gint topic; |
---|
| 61 | gboolean initialized; |
---|
| 62 | }; |
---|
| 63 | |
---|
| 64 | |
---|
[5ebff60] | 65 | struct im_connection *purple_ic_by_pa(PurpleAccount *pa) |
---|
[860ba6a] | 66 | { |
---|
| 67 | GSList *i; |
---|
[d93c8beb] | 68 | struct purple_data *pd; |
---|
[5ebff60] | 69 | |
---|
| 70 | for (i = purple_connections; i; i = i->next) { |
---|
[d93c8beb] | 71 | pd = ((struct im_connection *) i->data)->proto_data; |
---|
| 72 | if (pd->account == pa) { |
---|
[860ba6a] | 73 | return i->data; |
---|
[5ebff60] | 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
[860ba6a] | 77 | return NULL; |
---|
| 78 | } |
---|
| 79 | |
---|
[5ebff60] | 80 | static struct im_connection *purple_ic_by_gc(PurpleConnection *gc) |
---|
[7da726b] | 81 | { |
---|
[5ebff60] | 82 | return purple_ic_by_pa(purple_connection_get_account(gc)); |
---|
[7da726b] | 83 | } |
---|
| 84 | |
---|
[5ebff60] | 85 | static gboolean purple_menu_cmp(const char *a, const char *b) |
---|
[8ad5c34] | 86 | { |
---|
[5ebff60] | 87 | while (*a && *b) { |
---|
| 88 | while (*a == '_') { |
---|
| 89 | a++; |
---|
| 90 | } |
---|
| 91 | while (*b == '_') { |
---|
| 92 | b++; |
---|
| 93 | } |
---|
| 94 | if (g_ascii_tolower(*a) != g_ascii_tolower(*b)) { |
---|
[8ad5c34] | 95 | return FALSE; |
---|
[5ebff60] | 96 | } |
---|
| 97 | |
---|
| 98 | a++; |
---|
| 99 | b++; |
---|
[8ad5c34] | 100 | } |
---|
[5ebff60] | 101 | |
---|
| 102 | return (*a == '\0' && *b == '\0'); |
---|
[8ad5c34] | 103 | } |
---|
| 104 | |
---|
[50988d1] | 105 | static char *purple_get_account_prpl_id(account_t *acc) |
---|
| 106 | { |
---|
| 107 | /* "oscar" is how non-purple bitlbee calls it, |
---|
| 108 | * and it might be icq or aim, depending on the username */ |
---|
| 109 | if (g_strcmp0(acc->prpl->name, "oscar") == 0) { |
---|
| 110 | return (g_ascii_isdigit(acc->user[0])) ? "prpl-icq" : "prpl-aim"; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | return acc->prpl->data; |
---|
| 114 | } |
---|
| 115 | |
---|
[59ccef5] | 116 | static gboolean purple_account_should_set_nick(account_t *acc) |
---|
| 117 | { |
---|
| 118 | /* whitelist of protocols that tend to have numeric or meaningless usernames, and should |
---|
| 119 | * always offer the 'alias' as a nick. this is just so that users don't have to do |
---|
| 120 | * 'account whatever set nick_format %full_name' |
---|
| 121 | */ |
---|
| 122 | char *whitelist[] = { |
---|
| 123 | "prpl-hangouts", |
---|
| 124 | "prpl-eionrobb-funyahoo-plusplus", |
---|
| 125 | "prpl-icq", |
---|
[faa7abb6] | 126 | "prpl-line", |
---|
[59ccef5] | 127 | NULL, |
---|
| 128 | }; |
---|
| 129 | char **p; |
---|
| 130 | |
---|
| 131 | for (p = whitelist; *p; p++) { |
---|
| 132 | if (g_strcmp0(acc->prpl->data, *p) == 0) { |
---|
| 133 | return TRUE; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | return FALSE; |
---|
| 138 | } |
---|
| 139 | |
---|
[5ebff60] | 140 | static void purple_init(account_t *acc) |
---|
[796da03] | 141 | { |
---|
[50988d1] | 142 | char *prpl_id = purple_get_account_prpl_id(acc); |
---|
| 143 | PurplePlugin *prpl = purple_plugins_find_with_id(prpl_id); |
---|
[0f7ee7e5] | 144 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
[52cae01] | 145 | PurpleAccount *pa; |
---|
| 146 | GList *i, *st; |
---|
[bab1c86] | 147 | set_t *s; |
---|
[7c5affca] | 148 | char help_title[64]; |
---|
| 149 | GString *help; |
---|
[3c9b095] | 150 | static gboolean dir_fixed = FALSE; |
---|
[5ebff60] | 151 | |
---|
[3c9b095] | 152 | /* Layer violation coming up: Making an exception for libpurple here. |
---|
| 153 | Dig in the IRC state a bit to get a username. Ideally we should |
---|
| 154 | check if s/he identified but this info doesn't seem *that* important. |
---|
| 155 | It's just that fecking libpurple can't *not* store this shit. |
---|
[5ebff60] | 156 | |
---|
[3c9b095] | 157 | Remember that libpurple is not really meant to be used on public |
---|
| 158 | servers anyway! */ |
---|
[5ebff60] | 159 | if (!dir_fixed) { |
---|
[e4c3041] | 160 | PurpleCertificatePool *pool; |
---|
[3c9b095] | 161 | irc_t *irc = acc->bee->ui_data; |
---|
| 162 | char *dir; |
---|
[5ebff60] | 163 | |
---|
| 164 | dir = g_strdup_printf("%s/purple/%s", global.conf->configdir, irc->user->nick); |
---|
| 165 | purple_util_set_user_dir(dir); |
---|
| 166 | g_free(dir); |
---|
| 167 | |
---|
[3c9b095] | 168 | purple_blist_load(); |
---|
| 169 | purple_prefs_load(); |
---|
[12f041d] | 170 | |
---|
| 171 | if (proxytype == PROXY_SOCKS4A) { |
---|
| 172 | /* do this here after loading prefs. yes, i know, it sucks */ |
---|
| 173 | purple_prefs_set_bool("/purple/proxy/socks4_remotedns", TRUE); |
---|
| 174 | } |
---|
| 175 | |
---|
[e4c3041] | 176 | /* re-create the certificate cache directory */ |
---|
| 177 | pool = purple_certificate_find_pool("x509", "tls_peers"); |
---|
| 178 | dir = purple_certificate_pool_mkpath(pool, NULL); |
---|
| 179 | purple_build_dir(dir, 0700); |
---|
[1ec454c] | 180 | g_free(dir); |
---|
[e4c3041] | 181 | |
---|
[3c9b095] | 182 | dir_fixed = TRUE; |
---|
| 183 | } |
---|
[5ebff60] | 184 | |
---|
| 185 | help = g_string_new(""); |
---|
| 186 | g_string_printf(help, "BitlBee libpurple module %s (%s).\n\nSupported settings:", |
---|
| 187 | (char *) acc->prpl->name, prpl->info->name); |
---|
| 188 | |
---|
| 189 | if (pi->user_splits) { |
---|
[eb4c81a] | 190 | GList *l; |
---|
[5ebff60] | 191 | g_string_append_printf(help, "\n* username: Username"); |
---|
| 192 | for (l = pi->user_splits; l; l = l->next) { |
---|
| 193 | g_string_append_printf(help, "%c%s", |
---|
| 194 | purple_account_user_split_get_separator(l->data), |
---|
| 195 | purple_account_user_split_get_text(l->data)); |
---|
| 196 | } |
---|
[eb4c81a] | 197 | } |
---|
[5ebff60] | 198 | |
---|
[52cae01] | 199 | /* Convert all protocol_options into per-account setting variables. */ |
---|
[5ebff60] | 200 | for (i = pi->protocol_options; i; i = i->next) { |
---|
[0f7ee7e5] | 201 | PurpleAccountOption *o = i->data; |
---|
| 202 | const char *name; |
---|
| 203 | char *def = NULL; |
---|
| 204 | set_eval eval = NULL; |
---|
[4dc6b8d] | 205 | void *eval_data = NULL; |
---|
| 206 | GList *io = NULL; |
---|
| 207 | GSList *opts = NULL; |
---|
[5ebff60] | 208 | |
---|
| 209 | name = purple_account_option_get_setting(o); |
---|
| 210 | |
---|
| 211 | switch (purple_account_option_get_type(o)) { |
---|
[0f7ee7e5] | 212 | case PURPLE_PREF_STRING: |
---|
[5ebff60] | 213 | def = g_strdup(purple_account_option_get_default_string(o)); |
---|
| 214 | |
---|
| 215 | g_string_append_printf(help, "\n* %s (%s), %s, default: %s", |
---|
| 216 | name, purple_account_option_get_text(o), |
---|
| 217 | "string", def); |
---|
| 218 | |
---|
[0f7ee7e5] | 219 | break; |
---|
[5ebff60] | 220 | |
---|
[0f7ee7e5] | 221 | case PURPLE_PREF_INT: |
---|
[5ebff60] | 222 | def = g_strdup_printf("%d", purple_account_option_get_default_int(o)); |
---|
[0f7ee7e5] | 223 | eval = set_eval_int; |
---|
[5ebff60] | 224 | |
---|
| 225 | g_string_append_printf(help, "\n* %s (%s), %s, default: %s", |
---|
| 226 | name, purple_account_option_get_text(o), |
---|
| 227 | "integer", def); |
---|
| 228 | |
---|
[0f7ee7e5] | 229 | break; |
---|
[5ebff60] | 230 | |
---|
[0f7ee7e5] | 231 | case PURPLE_PREF_BOOLEAN: |
---|
[5ebff60] | 232 | if (purple_account_option_get_default_bool(o)) { |
---|
| 233 | def = g_strdup("true"); |
---|
| 234 | } else { |
---|
| 235 | def = g_strdup("false"); |
---|
| 236 | } |
---|
[0f7ee7e5] | 237 | eval = set_eval_bool; |
---|
[5ebff60] | 238 | |
---|
| 239 | g_string_append_printf(help, "\n* %s (%s), %s, default: %s", |
---|
| 240 | name, purple_account_option_get_text(o), |
---|
| 241 | "boolean", def); |
---|
| 242 | |
---|
[0f7ee7e5] | 243 | break; |
---|
[5ebff60] | 244 | |
---|
[4dc6b8d] | 245 | case PURPLE_PREF_STRING_LIST: |
---|
[5ebff60] | 246 | def = g_strdup(purple_account_option_get_default_list_value(o)); |
---|
| 247 | |
---|
| 248 | g_string_append_printf(help, "\n* %s (%s), %s, default: %s", |
---|
| 249 | name, purple_account_option_get_text(o), |
---|
| 250 | "list", def); |
---|
| 251 | g_string_append(help, "\n Possible values: "); |
---|
| 252 | |
---|
| 253 | for (io = purple_account_option_get_list(o); io; io = io->next) { |
---|
[4dc6b8d] | 254 | PurpleKeyValuePair *kv = io->data; |
---|
[5ebff60] | 255 | opts = g_slist_append(opts, kv->value); |
---|
[c96c72f] | 256 | /* TODO: kv->value is not a char*, WTF? */ |
---|
[5ebff60] | 257 | if (strcmp(kv->value, kv->key) != 0) { |
---|
| 258 | g_string_append_printf(help, "%s (%s), ", (char *) kv->value, kv->key); |
---|
| 259 | } else { |
---|
| 260 | g_string_append_printf(help, "%s, ", (char *) kv->value); |
---|
| 261 | } |
---|
[4dc6b8d] | 262 | } |
---|
[5ebff60] | 263 | g_string_truncate(help, help->len - 2); |
---|
[4dc6b8d] | 264 | eval = set_eval_list; |
---|
| 265 | eval_data = opts; |
---|
[5ebff60] | 266 | |
---|
[4dc6b8d] | 267 | break; |
---|
[5ebff60] | 268 | |
---|
[0f7ee7e5] | 269 | default: |
---|
[4aa0f6b] | 270 | /** No way to talk to the user right now, invent one when |
---|
| 271 | this becomes important. |
---|
[e67e513] | 272 | irc_rootmsg( acc->irc, "Setting with unknown type: %s (%d) Expect stuff to break..\n", |
---|
[4dc6b8d] | 273 | name, purple_account_option_get_type( o ) ); |
---|
[4aa0f6b] | 274 | */ |
---|
[5ebff60] | 275 | g_string_append_printf(help, "\n* [%s] UNSUPPORTED (type %d)", |
---|
| 276 | name, purple_account_option_get_type(o)); |
---|
[b3117f2] | 277 | name = NULL; |
---|
[0f7ee7e5] | 278 | } |
---|
[5ebff60] | 279 | |
---|
| 280 | if (name != NULL) { |
---|
| 281 | s = set_add(&acc->set, name, def, eval, acc); |
---|
[0f7ee7e5] | 282 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
[4dc6b8d] | 283 | s->eval_data = eval_data; |
---|
[5ebff60] | 284 | g_free(def); |
---|
[0f7ee7e5] | 285 | } |
---|
| 286 | } |
---|
[5ebff60] | 287 | |
---|
| 288 | g_snprintf(help_title, sizeof(help_title), "purple %s", (char *) acc->prpl->name); |
---|
| 289 | help_add_mem(&global.help, help_title, help->str); |
---|
| 290 | g_string_free(help, TRUE); |
---|
| 291 | |
---|
| 292 | s = set_add(&acc->set, "display_name", NULL, set_eval_display_name, acc); |
---|
[f85e9d6] | 293 | s->flags |= ACC_SET_ONLINE_ONLY; |
---|
[5ebff60] | 294 | |
---|
| 295 | if (pi->options & OPT_PROTO_MAIL_CHECK) { |
---|
| 296 | s = set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc); |
---|
[bab1c86] | 297 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
[dd43c62] | 298 | |
---|
[b38f655] | 299 | s = set_add(&acc->set, "mail_notifications_handle", NULL, NULL, acc); |
---|
[dd43c62] | 300 | s->flags |= ACC_SET_OFFLINE_ONLY | SET_NULL_OK; |
---|
[bab1c86] | 301 | } |
---|
[5ebff60] | 302 | |
---|
| 303 | if (strcmp(prpl->info->name, "Gadu-Gadu") == 0) { |
---|
| 304 | s = set_add(&acc->set, "gg_sync_contacts", "true", set_eval_bool, acc); |
---|
| 305 | } |
---|
| 306 | |
---|
[faa7abb6] | 307 | if (g_strcmp0(prpl->info->id, "prpl-line") == 0) { |
---|
| 308 | s = set_add(&acc->set, "line-auth-token", NULL, NULL, acc); |
---|
| 309 | s->flags |= SET_HIDDEN; |
---|
| 310 | } |
---|
| 311 | |
---|
[52cae01] | 312 | /* Go through all away states to figure out if away/status messages |
---|
| 313 | are possible. */ |
---|
[50988d1] | 314 | pa = purple_account_new(acc->user, prpl_id); |
---|
[5ebff60] | 315 | for (st = purple_account_get_status_types(pa); st; st = st->next) { |
---|
| 316 | PurpleStatusPrimitive prim = purple_status_type_get_primitive(st->data); |
---|
| 317 | |
---|
| 318 | if (prim == PURPLE_STATUS_AVAILABLE) { |
---|
| 319 | if (purple_status_type_get_attr(st->data, "message")) { |
---|
[52cae01] | 320 | acc->flags |= ACC_FLAG_STATUS_MESSAGE; |
---|
[5ebff60] | 321 | } |
---|
| 322 | } else if (prim != PURPLE_STATUS_OFFLINE) { |
---|
| 323 | if (purple_status_type_get_attr(st->data, "message")) { |
---|
[52cae01] | 324 | acc->flags |= ACC_FLAG_AWAY_MESSAGE; |
---|
[5ebff60] | 325 | } |
---|
[52cae01] | 326 | } |
---|
| 327 | } |
---|
[5ebff60] | 328 | purple_accounts_remove(pa); |
---|
[796da03] | 329 | } |
---|
| 330 | |
---|
[5ebff60] | 331 | static void purple_sync_settings(account_t *acc, PurpleAccount *pa) |
---|
[b74b287] | 332 | { |
---|
[5ebff60] | 333 | PurplePlugin *prpl = purple_plugins_find_with_id(pa->protocol_id); |
---|
[b74b287] | 334 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
| 335 | GList *i; |
---|
[5ebff60] | 336 | |
---|
| 337 | for (i = pi->protocol_options; i; i = i->next) { |
---|
[b74b287] | 338 | PurpleAccountOption *o = i->data; |
---|
| 339 | const char *name; |
---|
| 340 | set_t *s; |
---|
[5ebff60] | 341 | |
---|
| 342 | name = purple_account_option_get_setting(o); |
---|
| 343 | s = set_find(&acc->set, name); |
---|
| 344 | if (s->value == NULL) { |
---|
[b74b287] | 345 | continue; |
---|
[5ebff60] | 346 | } |
---|
| 347 | |
---|
| 348 | switch (purple_account_option_get_type(o)) { |
---|
[b74b287] | 349 | case PURPLE_PREF_STRING: |
---|
[4dc6b8d] | 350 | case PURPLE_PREF_STRING_LIST: |
---|
[5ebff60] | 351 | purple_account_set_string(pa, name, set_getstr(&acc->set, name)); |
---|
[b74b287] | 352 | break; |
---|
[5ebff60] | 353 | |
---|
[b74b287] | 354 | case PURPLE_PREF_INT: |
---|
[5ebff60] | 355 | purple_account_set_int(pa, name, set_getint(&acc->set, name)); |
---|
[b74b287] | 356 | break; |
---|
[5ebff60] | 357 | |
---|
[b74b287] | 358 | case PURPLE_PREF_BOOLEAN: |
---|
[5ebff60] | 359 | purple_account_set_bool(pa, name, set_getbool(&acc->set, name)); |
---|
[b74b287] | 360 | break; |
---|
[5ebff60] | 361 | |
---|
[b74b287] | 362 | default: |
---|
| 363 | break; |
---|
| 364 | } |
---|
| 365 | } |
---|
[5ebff60] | 366 | |
---|
| 367 | if (pi->options & OPT_PROTO_MAIL_CHECK) { |
---|
| 368 | purple_account_set_check_mail(pa, set_getbool(&acc->set, "mail_notifications")); |
---|
| 369 | } |
---|
[faa7abb6] | 370 | |
---|
| 371 | if (g_strcmp0(prpl->info->id, "prpl-line") == 0) { |
---|
| 372 | const char *name = "line-auth-token"; |
---|
| 373 | purple_account_set_string(pa, name, set_getstr(&acc->set, name)); |
---|
| 374 | } |
---|
[b74b287] | 375 | } |
---|
| 376 | |
---|
[5ebff60] | 377 | static void purple_login(account_t *acc) |
---|
[796da03] | 378 | { |
---|
[5ebff60] | 379 | struct im_connection *ic = imcb_new(acc); |
---|
[d93c8beb] | 380 | struct purple_data *pd; |
---|
[5ebff60] | 381 | |
---|
| 382 | if ((local_bee != NULL && local_bee != acc->bee) || |
---|
| 383 | (global.conf->runmode == RUNMODE_DAEMON && !getenv("BITLBEE_DEBUG"))) { |
---|
| 384 | imcb_error(ic, "Daemon mode detected. Do *not* try to use libpurple in daemon mode! " |
---|
| 385 | "Please use inetd or ForkDaemon mode instead."); |
---|
| 386 | imc_logout(ic, FALSE); |
---|
[6967d01] | 387 | return; |
---|
| 388 | } |
---|
[4aa0f6b] | 389 | local_bee = acc->bee; |
---|
[5ebff60] | 390 | |
---|
[796da03] | 391 | /* For now this is needed in the _connected() handlers if using |
---|
| 392 | GLib event handling, to make sure we're not handling events |
---|
| 393 | on dead connections. */ |
---|
[5ebff60] | 394 | purple_connections = g_slist_prepend(purple_connections, ic); |
---|
| 395 | |
---|
[d93c8beb] | 396 | ic->proto_data = pd = g_new0(struct purple_data, 1); |
---|
[50988d1] | 397 | pd->account = purple_account_new(acc->user, purple_get_account_prpl_id(acc)); |
---|
[6a48992] | 398 | pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal, |
---|
| 399 | NULL, g_free); |
---|
| 400 | pd->next_request_id = 0; |
---|
[d93c8beb] | 401 | purple_account_set_password(pd->account, acc->pass); |
---|
| 402 | purple_sync_settings(acc, pd->account); |
---|
[5ebff60] | 403 | |
---|
[59ccef5] | 404 | if (purple_account_should_set_nick(acc)) { |
---|
| 405 | pd->flags = PURPLE_OPT_SHOULD_SET_NICK; |
---|
| 406 | } |
---|
| 407 | |
---|
[d93c8beb] | 408 | purple_account_set_enabled(pd->account, "BitlBee", TRUE); |
---|
[dd43c62] | 409 | |
---|
[b38f655] | 410 | if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "mail_notifications_handle")) { |
---|
| 411 | imcb_add_buddy(ic, set_getstr(&acc->set, "mail_notifications_handle"), NULL); |
---|
[dd43c62] | 412 | } |
---|
[796da03] | 413 | } |
---|
| 414 | |
---|
[5ebff60] | 415 | static void purple_logout(struct im_connection *ic) |
---|
[796da03] | 416 | { |
---|
[d93c8beb] | 417 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 418 | |
---|
[2dd23da] | 419 | if (!pd) { |
---|
| 420 | return; |
---|
| 421 | } |
---|
| 422 | |
---|
[1ec454c] | 423 | while (ic->groupchats) { |
---|
| 424 | imcb_chat_free(ic->groupchats->data); |
---|
| 425 | } |
---|
| 426 | |
---|
[ea90275] | 427 | if (pd->filetransfers) { |
---|
| 428 | purple_transfer_cancel_all(ic); |
---|
| 429 | } |
---|
| 430 | |
---|
[d93c8beb] | 431 | purple_account_set_enabled(pd->account, "BitlBee", FALSE); |
---|
[5ebff60] | 432 | purple_connections = g_slist_remove(purple_connections, ic); |
---|
[d93c8beb] | 433 | purple_accounts_remove(pd->account); |
---|
[6e991a9] | 434 | imcb_chat_list_free(ic); |
---|
[fecdd71] | 435 | g_free(pd->chat_list_server); |
---|
[6a48992] | 436 | g_hash_table_destroy(pd->input_requests); |
---|
[d93c8beb] | 437 | g_free(pd); |
---|
[796da03] | 438 | } |
---|
| 439 | |
---|
[5ebff60] | 440 | static int purple_buddy_msg(struct im_connection *ic, char *who, char *message, int flags) |
---|
[796da03] | 441 | { |
---|
[389f7be] | 442 | PurpleConversation *conv; |
---|
[d93c8beb] | 443 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 444 | |
---|
[6a48992] | 445 | if (!strncmp(who, PURPLE_REQUEST_HANDLE, sizeof(PURPLE_REQUEST_HANDLE) - 1)) { |
---|
| 446 | guint request_id = atoi(who + sizeof(PURPLE_REQUEST_HANDLE)); |
---|
| 447 | purple_request_input_callback(request_id, ic, message, who); |
---|
| 448 | return 1; |
---|
| 449 | } |
---|
| 450 | |
---|
[5ebff60] | 451 | if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
---|
[d93c8beb] | 452 | who, pd->account)) == NULL) { |
---|
[5ebff60] | 453 | conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, |
---|
[d93c8beb] | 454 | pd->account, who); |
---|
[389f7be] | 455 | } |
---|
[5ebff60] | 456 | |
---|
| 457 | purple_conv_im_send(purple_conversation_get_im_data(conv), message); |
---|
| 458 | |
---|
[0cbef26] | 459 | return 1; |
---|
[796da03] | 460 | } |
---|
| 461 | |
---|
[5ebff60] | 462 | static GList *purple_away_states(struct im_connection *ic) |
---|
[796da03] | 463 | { |
---|
[d93c8beb] | 464 | struct purple_data *pd = ic->proto_data; |
---|
[ec5e57d] | 465 | GList *st, *ret = NULL; |
---|
[5ebff60] | 466 | |
---|
[d93c8beb] | 467 | for (st = purple_account_get_status_types(pd->account); st; st = st->next) { |
---|
[5ebff60] | 468 | PurpleStatusPrimitive prim = purple_status_type_get_primitive(st->data); |
---|
| 469 | if (prim != PURPLE_STATUS_AVAILABLE && prim != PURPLE_STATUS_OFFLINE) { |
---|
| 470 | ret = g_list_append(ret, (void *) purple_status_type_get_name(st->data)); |
---|
| 471 | } |
---|
[279607e] | 472 | } |
---|
[5ebff60] | 473 | |
---|
[ec5e57d] | 474 | return ret; |
---|
[796da03] | 475 | } |
---|
| 476 | |
---|
[5ebff60] | 477 | static void purple_set_away(struct im_connection *ic, char *state_txt, char *message) |
---|
[796da03] | 478 | { |
---|
[d93c8beb] | 479 | struct purple_data *pd = ic->proto_data; |
---|
| 480 | GList *status_types = purple_account_get_status_types(pd->account), *st; |
---|
[ec5e57d] | 481 | PurpleStatusType *pst = NULL; |
---|
[279607e] | 482 | GList *args = NULL; |
---|
[5ebff60] | 483 | |
---|
| 484 | for (st = status_types; st; st = st->next) { |
---|
[ec5e57d] | 485 | pst = st->data; |
---|
[5ebff60] | 486 | |
---|
| 487 | if (state_txt == NULL && |
---|
| 488 | purple_status_type_get_primitive(pst) == PURPLE_STATUS_AVAILABLE) { |
---|
[279607e] | 489 | break; |
---|
[5ebff60] | 490 | } |
---|
[279607e] | 491 | |
---|
[5ebff60] | 492 | if (state_txt != NULL && |
---|
| 493 | g_strcasecmp(state_txt, purple_status_type_get_name(pst)) == 0) { |
---|
[ec5e57d] | 494 | break; |
---|
[5ebff60] | 495 | } |
---|
[ec5e57d] | 496 | } |
---|
[5ebff60] | 497 | |
---|
| 498 | if (message && purple_status_type_get_attr(pst, "message")) { |
---|
| 499 | args = g_list_append(args, "message"); |
---|
| 500 | args = g_list_append(args, message); |
---|
[279607e] | 501 | } |
---|
| 502 | |
---|
[d93c8beb] | 503 | purple_account_set_status_list(pd->account, |
---|
| 504 | st ? purple_status_type_get_id(pst) : "away", |
---|
[5ebff60] | 505 | TRUE, args); |
---|
| 506 | |
---|
| 507 | g_list_free(args); |
---|
[796da03] | 508 | } |
---|
| 509 | |
---|
[5ebff60] | 510 | static char *set_eval_display_name(set_t *set, char *value) |
---|
[f85e9d6] | 511 | { |
---|
| 512 | account_t *acc = set->data; |
---|
| 513 | struct im_connection *ic = acc->ic; |
---|
[5ebff60] | 514 | |
---|
| 515 | if (ic) { |
---|
| 516 | imcb_log(ic, "Changing display_name not currently supported with libpurple!"); |
---|
| 517 | } |
---|
| 518 | |
---|
[f85e9d6] | 519 | return NULL; |
---|
| 520 | } |
---|
| 521 | |
---|
[694be84] | 522 | /* Bad bad gadu-gadu, not saving buddy list by itself */ |
---|
[5ebff60] | 523 | static void purple_gg_buddylist_export(PurpleConnection *gc) |
---|
[694be84] | 524 | { |
---|
[5ebff60] | 525 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 526 | |
---|
| 527 | if (set_getstr(&ic->acc->set, "gg_sync_contacts")) { |
---|
| 528 | GList *actions = gc->prpl->info->actions(gc->prpl, gc); |
---|
[694be84] | 529 | GList *p; |
---|
[5ebff60] | 530 | for (p = g_list_first(actions); p; p = p->next) { |
---|
| 531 | if (((PurplePluginAction *) p->data) && |
---|
| 532 | purple_menu_cmp(((PurplePluginAction *) p->data)->label, |
---|
| 533 | "Upload buddylist to Server") == 0) { |
---|
[694be84] | 534 | PurplePluginAction action; |
---|
| 535 | action.plugin = gc->prpl; |
---|
| 536 | action.context = gc; |
---|
| 537 | action.user_data = NULL; |
---|
[5ebff60] | 538 | ((PurplePluginAction *) p->data)->callback(&action); |
---|
[694be84] | 539 | break; |
---|
| 540 | } |
---|
| 541 | } |
---|
[5ebff60] | 542 | g_list_free(actions); |
---|
[694be84] | 543 | } |
---|
| 544 | } |
---|
| 545 | |
---|
[5ebff60] | 546 | static void purple_gg_buddylist_import(PurpleConnection *gc) |
---|
[694be84] | 547 | { |
---|
[5ebff60] | 548 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 549 | |
---|
| 550 | if (set_getstr(&ic->acc->set, "gg_sync_contacts")) { |
---|
| 551 | GList *actions = gc->prpl->info->actions(gc->prpl, gc); |
---|
[694be84] | 552 | GList *p; |
---|
[5ebff60] | 553 | for (p = g_list_first(actions); p; p = p->next) { |
---|
| 554 | if (((PurplePluginAction *) p->data) && |
---|
| 555 | purple_menu_cmp(((PurplePluginAction *) p->data)->label, |
---|
| 556 | "Download buddylist from Server") == 0) { |
---|
[694be84] | 557 | PurplePluginAction action; |
---|
| 558 | action.plugin = gc->prpl; |
---|
| 559 | action.context = gc; |
---|
| 560 | action.user_data = NULL; |
---|
[5ebff60] | 561 | ((PurplePluginAction *) p->data)->callback(&action); |
---|
[694be84] | 562 | break; |
---|
| 563 | } |
---|
| 564 | } |
---|
[5ebff60] | 565 | g_list_free(actions); |
---|
[694be84] | 566 | } |
---|
| 567 | } |
---|
| 568 | |
---|
[5ebff60] | 569 | static void purple_add_buddy(struct im_connection *ic, char *who, char *group) |
---|
[796da03] | 570 | { |
---|
[b3117f2] | 571 | PurpleBuddy *pb; |
---|
[3e59c8d] | 572 | PurpleGroup *pg = NULL; |
---|
[d93c8beb] | 573 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 574 | |
---|
| 575 | if (group && !(pg = purple_find_group(group))) { |
---|
| 576 | pg = purple_group_new(group); |
---|
| 577 | purple_blist_add_group(pg, NULL); |
---|
[3e59c8d] | 578 | } |
---|
[694be84] | 579 | |
---|
[d93c8beb] | 580 | pb = purple_buddy_new(pd->account, who, NULL); |
---|
[5ebff60] | 581 | purple_blist_add_buddy(pb, NULL, pg, NULL); |
---|
[d93c8beb] | 582 | purple_account_add_buddy(pd->account, pb); |
---|
[5ebff60] | 583 | |
---|
[d93c8beb] | 584 | purple_gg_buddylist_export(pd->account->gc); |
---|
[796da03] | 585 | } |
---|
| 586 | |
---|
[5ebff60] | 587 | static void purple_remove_buddy(struct im_connection *ic, char *who, char *group) |
---|
[796da03] | 588 | { |
---|
[b3117f2] | 589 | PurpleBuddy *pb; |
---|
[d93c8beb] | 590 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 591 | |
---|
[d93c8beb] | 592 | pb = purple_find_buddy(pd->account, who); |
---|
[5ebff60] | 593 | if (pb != NULL) { |
---|
[a91550c] | 594 | PurpleGroup *group; |
---|
[5ebff60] | 595 | |
---|
| 596 | group = purple_buddy_get_group(pb); |
---|
[d93c8beb] | 597 | purple_account_remove_buddy(pd->account, pb, group); |
---|
[5ebff60] | 598 | |
---|
| 599 | purple_blist_remove_buddy(pb); |
---|
[b3117f2] | 600 | } |
---|
[694be84] | 601 | |
---|
[d93c8beb] | 602 | purple_gg_buddylist_export(pd->account->gc); |
---|
[796da03] | 603 | } |
---|
| 604 | |
---|
[5ebff60] | 605 | static void purple_add_permit(struct im_connection *ic, char *who) |
---|
[05a8932] | 606 | { |
---|
[d93c8beb] | 607 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 608 | |
---|
[d93c8beb] | 609 | purple_privacy_permit_add(pd->account, who, FALSE); |
---|
[05a8932] | 610 | } |
---|
| 611 | |
---|
[5ebff60] | 612 | static void purple_add_deny(struct im_connection *ic, char *who) |
---|
[05a8932] | 613 | { |
---|
[d93c8beb] | 614 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 615 | |
---|
[d93c8beb] | 616 | purple_privacy_deny_add(pd->account, who, FALSE); |
---|
[05a8932] | 617 | } |
---|
| 618 | |
---|
[5ebff60] | 619 | static void purple_rem_permit(struct im_connection *ic, char *who) |
---|
[05a8932] | 620 | { |
---|
[d93c8beb] | 621 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 622 | |
---|
[d93c8beb] | 623 | purple_privacy_permit_remove(pd->account, who, FALSE); |
---|
[05a8932] | 624 | } |
---|
| 625 | |
---|
[5ebff60] | 626 | static void purple_rem_deny(struct im_connection *ic, char *who) |
---|
[05a8932] | 627 | { |
---|
[d93c8beb] | 628 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 629 | |
---|
[d93c8beb] | 630 | purple_privacy_deny_remove(pd->account, who, FALSE); |
---|
[05a8932] | 631 | } |
---|
| 632 | |
---|
[5ebff60] | 633 | static void purple_get_info(struct im_connection *ic, char *who) |
---|
[e77c264] | 634 | { |
---|
[d93c8beb] | 635 | struct purple_data *pd = ic->proto_data; |
---|
| 636 | |
---|
| 637 | serv_get_info(purple_account_get_connection(pd->account), who); |
---|
[e77c264] | 638 | } |
---|
| 639 | |
---|
[5ebff60] | 640 | static void purple_keepalive(struct im_connection *ic) |
---|
[796da03] | 641 | { |
---|
| 642 | } |
---|
| 643 | |
---|
[5ebff60] | 644 | static int purple_send_typing(struct im_connection *ic, char *who, int flags) |
---|
[796da03] | 645 | { |
---|
[487f555] | 646 | PurpleTypingState state = PURPLE_NOT_TYPING; |
---|
[d93c8beb] | 647 | struct purple_data *pd = ic->proto_data; |
---|
[5ebff60] | 648 | |
---|
| 649 | if (flags & OPT_TYPING) { |
---|
[487f555] | 650 | state = PURPLE_TYPING; |
---|
[5ebff60] | 651 | } else if (flags & OPT_THINKING) { |
---|
[487f555] | 652 | state = PURPLE_TYPED; |
---|
[5ebff60] | 653 | } |
---|
| 654 | |
---|
[d93c8beb] | 655 | serv_send_typing(purple_account_get_connection(pd->account), who, state); |
---|
[5ebff60] | 656 | |
---|
[bad41f56] | 657 | return 1; |
---|
[796da03] | 658 | } |
---|
| 659 | |
---|
[5ebff60] | 660 | static void purple_chat_msg(struct groupchat *gc, char *message, int flags) |
---|
[f485008] | 661 | { |
---|
| 662 | PurpleConversation *pc = gc->data; |
---|
[5ebff60] | 663 | |
---|
| 664 | purple_conv_chat_send(purple_conversation_get_chat_data(pc), message); |
---|
[f485008] | 665 | } |
---|
| 666 | |
---|
[5ebff60] | 667 | struct groupchat *purple_chat_with(struct im_connection *ic, char *who) |
---|
[8ad5c34] | 668 | { |
---|
| 669 | /* No, "of course" this won't work this way. Or in fact, it almost |
---|
| 670 | does, but it only lets you send msgs to it, you won't receive |
---|
| 671 | any. Instead, we have to click the virtual menu item. |
---|
| 672 | PurpleAccount *pa = ic->proto_data; |
---|
| 673 | PurpleConversation *pc; |
---|
| 674 | PurpleConvChat *pcc; |
---|
| 675 | struct groupchat *gc; |
---|
[5ebff60] | 676 | |
---|
[8ad5c34] | 677 | gc = imcb_chat_new( ic, "BitlBee-libpurple groupchat" ); |
---|
| 678 | gc->data = pc = purple_conversation_new( PURPLE_CONV_TYPE_CHAT, pa, "BitlBee-libpurple groupchat" ); |
---|
| 679 | pc->ui_data = gc; |
---|
[5ebff60] | 680 | |
---|
[8ad5c34] | 681 | pcc = PURPLE_CONV_CHAT( pc ); |
---|
| 682 | purple_conv_chat_add_user( pcc, ic->acc->user, "", 0, TRUE ); |
---|
| 683 | purple_conv_chat_invite_user( pcc, who, "Please join my chat", FALSE ); |
---|
| 684 | //purple_conv_chat_add_user( pcc, who, "", 0, TRUE ); |
---|
| 685 | */ |
---|
[5ebff60] | 686 | |
---|
[8ad5c34] | 687 | /* There went my nice afternoon. :-( */ |
---|
[5ebff60] | 688 | |
---|
[d93c8beb] | 689 | struct purple_data *pd = ic->proto_data; |
---|
| 690 | PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); |
---|
[8ad5c34] | 691 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
[d93c8beb] | 692 | PurpleBuddy *pb = purple_find_buddy(pd->account, who); |
---|
[8ad5c34] | 693 | PurpleMenuAction *mi; |
---|
| 694 | GList *menu; |
---|
[5ebff60] | 695 | |
---|
[8ad5c34] | 696 | void (*callback)(PurpleBlistNode *, gpointer); /* FFFFFFFFFFFFFUUUUUUUUUUUUUU */ |
---|
[5ebff60] | 697 | |
---|
| 698 | if (!pb || !pi || !pi->blist_node_menu) { |
---|
[8ad5c34] | 699 | return NULL; |
---|
[5ebff60] | 700 | } |
---|
| 701 | |
---|
| 702 | menu = pi->blist_node_menu(&pb->node); |
---|
| 703 | while (menu) { |
---|
[8ad5c34] | 704 | mi = menu->data; |
---|
[5ebff60] | 705 | if (purple_menu_cmp(mi->label, "initiate chat") || |
---|
| 706 | purple_menu_cmp(mi->label, "initiate conference")) { |
---|
[8ad5c34] | 707 | break; |
---|
[5ebff60] | 708 | } |
---|
[8ad5c34] | 709 | menu = menu->next; |
---|
| 710 | } |
---|
[5ebff60] | 711 | |
---|
| 712 | if (menu == NULL) { |
---|
[8ad5c34] | 713 | return NULL; |
---|
[5ebff60] | 714 | } |
---|
| 715 | |
---|
[8ad5c34] | 716 | /* Call the fucker. */ |
---|
[5ebff60] | 717 | callback = (void *) mi->callback; |
---|
[459dec8] | 718 | callback(&pb->node, mi->data); |
---|
[5ebff60] | 719 | |
---|
[8ad5c34] | 720 | return NULL; |
---|
| 721 | } |
---|
| 722 | |
---|
[5ebff60] | 723 | void purple_chat_invite(struct groupchat *gc, char *who, char *message) |
---|
[8ad5c34] | 724 | { |
---|
| 725 | PurpleConversation *pc = gc->data; |
---|
[5ebff60] | 726 | PurpleConvChat *pcc = PURPLE_CONV_CHAT(pc); |
---|
[d93c8beb] | 727 | struct purple_data *pd = gc->ic->proto_data; |
---|
[5ebff60] | 728 | |
---|
[d93c8beb] | 729 | serv_chat_invite(purple_account_get_connection(pd->account), |
---|
[5ebff60] | 730 | purple_conv_chat_get_id(pcc), |
---|
| 731 | message && *message ? message : "Please join my chat", |
---|
| 732 | who); |
---|
[8ad5c34] | 733 | } |
---|
| 734 | |
---|
[524e931] | 735 | void purple_chat_set_topic(struct groupchat *gc, char *topic) |
---|
| 736 | { |
---|
| 737 | PurpleConversation *pc = gc->data; |
---|
| 738 | PurpleConvChat *pcc = PURPLE_CONV_CHAT(pc); |
---|
| 739 | struct purple_data *pd = gc->ic->proto_data; |
---|
| 740 | PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); |
---|
| 741 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
| 742 | |
---|
| 743 | if (pi->set_chat_topic) { |
---|
| 744 | pi->set_chat_topic(purple_account_get_connection(pd->account), |
---|
| 745 | purple_conv_chat_get_id(pcc), |
---|
| 746 | topic); |
---|
| 747 | } |
---|
| 748 | } |
---|
| 749 | |
---|
[5ebff60] | 750 | void purple_chat_kick(struct groupchat *gc, char *who, const char *message) |
---|
[e41cc40] | 751 | { |
---|
| 752 | PurpleConversation *pc = gc->data; |
---|
[5ebff60] | 753 | char *str = g_strdup_printf("kick %s %s", who, message); |
---|
| 754 | |
---|
| 755 | purple_conversation_do_command(pc, str, NULL, NULL); |
---|
| 756 | g_free(str); |
---|
[e41cc40] | 757 | } |
---|
| 758 | |
---|
[5ebff60] | 759 | void purple_chat_leave(struct groupchat *gc) |
---|
[15794dc] | 760 | { |
---|
| 761 | PurpleConversation *pc = gc->data; |
---|
[5ebff60] | 762 | |
---|
| 763 | purple_conversation_destroy(pc); |
---|
[15794dc] | 764 | } |
---|
| 765 | |
---|
[5ebff60] | 766 | struct groupchat *purple_chat_join(struct im_connection *ic, const char *room, const char *nick, const char *password, |
---|
| 767 | set_t **sets) |
---|
[c3caa46] | 768 | { |
---|
[d93c8beb] | 769 | struct purple_data *pd = ic->proto_data; |
---|
| 770 | PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); |
---|
[c3caa46] | 771 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
| 772 | GHashTable *chat_hash; |
---|
| 773 | PurpleConversation *conv; |
---|
[1a8875f] | 774 | struct groupchat *gc; |
---|
[c3caa46] | 775 | GList *info, *l; |
---|
[1882b70] | 776 | GString *missing_settings = NULL; |
---|
[5ebff60] | 777 | |
---|
| 778 | if (!pi->chat_info || !pi->chat_info_defaults || |
---|
[d93c8beb] | 779 | !(info = pi->chat_info(purple_account_get_connection(pd->account)))) { |
---|
[5ebff60] | 780 | imcb_error(ic, "Joining chatrooms not supported by this protocol"); |
---|
[c3caa46] | 781 | return NULL; |
---|
| 782 | } |
---|
[5ebff60] | 783 | |
---|
[d93c8beb] | 784 | if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, |
---|
| 785 | room, pd->account))) { |
---|
[5ebff60] | 786 | purple_conversation_destroy(conv); |
---|
| 787 | } |
---|
| 788 | |
---|
[d93c8beb] | 789 | chat_hash = pi->chat_info_defaults( |
---|
| 790 | purple_account_get_connection(pd->account), room |
---|
| 791 | ); |
---|
[5ebff60] | 792 | |
---|
| 793 | for (l = info; l; l = l->next) { |
---|
[c3caa46] | 794 | struct proto_chat_entry *pce = l->data; |
---|
[5ebff60] | 795 | |
---|
| 796 | if (strcmp(pce->identifier, "handle") == 0) { |
---|
| 797 | g_hash_table_replace(chat_hash, "handle", g_strdup(nick)); |
---|
| 798 | } else if (strcmp(pce->identifier, "password") == 0) { |
---|
| 799 | g_hash_table_replace(chat_hash, "password", g_strdup(password)); |
---|
| 800 | } else if (strcmp(pce->identifier, "passwd") == 0) { |
---|
| 801 | g_hash_table_replace(chat_hash, "passwd", g_strdup(password)); |
---|
[1882b70] | 802 | } else { |
---|
| 803 | char *key, *value; |
---|
| 804 | |
---|
| 805 | key = g_strdup_printf("purple_%s", pce->identifier); |
---|
| 806 | str_reject_chars(key, " -", '_'); |
---|
| 807 | |
---|
| 808 | if ((value = set_getstr(sets, key))) { |
---|
| 809 | /* sync from bitlbee to the prpl */ |
---|
| 810 | g_hash_table_replace(chat_hash, (char *) pce->identifier, g_strdup(value)); |
---|
| 811 | } else if ((value = g_hash_table_lookup(chat_hash, pce->identifier))) { |
---|
| 812 | /* if the bitlbee one was empty, sync from prpl to bitlbee */ |
---|
| 813 | set_setstr(sets, key, value); |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | g_free(key); |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | if (pce->required && !g_hash_table_lookup(chat_hash, pce->identifier)) { |
---|
| 820 | if (!missing_settings) { |
---|
[c11b68a] | 821 | missing_settings = g_string_sized_new(32); |
---|
[1882b70] | 822 | } |
---|
| 823 | g_string_append_printf(missing_settings, "%s, ", pce->identifier); |
---|
[5ebff60] | 824 | } |
---|
[1ec454c] | 825 | |
---|
| 826 | g_free(pce); |
---|
[c3caa46] | 827 | } |
---|
[5ebff60] | 828 | |
---|
[1ec454c] | 829 | g_list_free(info); |
---|
| 830 | |
---|
[1882b70] | 831 | if (missing_settings) { |
---|
| 832 | /* remove the ", " from the end */ |
---|
| 833 | g_string_truncate(missing_settings, missing_settings->len - 2); |
---|
| 834 | |
---|
[c11b68a] | 835 | imcb_error(ic, "Can't join %s. The following settings are required: %s", room, missing_settings->str); |
---|
[1882b70] | 836 | |
---|
| 837 | g_string_free(missing_settings, TRUE); |
---|
| 838 | g_hash_table_destroy(chat_hash); |
---|
| 839 | return NULL; |
---|
| 840 | } |
---|
| 841 | |
---|
[1a8875f] | 842 | /* do this before serv_join_chat to handle cases where prplcb_conv_new is called immediately (not async) */ |
---|
| 843 | gc = imcb_chat_new(ic, room); |
---|
| 844 | |
---|
[d93c8beb] | 845 | serv_join_chat(purple_account_get_connection(pd->account), chat_hash); |
---|
[5ebff60] | 846 | |
---|
[1ec454c] | 847 | g_hash_table_destroy(chat_hash); |
---|
| 848 | |
---|
[1a8875f] | 849 | return gc; |
---|
[c3caa46] | 850 | } |
---|
| 851 | |
---|
[725f942] | 852 | void purple_chat_list(struct im_connection *ic, const char *server) |
---|
| 853 | { |
---|
| 854 | PurpleRoomlist *list; |
---|
| 855 | struct purple_data *pd = ic->proto_data; |
---|
[01d56c0] | 856 | PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); |
---|
| 857 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
| 858 | |
---|
| 859 | if (!pi || !pi->roomlist_get_list) { |
---|
| 860 | imcb_log(ic, "Room listing unsupported by this purple plugin"); |
---|
| 861 | return; |
---|
| 862 | } |
---|
[725f942] | 863 | |
---|
[fecdd71] | 864 | g_free(pd->chat_list_server); |
---|
| 865 | pd->chat_list_server = (server && *server) ? g_strdup(server) : NULL; |
---|
| 866 | |
---|
[725f942] | 867 | list = purple_roomlist_get_list(pd->account->gc); |
---|
| 868 | |
---|
| 869 | if (list) { |
---|
[01d56c0] | 870 | struct purple_roomlist_data *rld = list->ui_data; |
---|
| 871 | rld->initialized = TRUE; |
---|
| 872 | |
---|
[725f942] | 873 | purple_roomlist_ref(list); |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | |
---|
[1882b70] | 877 | /* handles either prpl->chat_(add|free)_settings depending on the value of 'add' */ |
---|
| 878 | static void purple_chat_update_settings(account_t *acc, set_t **head, gboolean add) |
---|
| 879 | { |
---|
| 880 | PurplePlugin *prpl = purple_plugins_find_with_id((char *) acc->prpl->data); |
---|
| 881 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
| 882 | GList *info, *l; |
---|
| 883 | |
---|
| 884 | if (!pi->chat_info || !pi->chat_info_defaults) { |
---|
| 885 | return; |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | /* hack / leap of faith: pass a NULL here because we don't have a connection yet. |
---|
| 889 | * i reviewed all the built-in prpls and a bunch of third-party ones and none |
---|
| 890 | * of them seem to need this parameter at all, so... i hope it never crashes */ |
---|
| 891 | info = pi->chat_info(NULL); |
---|
| 892 | |
---|
| 893 | for (l = info; l; l = l->next) { |
---|
| 894 | struct proto_chat_entry *pce = l->data; |
---|
| 895 | char *key; |
---|
| 896 | |
---|
| 897 | if (strcmp(pce->identifier, "handle") == 0 || |
---|
| 898 | strcmp(pce->identifier, "password") == 0 || |
---|
| 899 | strcmp(pce->identifier, "passwd") == 0) { |
---|
| 900 | /* skip these, they are handled above */ |
---|
| 901 | g_free(pce); |
---|
| 902 | continue; |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | key = g_strdup_printf("purple_%s", pce->identifier); |
---|
| 906 | str_reject_chars(key, " -", '_'); |
---|
| 907 | |
---|
| 908 | if (add) { |
---|
| 909 | set_add(head, key, NULL, NULL, NULL); |
---|
| 910 | } else { |
---|
| 911 | set_del(head, key); |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | g_free(key); |
---|
| 915 | g_free(pce); |
---|
| 916 | } |
---|
| 917 | |
---|
| 918 | g_list_free(NULL); |
---|
| 919 | g_list_free(info); |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | static void purple_chat_add_settings(account_t *acc, set_t **head) |
---|
| 923 | { |
---|
| 924 | purple_chat_update_settings(acc, head, TRUE); |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | static void purple_chat_free_settings(account_t *acc, set_t **head) |
---|
| 928 | { |
---|
| 929 | purple_chat_update_settings(acc, head, FALSE); |
---|
| 930 | } |
---|
| 931 | |
---|
[5ebff60] | 932 | void purple_transfer_request(struct im_connection *ic, file_transfer_t *ft, char *handle); |
---|
[edfc6db] | 933 | |
---|
[860ba6a] | 934 | static void purple_ui_init(); |
---|
| 935 | |
---|
[dca8eff] | 936 | GHashTable *prplcb_ui_info() |
---|
| 937 | { |
---|
| 938 | static GHashTable *ret; |
---|
[5ebff60] | 939 | |
---|
| 940 | if (ret == NULL) { |
---|
[dca8eff] | 941 | ret = g_hash_table_new(g_str_hash, g_str_equal); |
---|
[5ebff60] | 942 | g_hash_table_insert(ret, "name", "BitlBee"); |
---|
| 943 | g_hash_table_insert(ret, "version", BITLBEE_VERSION); |
---|
[dca8eff] | 944 | } |
---|
[5ebff60] | 945 | |
---|
[dca8eff] | 946 | return ret; |
---|
| 947 | } |
---|
| 948 | |
---|
[5ebff60] | 949 | static PurpleCoreUiOps bee_core_uiops = |
---|
[860ba6a] | 950 | { |
---|
[98d46d5] | 951 | NULL, /* ui_prefs_init */ |
---|
| 952 | NULL, /* debug_ui_init */ |
---|
| 953 | purple_ui_init, /* ui_init */ |
---|
| 954 | NULL, /* quit */ |
---|
| 955 | prplcb_ui_info, /* get_ui_info */ |
---|
[860ba6a] | 956 | }; |
---|
| 957 | |
---|
[5ebff60] | 958 | static void prplcb_conn_progress(PurpleConnection *gc, const char *text, size_t step, size_t step_count) |
---|
[860ba6a] | 959 | { |
---|
[5ebff60] | 960 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 961 | |
---|
| 962 | imcb_log(ic, "%s", text); |
---|
[860ba6a] | 963 | } |
---|
| 964 | |
---|
[5ebff60] | 965 | static void prplcb_conn_connected(PurpleConnection *gc) |
---|
[860ba6a] | 966 | { |
---|
[5ebff60] | 967 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
[faa7abb6] | 968 | struct purple_data *pd = ic->proto_data; |
---|
| 969 | const char *dn, *token; |
---|
[f85e9d6] | 970 | set_t *s; |
---|
[5ebff60] | 971 | |
---|
| 972 | imcb_connected(ic); |
---|
| 973 | |
---|
| 974 | if ((dn = purple_connection_get_display_name(gc)) && |
---|
| 975 | (s = set_find(&ic->acc->set, "display_name"))) { |
---|
| 976 | g_free(s->value); |
---|
| 977 | s->value = g_strdup(dn); |
---|
[f85e9d6] | 978 | } |
---|
[694be84] | 979 | |
---|
| 980 | // user list needs to be requested for Gadu-Gadu |
---|
[5ebff60] | 981 | purple_gg_buddylist_import(gc); |
---|
| 982 | |
---|
[faa7abb6] | 983 | /* more awful hacks, because clearly we didn't have enough of those */ |
---|
| 984 | if ((s = set_find(&ic->acc->set, "line-auth-token")) && |
---|
| 985 | (token = purple_account_get_string(pd->account, "line-auth-token", NULL))) { |
---|
| 986 | g_free(s->value); |
---|
| 987 | s->value = g_strdup(token); |
---|
| 988 | } |
---|
| 989 | |
---|
[48b5fef] | 990 | ic->flags |= OPT_DOES_HTML; |
---|
[860ba6a] | 991 | } |
---|
| 992 | |
---|
[5ebff60] | 993 | static void prplcb_conn_disconnected(PurpleConnection *gc) |
---|
[860ba6a] | 994 | { |
---|
[5ebff60] | 995 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 996 | |
---|
| 997 | if (ic != NULL) { |
---|
| 998 | imc_logout(ic, !gc->wants_to_die); |
---|
[b74b287] | 999 | } |
---|
[860ba6a] | 1000 | } |
---|
| 1001 | |
---|
[5ebff60] | 1002 | static void prplcb_conn_notice(PurpleConnection *gc, const char *text) |
---|
[860ba6a] | 1003 | { |
---|
[5ebff60] | 1004 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 1005 | |
---|
| 1006 | if (ic != NULL) { |
---|
| 1007 | imcb_log(ic, "%s", text); |
---|
| 1008 | } |
---|
[860ba6a] | 1009 | } |
---|
| 1010 | |
---|
[5ebff60] | 1011 | static void prplcb_conn_report_disconnect_reason(PurpleConnection *gc, PurpleConnectionError reason, const char *text) |
---|
[860ba6a] | 1012 | { |
---|
[5ebff60] | 1013 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 1014 | |
---|
[860ba6a] | 1015 | /* PURPLE_CONNECTION_ERROR_NAME_IN_USE means concurrent login, |
---|
| 1016 | should probably handle that. */ |
---|
[5ebff60] | 1017 | if (ic != NULL) { |
---|
| 1018 | imcb_error(ic, "%s", text); |
---|
| 1019 | } |
---|
[860ba6a] | 1020 | } |
---|
| 1021 | |
---|
| 1022 | static PurpleConnectionUiOps bee_conn_uiops = |
---|
| 1023 | { |
---|
[98d46d5] | 1024 | prplcb_conn_progress, /* connect_progress */ |
---|
| 1025 | prplcb_conn_connected, /* connected */ |
---|
| 1026 | prplcb_conn_disconnected, /* disconnected */ |
---|
| 1027 | prplcb_conn_notice, /* notice */ |
---|
| 1028 | NULL, /* report_disconnect */ |
---|
| 1029 | NULL, /* network_connected */ |
---|
| 1030 | NULL, /* network_disconnected */ |
---|
| 1031 | prplcb_conn_report_disconnect_reason, /* report_disconnect_reason */ |
---|
[860ba6a] | 1032 | }; |
---|
| 1033 | |
---|
[5ebff60] | 1034 | static void prplcb_blist_update(PurpleBuddyList *list, PurpleBlistNode *node) |
---|
[7da726b] | 1035 | { |
---|
[5ebff60] | 1036 | if (node->type == PURPLE_BLIST_BUDDY_NODE) { |
---|
| 1037 | PurpleBuddy *bud = (PurpleBuddy *) node; |
---|
| 1038 | PurpleGroup *group = purple_buddy_get_group(bud); |
---|
| 1039 | struct im_connection *ic = purple_ic_by_pa(bud->account); |
---|
[59ccef5] | 1040 | struct purple_data *pd = ic->proto_data; |
---|
[4f103ea] | 1041 | PurpleStatus *as; |
---|
| 1042 | int flags = 0; |
---|
[59ccef5] | 1043 | char *alias = NULL; |
---|
[5ebff60] | 1044 | |
---|
| 1045 | if (ic == NULL) { |
---|
[db4cd40] | 1046 | return; |
---|
[5ebff60] | 1047 | } |
---|
| 1048 | |
---|
[59ccef5] | 1049 | alias = bud->server_alias ? : bud->alias; |
---|
| 1050 | |
---|
| 1051 | if (alias) { |
---|
| 1052 | imcb_rename_buddy(ic, bud->name, alias); |
---|
| 1053 | if (pd->flags & PURPLE_OPT_SHOULD_SET_NICK) { |
---|
| 1054 | imcb_buddy_nick_change(ic, bud->name, alias); |
---|
| 1055 | } |
---|
[5ebff60] | 1056 | } |
---|
| 1057 | |
---|
| 1058 | if (group) { |
---|
| 1059 | imcb_add_buddy(ic, bud->name, purple_group_get_name(group)); |
---|
| 1060 | } |
---|
| 1061 | |
---|
| 1062 | flags |= purple_presence_is_online(bud->presence) ? OPT_LOGGED_IN : 0; |
---|
| 1063 | flags |= purple_presence_is_available(bud->presence) ? 0 : OPT_AWAY; |
---|
| 1064 | |
---|
| 1065 | as = purple_presence_get_active_status(bud->presence); |
---|
| 1066 | |
---|
| 1067 | imcb_buddy_status(ic, bud->name, flags, purple_status_get_name(as), |
---|
| 1068 | purple_status_get_attr_string(as, "message")); |
---|
| 1069 | |
---|
| 1070 | imcb_buddy_times(ic, bud->name, |
---|
| 1071 | purple_presence_get_login_time(bud->presence), |
---|
| 1072 | purple_presence_get_idle_time(bud->presence)); |
---|
[7da726b] | 1073 | } |
---|
| 1074 | } |
---|
| 1075 | |
---|
[5ebff60] | 1076 | static void prplcb_blist_new(PurpleBlistNode *node) |
---|
[a08e875] | 1077 | { |
---|
[5ebff60] | 1078 | if (node->type == PURPLE_BLIST_BUDDY_NODE) { |
---|
| 1079 | PurpleBuddy *bud = (PurpleBuddy *) node; |
---|
| 1080 | struct im_connection *ic = purple_ic_by_pa(bud->account); |
---|
| 1081 | |
---|
| 1082 | if (ic == NULL) { |
---|
[a08e875] | 1083 | return; |
---|
[5ebff60] | 1084 | } |
---|
| 1085 | |
---|
| 1086 | imcb_add_buddy(ic, bud->name, NULL); |
---|
| 1087 | |
---|
| 1088 | prplcb_blist_update(NULL, node); |
---|
[a08e875] | 1089 | } |
---|
| 1090 | } |
---|
| 1091 | |
---|
[5ebff60] | 1092 | static void prplcb_blist_remove(PurpleBuddyList *list, PurpleBlistNode *node) |
---|
[7da726b] | 1093 | { |
---|
[a91550c] | 1094 | /* |
---|
[5ebff60] | 1095 | PurpleBuddy *bud = (PurpleBuddy*) node; |
---|
| 1096 | |
---|
| 1097 | if( node->type == PURPLE_BLIST_BUDDY_NODE ) |
---|
| 1098 | { |
---|
| 1099 | struct im_connection *ic = purple_ic_by_pa( bud->account ); |
---|
| 1100 | |
---|
| 1101 | if( ic == NULL ) |
---|
| 1102 | return; |
---|
| 1103 | |
---|
| 1104 | imcb_remove_buddy( ic, bud->name, NULL ); |
---|
| 1105 | } |
---|
[a91550c] | 1106 | */ |
---|
[7da726b] | 1107 | } |
---|
| 1108 | |
---|
| 1109 | static PurpleBlistUiOps bee_blist_uiops = |
---|
| 1110 | { |
---|
[98d46d5] | 1111 | NULL, /* new_list */ |
---|
| 1112 | prplcb_blist_new, /* new_node */ |
---|
| 1113 | NULL, /* show */ |
---|
| 1114 | prplcb_blist_update, /* update */ |
---|
| 1115 | prplcb_blist_remove, /* remove */ |
---|
[7da726b] | 1116 | }; |
---|
| 1117 | |
---|
[5ebff60] | 1118 | void prplcb_conv_new(PurpleConversation *conv) |
---|
[f485008] | 1119 | { |
---|
[5ebff60] | 1120 | if (conv->type == PURPLE_CONV_TYPE_CHAT) { |
---|
| 1121 | struct im_connection *ic = purple_ic_by_pa(conv->account); |
---|
[f485008] | 1122 | struct groupchat *gc; |
---|
[5ebff60] | 1123 | |
---|
[a3019499] | 1124 | gc = bee_chat_by_title(ic->bee, ic, conv->name); |
---|
| 1125 | |
---|
| 1126 | if (!gc) { |
---|
| 1127 | gc = imcb_chat_new(ic, conv->name); |
---|
| 1128 | if (conv->title != NULL) { |
---|
| 1129 | imcb_chat_name_hint(gc, conv->title); |
---|
| 1130 | } |
---|
| 1131 | } |
---|
| 1132 | |
---|
| 1133 | /* don't set the topic if it's just the name */ |
---|
| 1134 | if (conv->title != NULL && strcmp(conv->name, conv->title) != 0) { |
---|
[5ebff60] | 1135 | imcb_chat_topic(gc, NULL, conv->title, 0); |
---|
[fd213fe] | 1136 | } |
---|
[36ee8c6] | 1137 | |
---|
[f485008] | 1138 | conv->ui_data = gc; |
---|
| 1139 | gc->data = conv; |
---|
[5ebff60] | 1140 | |
---|
[c3caa46] | 1141 | /* libpurple brokenness: Whatever. Show that we join right away, |
---|
| 1142 | there's no clear "This is you!" signaling in _add_users so |
---|
| 1143 | don't even try. */ |
---|
[5ebff60] | 1144 | imcb_chat_add_buddy(gc, gc->ic->acc->user); |
---|
[f485008] | 1145 | } |
---|
| 1146 | } |
---|
| 1147 | |
---|
[5ebff60] | 1148 | void prplcb_conv_free(PurpleConversation *conv) |
---|
[f485008] | 1149 | { |
---|
| 1150 | struct groupchat *gc = conv->ui_data; |
---|
[5ebff60] | 1151 | |
---|
| 1152 | imcb_chat_free(gc); |
---|
[f485008] | 1153 | } |
---|
| 1154 | |
---|
[5ebff60] | 1155 | void prplcb_conv_add_users(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) |
---|
[f485008] | 1156 | { |
---|
| 1157 | struct groupchat *gc = conv->ui_data; |
---|
| 1158 | GList *b; |
---|
[5ebff60] | 1159 | |
---|
| 1160 | for (b = cbuddies; b; b = b->next) { |
---|
[f485008] | 1161 | PurpleConvChatBuddy *pcb = b->data; |
---|
[5ebff60] | 1162 | |
---|
| 1163 | imcb_chat_add_buddy(gc, pcb->name); |
---|
[f485008] | 1164 | } |
---|
| 1165 | } |
---|
| 1166 | |
---|
[5ebff60] | 1167 | void prplcb_conv_del_users(PurpleConversation *conv, GList *cbuddies) |
---|
[f485008] | 1168 | { |
---|
| 1169 | struct groupchat *gc = conv->ui_data; |
---|
| 1170 | GList *b; |
---|
[5ebff60] | 1171 | |
---|
| 1172 | for (b = cbuddies; b; b = b->next) { |
---|
| 1173 | imcb_chat_remove_buddy(gc, b->data, ""); |
---|
| 1174 | } |
---|
[f485008] | 1175 | } |
---|
| 1176 | |
---|
[ba7618d] | 1177 | /* Generic handler for IM or chat messages, covers write_chat, write_im and write_conv */ |
---|
[0e48e54] | 1178 | static void handle_conv_msg(PurpleConversation *conv, const char *who, const char *message_, guint32 bee_flags, time_t mtime) |
---|
[f485008] | 1179 | { |
---|
[ba7618d] | 1180 | struct im_connection *ic = purple_ic_by_pa(conv->account); |
---|
[f485008] | 1181 | struct groupchat *gc = conv->ui_data; |
---|
[0e48e54] | 1182 | char *message = g_strdup(message_); |
---|
[f485008] | 1183 | PurpleBuddy *buddy; |
---|
[5ebff60] | 1184 | |
---|
| 1185 | buddy = purple_find_buddy(conv->account, who); |
---|
| 1186 | if (buddy != NULL) { |
---|
| 1187 | who = purple_buddy_get_name(buddy); |
---|
| 1188 | } |
---|
| 1189 | |
---|
[ba7618d] | 1190 | if (conv->type == PURPLE_CONV_TYPE_IM) { |
---|
[0e48e54] | 1191 | imcb_buddy_msg(ic, who, message, bee_flags, mtime); |
---|
[ba7618d] | 1192 | } else if (gc) { |
---|
[0e48e54] | 1193 | imcb_chat_msg(gc, who, message, bee_flags, mtime); |
---|
[ba7618d] | 1194 | } |
---|
[0e48e54] | 1195 | |
---|
| 1196 | g_free(message); |
---|
[f485008] | 1197 | } |
---|
| 1198 | |
---|
[ba7618d] | 1199 | /* Handles write_im and write_chat. Removes echoes of locally sent messages */ |
---|
| 1200 | static void prplcb_conv_msg(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime) |
---|
[d250b2a] | 1201 | { |
---|
[ba7618d] | 1202 | if (!(flags & PURPLE_MESSAGE_SEND)) { |
---|
| 1203 | handle_conv_msg(conv, who, message, 0, mtime); |
---|
[5ebff60] | 1204 | } |
---|
[ba7618d] | 1205 | } |
---|
[5ebff60] | 1206 | |
---|
[ba7618d] | 1207 | /* Handles write_conv. Only passes self messages from other locations through. |
---|
| 1208 | * That is, only writes of PURPLE_MESSAGE_SEND. |
---|
| 1209 | * There are more events which might be handled in the future, but some are tricky. |
---|
| 1210 | * (images look like <img id="123">, what do i do with that?) */ |
---|
| 1211 | static void prplcb_conv_write(PurpleConversation *conv, const char *who, const char *alias, const char *message, |
---|
| 1212 | PurpleMessageFlags flags, time_t mtime) |
---|
| 1213 | { |
---|
| 1214 | if (flags & PURPLE_MESSAGE_SEND) { |
---|
| 1215 | handle_conv_msg(conv, who, message, OPT_SELFMESSAGE, mtime); |
---|
[5ebff60] | 1216 | } |
---|
[d250b2a] | 1217 | } |
---|
| 1218 | |
---|
[bad41f56] | 1219 | /* No, this is not a ui_op but a signal. */ |
---|
[5ebff60] | 1220 | static void prplcb_buddy_typing(PurpleAccount *account, const char *who, gpointer null) |
---|
[bad41f56] | 1221 | { |
---|
| 1222 | PurpleConversation *conv; |
---|
| 1223 | PurpleConvIm *im; |
---|
| 1224 | int state; |
---|
[5ebff60] | 1225 | |
---|
| 1226 | if ((conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, account)) == NULL) { |
---|
[bad41f56] | 1227 | return; |
---|
[5ebff60] | 1228 | } |
---|
| 1229 | |
---|
[bad41f56] | 1230 | im = PURPLE_CONV_IM(conv); |
---|
[5ebff60] | 1231 | switch (purple_conv_im_get_typing_state(im)) { |
---|
[bad41f56] | 1232 | case PURPLE_TYPING: |
---|
| 1233 | state = OPT_TYPING; |
---|
| 1234 | break; |
---|
| 1235 | case PURPLE_TYPED: |
---|
| 1236 | state = OPT_THINKING; |
---|
| 1237 | break; |
---|
| 1238 | default: |
---|
| 1239 | state = 0; |
---|
| 1240 | } |
---|
[5ebff60] | 1241 | |
---|
| 1242 | imcb_buddy_typing(purple_ic_by_pa(account), who, state); |
---|
[bad41f56] | 1243 | } |
---|
| 1244 | |
---|
[5ebff60] | 1245 | static PurpleConversationUiOps bee_conv_uiops = |
---|
[860ba6a] | 1246 | { |
---|
[f485008] | 1247 | prplcb_conv_new, /* create_conversation */ |
---|
| 1248 | prplcb_conv_free, /* destroy_conversation */ |
---|
[ba7618d] | 1249 | prplcb_conv_msg, /* write_chat */ |
---|
| 1250 | prplcb_conv_msg, /* write_im */ |
---|
| 1251 | prplcb_conv_write, /* write_conv */ |
---|
[f485008] | 1252 | prplcb_conv_add_users, /* chat_add_users */ |
---|
[860ba6a] | 1253 | NULL, /* chat_rename_user */ |
---|
[f485008] | 1254 | prplcb_conv_del_users, /* chat_remove_users */ |
---|
[860ba6a] | 1255 | NULL, /* chat_update_user */ |
---|
| 1256 | NULL, /* present */ |
---|
| 1257 | NULL, /* has_focus */ |
---|
| 1258 | NULL, /* custom_smiley_add */ |
---|
| 1259 | NULL, /* custom_smiley_write */ |
---|
| 1260 | NULL, /* custom_smiley_close */ |
---|
| 1261 | NULL, /* send_confirm */ |
---|
| 1262 | }; |
---|
| 1263 | |
---|
[5ebff60] | 1264 | struct prplcb_request_action_data { |
---|
[0ac1a375] | 1265 | void *user_data, *bee_data; |
---|
| 1266 | PurpleRequestActionCb yes, no; |
---|
| 1267 | int yes_i, no_i; |
---|
| 1268 | }; |
---|
| 1269 | |
---|
[5ebff60] | 1270 | static void prplcb_request_action_yes(void *data) |
---|
[0ac1a375] | 1271 | { |
---|
| 1272 | struct prplcb_request_action_data *pqad = data; |
---|
[5ebff60] | 1273 | |
---|
| 1274 | if (pqad->yes) { |
---|
| 1275 | pqad->yes(pqad->user_data, pqad->yes_i); |
---|
| 1276 | } |
---|
[0ac1a375] | 1277 | } |
---|
| 1278 | |
---|
[5ebff60] | 1279 | static void prplcb_request_action_no(void *data) |
---|
[0ac1a375] | 1280 | { |
---|
| 1281 | struct prplcb_request_action_data *pqad = data; |
---|
[5ebff60] | 1282 | |
---|
| 1283 | if (pqad->no) { |
---|
| 1284 | pqad->no(pqad->user_data, pqad->no_i); |
---|
| 1285 | } |
---|
[2c5ab49] | 1286 | } |
---|
| 1287 | |
---|
| 1288 | /* q->free() callback from query_del()*/ |
---|
| 1289 | static void prplcb_request_action_free(void *data) |
---|
| 1290 | { |
---|
| 1291 | struct prplcb_request_action_data *pqad = data; |
---|
| 1292 | |
---|
| 1293 | pqad->bee_data = NULL; |
---|
| 1294 | purple_request_close(PURPLE_REQUEST_ACTION, pqad); |
---|
[0ac1a375] | 1295 | } |
---|
| 1296 | |
---|
[5ebff60] | 1297 | static void *prplcb_request_action(const char *title, const char *primary, const char *secondary, |
---|
| 1298 | int default_action, PurpleAccount *account, const char *who, |
---|
| 1299 | PurpleConversation *conv, void *user_data, size_t action_count, |
---|
| 1300 | va_list actions) |
---|
[0ac1a375] | 1301 | { |
---|
[5ebff60] | 1302 | struct prplcb_request_action_data *pqad; |
---|
[0ac1a375] | 1303 | int i; |
---|
| 1304 | char *q; |
---|
[5ebff60] | 1305 | |
---|
| 1306 | pqad = g_new0(struct prplcb_request_action_data, 1); |
---|
| 1307 | |
---|
| 1308 | for (i = 0; i < action_count; i++) { |
---|
[0ac1a375] | 1309 | char *caption; |
---|
| 1310 | void *fn; |
---|
[5ebff60] | 1311 | |
---|
| 1312 | caption = va_arg(actions, char*); |
---|
| 1313 | fn = va_arg(actions, void*); |
---|
| 1314 | |
---|
| 1315 | if (strstr(caption, "Accept") || strstr(caption, "OK")) { |
---|
[0ac1a375] | 1316 | pqad->yes = fn; |
---|
| 1317 | pqad->yes_i = i; |
---|
[5ebff60] | 1318 | } else if (strstr(caption, "Reject") || strstr(caption, "Cancel")) { |
---|
[0ac1a375] | 1319 | pqad->no = fn; |
---|
| 1320 | pqad->no_i = i; |
---|
| 1321 | } |
---|
| 1322 | } |
---|
[5ebff60] | 1323 | |
---|
[0ac1a375] | 1324 | pqad->user_data = user_data; |
---|
[5ebff60] | 1325 | |
---|
[4aa0f6b] | 1326 | /* TODO: IRC stuff here :-( */ |
---|
[5ebff60] | 1327 | q = g_strdup_printf("Request: %s\n\n%s\n\n%s", title, primary, secondary); |
---|
[56985aa] | 1328 | pqad->bee_data = query_add(local_bee->ui_data, purple_ic_by_pa(account), q, |
---|
[2c5ab49] | 1329 | prplcb_request_action_yes, prplcb_request_action_no, |
---|
| 1330 | prplcb_request_action_free, pqad); |
---|
[5ebff60] | 1331 | |
---|
| 1332 | g_free(q); |
---|
| 1333 | |
---|
[e5d8d21] | 1334 | return pqad; |
---|
[0ac1a375] | 1335 | } |
---|
| 1336 | |
---|
[3bb333c] | 1337 | /* So it turns out some requests have no account context at all, because |
---|
| 1338 | * libpurple hates us. This means that query_del_by_conn() won't remove those |
---|
| 1339 | * on logout, and will segfault if the user replies. That's why this exists. |
---|
| 1340 | */ |
---|
| 1341 | static void prplcb_close_request(PurpleRequestType type, void *data) |
---|
| 1342 | { |
---|
[2c5ab49] | 1343 | struct prplcb_request_action_data *pqad; |
---|
| 1344 | struct request_input_data *ri; |
---|
| 1345 | struct purple_data *pd; |
---|
| 1346 | |
---|
| 1347 | if (!data) { |
---|
| 1348 | return; |
---|
| 1349 | } |
---|
| 1350 | |
---|
| 1351 | switch (type) { |
---|
| 1352 | case PURPLE_REQUEST_ACTION: |
---|
| 1353 | pqad = data; |
---|
| 1354 | /* if this is null, it's because query_del was run already */ |
---|
| 1355 | if (pqad->bee_data) { |
---|
| 1356 | query_del(local_bee->ui_data, pqad->bee_data); |
---|
| 1357 | } |
---|
| 1358 | g_free(pqad); |
---|
| 1359 | break; |
---|
| 1360 | case PURPLE_REQUEST_INPUT: |
---|
| 1361 | ri = data; |
---|
| 1362 | pd = ri->ic->proto_data; |
---|
| 1363 | imcb_remove_buddy(ri->ic, ri->buddy, NULL); |
---|
| 1364 | g_free(ri->buddy); |
---|
| 1365 | g_hash_table_remove(pd->input_requests, GUINT_TO_POINTER(ri->id)); |
---|
| 1366 | break; |
---|
| 1367 | default: |
---|
| 1368 | g_free(data); |
---|
| 1369 | break; |
---|
[3bb333c] | 1370 | } |
---|
| 1371 | |
---|
[177ffd7] | 1372 | } |
---|
| 1373 | |
---|
[6a48992] | 1374 | void* prplcb_request_input(const char *title, const char *primary, |
---|
| 1375 | const char *secondary, const char *default_value, gboolean multiline, |
---|
| 1376 | gboolean masked, gchar *hint, const char *ok_text, GCallback ok_cb, |
---|
| 1377 | const char *cancel_text, GCallback cancel_cb, PurpleAccount *account, |
---|
| 1378 | const char *who, PurpleConversation *conv, void *user_data) |
---|
| 1379 | { |
---|
| 1380 | struct im_connection *ic = purple_ic_by_pa(account); |
---|
| 1381 | struct purple_data *pd = ic->proto_data; |
---|
[fecdd71] | 1382 | struct request_input_data *ri; |
---|
| 1383 | guint id; |
---|
| 1384 | |
---|
| 1385 | /* hack so that jabber's chat list doesn't ask for conference server twice */ |
---|
| 1386 | if (pd->chat_list_server && title && g_strcmp0(title, "Enter a Conference Server") == 0) { |
---|
| 1387 | ((ri_callback_t) ok_cb)(user_data, pd->chat_list_server); |
---|
| 1388 | g_free(pd->chat_list_server); |
---|
| 1389 | pd->chat_list_server = NULL; |
---|
| 1390 | return NULL; |
---|
| 1391 | } |
---|
| 1392 | |
---|
| 1393 | id = pd->next_request_id++; |
---|
| 1394 | ri = g_new0(struct request_input_data, 1); |
---|
[6a48992] | 1395 | |
---|
[2c5ab49] | 1396 | ri->id = id; |
---|
| 1397 | ri->ic = ic; |
---|
| 1398 | ri->buddy = g_strdup_printf("%s_%u", PURPLE_REQUEST_HANDLE, id); |
---|
[6a48992] | 1399 | ri->data_callback = (ri_callback_t) ok_cb; |
---|
| 1400 | ri->user_data = user_data; |
---|
| 1401 | g_hash_table_insert(pd->input_requests, GUINT_TO_POINTER(id), ri); |
---|
| 1402 | |
---|
[2c5ab49] | 1403 | imcb_add_buddy(ic, ri->buddy, NULL); |
---|
[1239d05] | 1404 | |
---|
| 1405 | if (title && *title) { |
---|
| 1406 | imcb_buddy_msg(ic, ri->buddy, title, 0, 0); |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | if (primary && *primary) { |
---|
| 1410 | imcb_buddy_msg(ic, ri->buddy, primary, 0, 0); |
---|
| 1411 | } |
---|
| 1412 | |
---|
| 1413 | if (secondary && *secondary) { |
---|
| 1414 | imcb_buddy_msg(ic, ri->buddy, secondary, 0, 0); |
---|
| 1415 | } |
---|
[6a48992] | 1416 | |
---|
[2c5ab49] | 1417 | return ri; |
---|
[6a48992] | 1418 | } |
---|
| 1419 | |
---|
| 1420 | void purple_request_input_callback(guint id, struct im_connection *ic, |
---|
| 1421 | const char *message, const char *who) |
---|
| 1422 | { |
---|
| 1423 | struct purple_data *pd = ic->proto_data; |
---|
[2c5ab49] | 1424 | struct request_input_data *ri; |
---|
[6a48992] | 1425 | |
---|
[2c5ab49] | 1426 | if (!(ri = g_hash_table_lookup(pd->input_requests, GUINT_TO_POINTER(id)))) { |
---|
| 1427 | return; |
---|
[6a48992] | 1428 | } |
---|
| 1429 | |
---|
[2c5ab49] | 1430 | ri->data_callback(ri->user_data, message); |
---|
| 1431 | |
---|
| 1432 | purple_request_close(PURPLE_REQUEST_INPUT, ri); |
---|
[6a48992] | 1433 | } |
---|
| 1434 | |
---|
| 1435 | |
---|
[0ac1a375] | 1436 | static PurpleRequestUiOps bee_request_uiops = |
---|
| 1437 | { |
---|
[98d46d5] | 1438 | prplcb_request_input, /* request_input */ |
---|
| 1439 | NULL, /* request_choice */ |
---|
| 1440 | prplcb_request_action, /* request_action */ |
---|
| 1441 | NULL, /* request_fields */ |
---|
| 1442 | NULL, /* request_file */ |
---|
| 1443 | prplcb_close_request, /* close_request */ |
---|
| 1444 | NULL, /* request_folder */ |
---|
[0ac1a375] | 1445 | }; |
---|
| 1446 | |
---|
[5ebff60] | 1447 | static void prplcb_privacy_permit_added(PurpleAccount *account, const char *name) |
---|
[05a8932] | 1448 | { |
---|
[5ebff60] | 1449 | struct im_connection *ic = purple_ic_by_pa(account); |
---|
| 1450 | |
---|
| 1451 | if (!g_slist_find_custom(ic->permit, name, (GCompareFunc) ic->acc->prpl->handle_cmp)) { |
---|
| 1452 | ic->permit = g_slist_prepend(ic->permit, g_strdup(name)); |
---|
| 1453 | } |
---|
[05a8932] | 1454 | } |
---|
| 1455 | |
---|
[5ebff60] | 1456 | static void prplcb_privacy_permit_removed(PurpleAccount *account, const char *name) |
---|
[05a8932] | 1457 | { |
---|
[5ebff60] | 1458 | struct im_connection *ic = purple_ic_by_pa(account); |
---|
[05a8932] | 1459 | void *n; |
---|
[5ebff60] | 1460 | |
---|
| 1461 | n = g_slist_find_custom(ic->permit, name, (GCompareFunc) ic->acc->prpl->handle_cmp); |
---|
| 1462 | ic->permit = g_slist_remove(ic->permit, n); |
---|
[05a8932] | 1463 | } |
---|
| 1464 | |
---|
[5ebff60] | 1465 | static void prplcb_privacy_deny_added(PurpleAccount *account, const char *name) |
---|
[05a8932] | 1466 | { |
---|
[5ebff60] | 1467 | struct im_connection *ic = purple_ic_by_pa(account); |
---|
| 1468 | |
---|
| 1469 | if (!g_slist_find_custom(ic->deny, name, (GCompareFunc) ic->acc->prpl->handle_cmp)) { |
---|
| 1470 | ic->deny = g_slist_prepend(ic->deny, g_strdup(name)); |
---|
| 1471 | } |
---|
[05a8932] | 1472 | } |
---|
| 1473 | |
---|
[5ebff60] | 1474 | static void prplcb_privacy_deny_removed(PurpleAccount *account, const char *name) |
---|
[05a8932] | 1475 | { |
---|
[5ebff60] | 1476 | struct im_connection *ic = purple_ic_by_pa(account); |
---|
[05a8932] | 1477 | void *n; |
---|
[5ebff60] | 1478 | |
---|
| 1479 | n = g_slist_find_custom(ic->deny, name, (GCompareFunc) ic->acc->prpl->handle_cmp); |
---|
| 1480 | ic->deny = g_slist_remove(ic->deny, n); |
---|
[05a8932] | 1481 | } |
---|
| 1482 | |
---|
| 1483 | static PurplePrivacyUiOps bee_privacy_uiops = |
---|
| 1484 | { |
---|
[98d46d5] | 1485 | prplcb_privacy_permit_added, /* permit_added */ |
---|
| 1486 | prplcb_privacy_permit_removed, /* permit_removed */ |
---|
| 1487 | prplcb_privacy_deny_added, /* deny_added */ |
---|
| 1488 | prplcb_privacy_deny_removed, /* deny_removed */ |
---|
[05a8932] | 1489 | }; |
---|
| 1490 | |
---|
[725f942] | 1491 | static void prplcb_roomlist_create(PurpleRoomlist *list) |
---|
| 1492 | { |
---|
| 1493 | struct purple_roomlist_data *rld; |
---|
| 1494 | |
---|
| 1495 | list->ui_data = rld = g_new0(struct purple_roomlist_data, 1); |
---|
| 1496 | rld->topic = -1; |
---|
| 1497 | } |
---|
| 1498 | |
---|
| 1499 | static void prplcb_roomlist_set_fields(PurpleRoomlist *list, GList *fields) |
---|
| 1500 | { |
---|
| 1501 | gint topic = -1; |
---|
| 1502 | GList *l; |
---|
| 1503 | guint i; |
---|
| 1504 | PurpleRoomlistField *field; |
---|
| 1505 | struct purple_roomlist_data *rld = list->ui_data; |
---|
| 1506 | |
---|
| 1507 | for (i = 0, l = fields; l; i++, l = l->next) { |
---|
| 1508 | field = l->data; |
---|
| 1509 | |
---|
| 1510 | /* Use the first visible string field as a fallback topic */ |
---|
| 1511 | if (i != 0 && topic < 0 && !field->hidden && |
---|
| 1512 | field->type == PURPLE_ROOMLIST_FIELD_STRING) { |
---|
| 1513 | topic = i; |
---|
| 1514 | } |
---|
| 1515 | |
---|
| 1516 | if ((g_strcasecmp(field->name, "description") == 0) || |
---|
| 1517 | (g_strcasecmp(field->name, "topic") == 0)) { |
---|
| 1518 | if (field->type == PURPLE_ROOMLIST_FIELD_STRING) { |
---|
| 1519 | rld->topic = i; |
---|
| 1520 | } |
---|
| 1521 | } |
---|
| 1522 | } |
---|
| 1523 | |
---|
| 1524 | if (rld->topic < 0) { |
---|
| 1525 | rld->topic = topic; |
---|
| 1526 | } |
---|
| 1527 | } |
---|
| 1528 | |
---|
[87872c7] | 1529 | static char *prplcb_roomlist_get_room_name(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
---|
| 1530 | { |
---|
| 1531 | struct im_connection *ic = purple_ic_by_pa(list->account); |
---|
| 1532 | struct purple_data *pd = ic->proto_data; |
---|
| 1533 | PurplePlugin *prpl = purple_plugins_find_with_id(pd->account->protocol_id); |
---|
| 1534 | PurplePluginProtocolInfo *pi = prpl->info->extra_info; |
---|
| 1535 | |
---|
| 1536 | if (pi && pi->roomlist_room_serialize) { |
---|
| 1537 | return pi->roomlist_room_serialize(room); |
---|
| 1538 | } else { |
---|
| 1539 | return g_strdup(purple_roomlist_room_get_name(room)); |
---|
| 1540 | } |
---|
| 1541 | } |
---|
| 1542 | |
---|
[725f942] | 1543 | static void prplcb_roomlist_add_room(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
---|
| 1544 | { |
---|
| 1545 | bee_chat_info_t *ci; |
---|
[87872c7] | 1546 | char *title; |
---|
[725f942] | 1547 | const char *topic; |
---|
| 1548 | GList *fields; |
---|
| 1549 | struct purple_roomlist_data *rld = list->ui_data; |
---|
| 1550 | |
---|
| 1551 | fields = purple_roomlist_room_get_fields(room); |
---|
[87872c7] | 1552 | title = prplcb_roomlist_get_room_name(list, room); |
---|
[725f942] | 1553 | |
---|
| 1554 | if (rld->topic >= 0) { |
---|
| 1555 | topic = g_list_nth_data(fields, rld->topic); |
---|
| 1556 | } else { |
---|
| 1557 | topic = NULL; |
---|
| 1558 | } |
---|
| 1559 | |
---|
| 1560 | ci = g_new(bee_chat_info_t, 1); |
---|
[87872c7] | 1561 | ci->title = title; |
---|
[725f942] | 1562 | ci->topic = g_strdup(topic); |
---|
| 1563 | rld->chats = g_slist_prepend(rld->chats, ci); |
---|
| 1564 | } |
---|
| 1565 | |
---|
| 1566 | static void prplcb_roomlist_in_progress(PurpleRoomlist *list, gboolean in_progress) |
---|
| 1567 | { |
---|
| 1568 | struct im_connection *ic; |
---|
[fecdd71] | 1569 | struct purple_data *pd; |
---|
[725f942] | 1570 | struct purple_roomlist_data *rld = list->ui_data; |
---|
| 1571 | |
---|
[01d56c0] | 1572 | if (in_progress || !rld) { |
---|
[725f942] | 1573 | return; |
---|
| 1574 | } |
---|
| 1575 | |
---|
| 1576 | ic = purple_ic_by_pa(list->account); |
---|
[6e991a9] | 1577 | imcb_chat_list_free(ic); |
---|
[725f942] | 1578 | |
---|
[fecdd71] | 1579 | pd = ic->proto_data; |
---|
| 1580 | g_free(pd->chat_list_server); |
---|
| 1581 | pd->chat_list_server = NULL; |
---|
| 1582 | |
---|
[725f942] | 1583 | ic->chatlist = g_slist_reverse(rld->chats); |
---|
| 1584 | rld->chats = NULL; |
---|
| 1585 | |
---|
[a08b2db] | 1586 | imcb_chat_list_finish(ic); |
---|
[01d56c0] | 1587 | |
---|
| 1588 | if (rld->initialized) { |
---|
| 1589 | purple_roomlist_unref(list); |
---|
| 1590 | } |
---|
[725f942] | 1591 | } |
---|
| 1592 | |
---|
| 1593 | static void prplcb_roomlist_destroy(PurpleRoomlist *list) |
---|
| 1594 | { |
---|
| 1595 | g_free(list->ui_data); |
---|
| 1596 | list->ui_data = NULL; |
---|
| 1597 | } |
---|
| 1598 | |
---|
| 1599 | static PurpleRoomlistUiOps bee_roomlist_uiops = |
---|
| 1600 | { |
---|
| 1601 | NULL, /* show_with_account */ |
---|
| 1602 | prplcb_roomlist_create, /* create */ |
---|
| 1603 | prplcb_roomlist_set_fields, /* set_fields */ |
---|
| 1604 | prplcb_roomlist_add_room, /* add_room */ |
---|
| 1605 | prplcb_roomlist_in_progress, /* in_progress */ |
---|
| 1606 | prplcb_roomlist_destroy, /* destroy */ |
---|
| 1607 | }; |
---|
| 1608 | |
---|
[5ebff60] | 1609 | static void prplcb_debug_print(PurpleDebugLevel level, const char *category, const char *arg_s) |
---|
[0cbef26] | 1610 | { |
---|
[5ebff60] | 1611 | fprintf(stderr, "DEBUG %s: %s", category, arg_s); |
---|
[0cbef26] | 1612 | } |
---|
| 1613 | |
---|
| 1614 | static PurpleDebugUiOps bee_debug_uiops = |
---|
| 1615 | { |
---|
[98d46d5] | 1616 | prplcb_debug_print, /* print */ |
---|
[0cbef26] | 1617 | }; |
---|
| 1618 | |
---|
[5ebff60] | 1619 | static guint prplcb_ev_timeout_add(guint interval, GSourceFunc func, gpointer udata) |
---|
[4164e62] | 1620 | { |
---|
[5ebff60] | 1621 | return b_timeout_add(interval, (b_event_handler) func, udata); |
---|
[4164e62] | 1622 | } |
---|
| 1623 | |
---|
[5ebff60] | 1624 | static guint prplcb_ev_input_add(int fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer udata) |
---|
[4164e62] | 1625 | { |
---|
[5ebff60] | 1626 | return b_input_add(fd, cond | B_EV_FLAG_FORCE_REPEAT, (b_event_handler) func, udata); |
---|
[4164e62] | 1627 | } |
---|
| 1628 | |
---|
[5ebff60] | 1629 | static gboolean prplcb_ev_remove(guint id) |
---|
[4164e62] | 1630 | { |
---|
[5ebff60] | 1631 | b_event_remove((gint) id); |
---|
[4164e62] | 1632 | return TRUE; |
---|
| 1633 | } |
---|
| 1634 | |
---|
[5ebff60] | 1635 | static PurpleEventLoopUiOps glib_eventloops = |
---|
[4164e62] | 1636 | { |
---|
[98d46d5] | 1637 | prplcb_ev_timeout_add, /* timeout_add */ |
---|
| 1638 | prplcb_ev_remove, /* timeout_remove */ |
---|
| 1639 | prplcb_ev_input_add, /* input_add */ |
---|
| 1640 | prplcb_ev_remove, /* input_remove */ |
---|
[4164e62] | 1641 | }; |
---|
| 1642 | |
---|
[05aba55] | 1643 | /* Absolutely no connection context at all. Thanks purple! brb crying */ |
---|
| 1644 | static void *prplcb_notify_message(PurpleNotifyMsgType type, const char *title, |
---|
| 1645 | const char *primary, const char *secondary) |
---|
| 1646 | { |
---|
| 1647 | char *text = g_strdup_printf("%s%s - %s%s%s", |
---|
| 1648 | (type == PURPLE_NOTIFY_MSG_ERROR) ? "Error: " : "", |
---|
| 1649 | title, |
---|
| 1650 | primary ?: "", |
---|
| 1651 | (primary && secondary) ? " - " : "", |
---|
| 1652 | secondary ?: "" |
---|
| 1653 | ); |
---|
| 1654 | |
---|
| 1655 | if (local_bee->ui->log) { |
---|
| 1656 | local_bee->ui->log(local_bee, "purple", text); |
---|
| 1657 | } |
---|
| 1658 | |
---|
| 1659 | g_free(text); |
---|
| 1660 | |
---|
| 1661 | return NULL; |
---|
| 1662 | } |
---|
| 1663 | |
---|
[5ebff60] | 1664 | static void *prplcb_notify_email(PurpleConnection *gc, const char *subject, const char *from, |
---|
| 1665 | const char *to, const char *url) |
---|
[bab1c86] | 1666 | { |
---|
[5ebff60] | 1667 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 1668 | |
---|
[0864a52] | 1669 | imcb_notify_email(ic, "Received e-mail from %s for %s: %s <%s>", from, to, subject, url); |
---|
[5ebff60] | 1670 | |
---|
[bab1c86] | 1671 | return NULL; |
---|
| 1672 | } |
---|
| 1673 | |
---|
[5ebff60] | 1674 | static void *prplcb_notify_userinfo(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info) |
---|
[e77c264] | 1675 | { |
---|
[5ebff60] | 1676 | struct im_connection *ic = purple_ic_by_gc(gc); |
---|
| 1677 | GString *info = g_string_new(""); |
---|
| 1678 | GList *l = purple_notify_user_info_get_entries(user_info); |
---|
[e77c264] | 1679 | char *key; |
---|
| 1680 | const char *value; |
---|
| 1681 | int n; |
---|
[5ebff60] | 1682 | |
---|
| 1683 | while (l) { |
---|
[e77c264] | 1684 | PurpleNotifyUserInfoEntry *e = l->data; |
---|
[5ebff60] | 1685 | |
---|
| 1686 | switch (purple_notify_user_info_entry_get_type(e)) { |
---|
[e77c264] | 1687 | case PURPLE_NOTIFY_USER_INFO_ENTRY_PAIR: |
---|
| 1688 | case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER: |
---|
[5ebff60] | 1689 | key = g_strdup(purple_notify_user_info_entry_get_label(e)); |
---|
| 1690 | value = purple_notify_user_info_entry_get_value(e); |
---|
| 1691 | |
---|
| 1692 | if (key) { |
---|
| 1693 | strip_html(key); |
---|
| 1694 | g_string_append_printf(info, "%s: ", key); |
---|
| 1695 | |
---|
| 1696 | if (value) { |
---|
| 1697 | n = strlen(value) - 1; |
---|
| 1698 | while (g_ascii_isspace(value[n])) { |
---|
| 1699 | n--; |
---|
| 1700 | } |
---|
| 1701 | g_string_append_len(info, value, n + 1); |
---|
[e77c264] | 1702 | } |
---|
[5ebff60] | 1703 | g_string_append_c(info, '\n'); |
---|
| 1704 | g_free(key); |
---|
[e77c264] | 1705 | } |
---|
[5ebff60] | 1706 | |
---|
[e77c264] | 1707 | break; |
---|
| 1708 | case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK: |
---|
[5ebff60] | 1709 | g_string_append(info, "------------------------\n"); |
---|
[e77c264] | 1710 | break; |
---|
| 1711 | } |
---|
[5ebff60] | 1712 | |
---|
[e77c264] | 1713 | l = l->next; |
---|
| 1714 | } |
---|
[5ebff60] | 1715 | |
---|
| 1716 | imcb_log(ic, "User %s info:\n%s", who, info->str); |
---|
| 1717 | g_string_free(info, TRUE); |
---|
| 1718 | |
---|
[e77c264] | 1719 | return NULL; |
---|
| 1720 | } |
---|
| 1721 | |
---|
[437bd9b] | 1722 | static PurpleNotifyUiOps bee_notify_uiops = |
---|
[bab1c86] | 1723 | { |
---|
[98d46d5] | 1724 | prplcb_notify_message, /* notify_message */ |
---|
| 1725 | prplcb_notify_email, /* notify_email */ |
---|
| 1726 | NULL, /* notify_emails */ |
---|
| 1727 | NULL, /* notify_formatted */ |
---|
| 1728 | NULL, /* notify_searchresults */ |
---|
| 1729 | NULL, /* notify_searchresults_new_rows */ |
---|
| 1730 | prplcb_notify_userinfo, /* notify_userinfo */ |
---|
[bab1c86] | 1731 | }; |
---|
| 1732 | |
---|
[5ebff60] | 1733 | static void *prplcb_account_request_authorize(PurpleAccount *account, const char *remote_user, |
---|
| 1734 | const char *id, const char *alias, const char *message, gboolean on_list, |
---|
| 1735 | PurpleAccountRequestAuthorizationCb authorize_cb, |
---|
| 1736 | PurpleAccountRequestAuthorizationCb deny_cb, void *user_data) |
---|
[d0527c1] | 1737 | { |
---|
[5ebff60] | 1738 | struct im_connection *ic = purple_ic_by_pa(account); |
---|
[d0527c1] | 1739 | char *q; |
---|
[5ebff60] | 1740 | |
---|
| 1741 | if (alias) { |
---|
| 1742 | q = g_strdup_printf("%s (%s) wants to add you to his/her contact " |
---|
| 1743 | "list. (%s)", alias, remote_user, message); |
---|
| 1744 | } else { |
---|
| 1745 | q = g_strdup_printf("%s wants to add you to his/her contact " |
---|
| 1746 | "list. (%s)", remote_user, message); |
---|
| 1747 | } |
---|
| 1748 | |
---|
| 1749 | imcb_ask_with_free(ic, q, user_data, authorize_cb, deny_cb, NULL); |
---|
| 1750 | g_free(q); |
---|
| 1751 | |
---|
[3e59c8d] | 1752 | return NULL; |
---|
[d0527c1] | 1753 | } |
---|
| 1754 | |
---|
| 1755 | static PurpleAccountUiOps bee_account_uiops = |
---|
| 1756 | { |
---|
[98d46d5] | 1757 | NULL, /* notify_added */ |
---|
| 1758 | NULL, /* status_changed */ |
---|
| 1759 | NULL, /* request_add */ |
---|
| 1760 | prplcb_account_request_authorize, /* request_authorize */ |
---|
| 1761 | NULL, /* close_account_request */ |
---|
[d0527c1] | 1762 | }; |
---|
| 1763 | |
---|
[2309152] | 1764 | extern PurpleXferUiOps bee_xfer_uiops; |
---|
[edfc6db] | 1765 | |
---|
[860ba6a] | 1766 | static void purple_ui_init() |
---|
| 1767 | { |
---|
[5ebff60] | 1768 | purple_connections_set_ui_ops(&bee_conn_uiops); |
---|
| 1769 | purple_blist_set_ui_ops(&bee_blist_uiops); |
---|
| 1770 | purple_conversations_set_ui_ops(&bee_conv_uiops); |
---|
| 1771 | purple_request_set_ui_ops(&bee_request_uiops); |
---|
| 1772 | purple_privacy_set_ui_ops(&bee_privacy_uiops); |
---|
[725f942] | 1773 | purple_roomlist_set_ui_ops(&bee_roomlist_uiops); |
---|
[5ebff60] | 1774 | purple_notify_set_ui_ops(&bee_notify_uiops); |
---|
| 1775 | purple_accounts_set_ui_ops(&bee_account_uiops); |
---|
| 1776 | purple_xfers_set_ui_ops(&bee_xfer_uiops); |
---|
| 1777 | |
---|
| 1778 | if (getenv("BITLBEE_DEBUG")) { |
---|
| 1779 | purple_debug_set_ui_ops(&bee_debug_uiops); |
---|
| 1780 | } |
---|
[860ba6a] | 1781 | } |
---|
| 1782 | |
---|
[6d212f4] | 1783 | /* borrowing this semi-private function |
---|
| 1784 | * TODO: figure out a better interface later (famous last words) */ |
---|
| 1785 | gboolean plugin_info_add(struct plugin_info *info); |
---|
| 1786 | |
---|
[796da03] | 1787 | void purple_initmodule() |
---|
| 1788 | { |
---|
[cd741d8] | 1789 | struct prpl funcs; |
---|
[796da03] | 1790 | GList *prots; |
---|
[e5d8d21] | 1791 | GString *help; |
---|
[3c9b095] | 1792 | char *dir; |
---|
[5ebff60] | 1793 | |
---|
[57f81ec] | 1794 | if (purple_get_core() != NULL) { |
---|
| 1795 | log_message(LOGLVL_ERROR, "libpurple already initialized. " |
---|
| 1796 | "Please use inetd or ForkDaemon mode instead."); |
---|
| 1797 | return; |
---|
| 1798 | } |
---|
| 1799 | |
---|
[d57484d] | 1800 | g_return_if_fail((int) B_EV_IO_READ == (int) PURPLE_INPUT_READ); |
---|
| 1801 | g_return_if_fail((int) B_EV_IO_WRITE == (int) PURPLE_INPUT_WRITE); |
---|
[5ebff60] | 1802 | |
---|
| 1803 | dir = g_strdup_printf("%s/purple", global.conf->configdir); |
---|
| 1804 | purple_util_set_user_dir(dir); |
---|
| 1805 | g_free(dir); |
---|
| 1806 | |
---|
[5dbf66e] | 1807 | dir = g_strdup_printf("%s/purple", global.conf->plugindir); |
---|
| 1808 | purple_plugins_add_search_path(dir); |
---|
| 1809 | g_free(dir); |
---|
| 1810 | |
---|
[5ebff60] | 1811 | purple_debug_set_enabled(FALSE); |
---|
| 1812 | purple_core_set_ui_ops(&bee_core_uiops); |
---|
| 1813 | purple_eventloop_set_ui_ops(&glib_eventloops); |
---|
| 1814 | if (!purple_core_init("BitlBee")) { |
---|
[796da03] | 1815 | /* Initializing the core failed. Terminate. */ |
---|
[5ebff60] | 1816 | fprintf(stderr, "libpurple initialization failed.\n"); |
---|
[796da03] | 1817 | abort(); |
---|
| 1818 | } |
---|
[5ebff60] | 1819 | |
---|
| 1820 | if (proxytype != PROXY_NONE) { |
---|
[ff94563] | 1821 | PurpleProxyInfo *pi = purple_global_proxy_get_info(); |
---|
[5ebff60] | 1822 | switch (proxytype) { |
---|
[12f041d] | 1823 | case PROXY_SOCKS4A: |
---|
[7add7ec] | 1824 | case PROXY_SOCKS4: |
---|
[5ebff60] | 1825 | purple_proxy_info_set_type(pi, PURPLE_PROXY_SOCKS4); |
---|
[7add7ec] | 1826 | break; |
---|
| 1827 | case PROXY_SOCKS5: |
---|
[5ebff60] | 1828 | purple_proxy_info_set_type(pi, PURPLE_PROXY_SOCKS5); |
---|
[7add7ec] | 1829 | break; |
---|
| 1830 | case PROXY_HTTP: |
---|
[5ebff60] | 1831 | purple_proxy_info_set_type(pi, PURPLE_PROXY_HTTP); |
---|
[7add7ec] | 1832 | break; |
---|
[5ebff60] | 1833 | } |
---|
| 1834 | purple_proxy_info_set_host(pi, proxyhost); |
---|
| 1835 | purple_proxy_info_set_port(pi, proxyport); |
---|
| 1836 | purple_proxy_info_set_username(pi, proxyuser); |
---|
| 1837 | purple_proxy_info_set_password(pi, proxypass); |
---|
[7add7ec] | 1838 | } |
---|
[5ebff60] | 1839 | |
---|
| 1840 | purple_set_blist(purple_blist_new()); |
---|
| 1841 | |
---|
[bad41f56] | 1842 | /* No, really. So far there were ui_ops for everything, but now suddenly |
---|
| 1843 | one needs to use signals for typing notification stuff. :-( */ |
---|
[5ebff60] | 1844 | purple_signal_connect(purple_conversations_get_handle(), "buddy-typing", |
---|
| 1845 | &funcs, PURPLE_CALLBACK(prplcb_buddy_typing), NULL); |
---|
| 1846 | purple_signal_connect(purple_conversations_get_handle(), "buddy-typed", |
---|
| 1847 | &funcs, PURPLE_CALLBACK(prplcb_buddy_typing), NULL); |
---|
| 1848 | purple_signal_connect(purple_conversations_get_handle(), "buddy-typing-stopped", |
---|
| 1849 | &funcs, PURPLE_CALLBACK(prplcb_buddy_typing), NULL); |
---|
| 1850 | |
---|
| 1851 | memset(&funcs, 0, sizeof(funcs)); |
---|
[cd741d8] | 1852 | funcs.login = purple_login; |
---|
| 1853 | funcs.init = purple_init; |
---|
| 1854 | funcs.logout = purple_logout; |
---|
| 1855 | funcs.buddy_msg = purple_buddy_msg; |
---|
| 1856 | funcs.away_states = purple_away_states; |
---|
| 1857 | funcs.set_away = purple_set_away; |
---|
| 1858 | funcs.add_buddy = purple_add_buddy; |
---|
| 1859 | funcs.remove_buddy = purple_remove_buddy; |
---|
[05a8932] | 1860 | funcs.add_permit = purple_add_permit; |
---|
| 1861 | funcs.add_deny = purple_add_deny; |
---|
| 1862 | funcs.rem_permit = purple_rem_permit; |
---|
| 1863 | funcs.rem_deny = purple_rem_deny; |
---|
[e77c264] | 1864 | funcs.get_info = purple_get_info; |
---|
[cd741d8] | 1865 | funcs.keepalive = purple_keepalive; |
---|
| 1866 | funcs.send_typing = purple_send_typing; |
---|
| 1867 | funcs.handle_cmp = g_strcasecmp; |
---|
[f485008] | 1868 | /* TODO(wilmer): Set these only for protocols that support them? */ |
---|
| 1869 | funcs.chat_msg = purple_chat_msg; |
---|
[8ad5c34] | 1870 | funcs.chat_with = purple_chat_with; |
---|
| 1871 | funcs.chat_invite = purple_chat_invite; |
---|
[524e931] | 1872 | funcs.chat_topic = purple_chat_set_topic; |
---|
[e41cc40] | 1873 | funcs.chat_kick = purple_chat_kick; |
---|
[15794dc] | 1874 | funcs.chat_leave = purple_chat_leave; |
---|
[c3caa46] | 1875 | funcs.chat_join = purple_chat_join; |
---|
[725f942] | 1876 | funcs.chat_list = purple_chat_list; |
---|
[1882b70] | 1877 | funcs.chat_add_settings = purple_chat_add_settings; |
---|
| 1878 | funcs.chat_free_settings = purple_chat_free_settings; |
---|
[edfc6db] | 1879 | funcs.transfer_request = purple_transfer_request; |
---|
[5ebff60] | 1880 | |
---|
| 1881 | help = g_string_new("BitlBee libpurple module supports the following IM protocols:\n"); |
---|
| 1882 | |
---|
[bab1c86] | 1883 | /* Add a protocol entry to BitlBee's structures for every protocol |
---|
[5ebff60] | 1884 | supported by this libpurple instance. */ |
---|
| 1885 | for (prots = purple_plugins_get_protocols(); prots; prots = prots->next) { |
---|
[796da03] | 1886 | PurplePlugin *prot = prots->data; |
---|
[9f03c47] | 1887 | PurplePluginProtocolInfo *pi = prot->info->extra_info; |
---|
[cd741d8] | 1888 | struct prpl *ret; |
---|
[6d212f4] | 1889 | struct plugin_info *info; |
---|
[5ebff60] | 1890 | |
---|
[c775a58] | 1891 | /* If we already have this one (as a native module), don't |
---|
| 1892 | add a libpurple duplicate. */ |
---|
[5ebff60] | 1893 | if (find_protocol(prot->info->id)) { |
---|
[c775a58] | 1894 | continue; |
---|
[5ebff60] | 1895 | } |
---|
| 1896 | |
---|
| 1897 | ret = g_memdup(&funcs, sizeof(funcs)); |
---|
[cd741d8] | 1898 | ret->name = ret->data = prot->info->id; |
---|
[5ebff60] | 1899 | if (strncmp(ret->name, "prpl-", 5) == 0) { |
---|
[cd741d8] | 1900 | ret->name += 5; |
---|
[5ebff60] | 1901 | } |
---|
[9f03c47] | 1902 | |
---|
| 1903 | if (pi->options & OPT_PROTO_NO_PASSWORD) { |
---|
| 1904 | ret->options |= PRPL_OPT_NO_PASSWORD; |
---|
| 1905 | } |
---|
| 1906 | |
---|
| 1907 | if (pi->options & OPT_PROTO_PASSWORD_OPTIONAL) { |
---|
| 1908 | ret->options |= PRPL_OPT_PASSWORD_OPTIONAL; |
---|
| 1909 | } |
---|
| 1910 | |
---|
[5ebff60] | 1911 | register_protocol(ret); |
---|
| 1912 | |
---|
| 1913 | g_string_append_printf(help, "\n* %s (%s)", ret->name, prot->info->name); |
---|
| 1914 | |
---|
[bab1c86] | 1915 | /* libpurple doesn't define a protocol called OSCAR, but we |
---|
| 1916 | need it to be compatible with normal BitlBee. */ |
---|
[5ebff60] | 1917 | if (g_strcasecmp(prot->info->id, "prpl-aim") == 0) { |
---|
| 1918 | ret = g_memdup(&funcs, sizeof(funcs)); |
---|
[cd741d8] | 1919 | ret->name = "oscar"; |
---|
[50988d1] | 1920 | /* purple_get_account_prpl_id() determines the actual protocol ID (icq/aim) */ |
---|
| 1921 | ret->data = NULL; |
---|
[5ebff60] | 1922 | register_protocol(ret); |
---|
[cd741d8] | 1923 | } |
---|
[6d212f4] | 1924 | |
---|
| 1925 | info = g_new0(struct plugin_info, 1); |
---|
| 1926 | info->abiver = BITLBEE_ABI_VERSION_CODE; |
---|
| 1927 | info->name = ret->name; |
---|
| 1928 | info->version = prot->info->version; |
---|
| 1929 | info->description = prot->info->description; |
---|
| 1930 | info->author = prot->info->author; |
---|
| 1931 | info->url = prot->info->homepage; |
---|
| 1932 | |
---|
| 1933 | plugin_info_add(info); |
---|
[796da03] | 1934 | } |
---|
[5ebff60] | 1935 | |
---|
| 1936 | g_string_append(help, "\n\nFor used protocols, more information about available " |
---|
| 1937 | "settings can be found using \x02help purple <protocol name>\x02 " |
---|
| 1938 | "(create an account using that protocol first!)"); |
---|
| 1939 | |
---|
[bab1c86] | 1940 | /* Add a simple dynamically-generated help item listing all |
---|
| 1941 | the supported protocols. */ |
---|
[5ebff60] | 1942 | help_add_mem(&global.help, "purple", help->str); |
---|
| 1943 | g_string_free(help, TRUE); |
---|
[796da03] | 1944 | } |
---|