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