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