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