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