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