source: protocols/nogaim.c @ b4f496e

Last change on this file since b4f496e was b4f496e, checked in by dequis <dx@…>, at 2016-11-19T07:32:48Z

Improve handling of unknown protocols / missing plugins

Instead of failing to load the config, a fake prpl is created to load
the account, keep its settings, and refuse to log in with a helpful
error message.

Also added a new explain_unknown_protocol() function which returns text
which attempts to explain why a protocol is missing, handling several
typical cases, including the future removal of several dead libpurple
plugins.

That message is shown when logging in to a loaded account with a missing
protocol and when adding a new one with 'account add', with the
difference that the latter doesn't leave a placeholder fake account.

  • Property mode set to 100644
File size: 21.2 KB
Line 
1/********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2012 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/*
8 * nogaim
9 *
10 * Gaim without gaim - for BitlBee
11 *
12 * This file contains functions called by the Gaim IM-modules. It's written
13 * from scratch for BitlBee and doesn't contain any code from Gaim anymore
14 * (except for the function names).
15 */
16
17/*
18  This program is free software; you can redistribute it and/or modify
19  it under the terms of the GNU General Public License as published by
20  the Free Software Foundation; either version 2 of the License, or
21  (at your option) any later version.
22
23  This program is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  GNU General Public License for more details.
27
28  You should have received a copy of the GNU General Public License with
29  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
30  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
31  Fifth Floor, Boston, MA  02110-1301  USA
32*/
33
34#define BITLBEE_CORE
35#include <ctype.h>
36
37#include "nogaim.h"
38
39GSList *connections;
40
41#ifdef WITH_PLUGINS
42GList *plugins = NULL;
43
44static gint pluginscmp(gconstpointer a, gconstpointer b, gpointer data)
45{
46        const struct plugin_info *ia = a;
47        const struct plugin_info *ib = b;
48
49        return g_strcasecmp(ia->name, ib->name);
50}
51
52gboolean load_plugin(char *path)
53{
54        GList *l;
55        struct plugin_info *i;
56        struct plugin_info *info;
57        struct plugin_info * (*info_function) (void) = NULL;
58        void (*init_function) (void);
59
60        GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY);
61        gboolean loaded = FALSE;
62
63        if (!mod) {
64                log_message(LOGLVL_ERROR, "Error loading plugin `%s': %s\n", path, g_module_error());
65                return FALSE;
66        }
67
68        if (g_module_symbol(mod, "init_plugin_info", (gpointer *) &info_function)) {
69                info = info_function();
70
71                if (info->abiver != BITLBEE_ABI_VERSION_CODE) {
72                        log_message(LOGLVL_ERROR,
73                                    "`%s' uses ABI %u but %u is required\n",
74                                    path, info->abiver,
75                                    BITLBEE_ABI_VERSION_CODE);
76                        g_module_close(mod);
77                        return FALSE;
78                }
79
80                if (!info->name || !info->version) {
81                        log_message(LOGLVL_ERROR,
82                                    "Name or version missing from the "
83                                    "plugin info in `%s'\n", path);
84                        g_module_close(mod);
85                        return FALSE;
86                }
87
88                for (l = plugins; l; l = l->next) {
89                        i = l->data;
90
91                        if (g_strcasecmp(i->name, info->name) == 0) {
92                                loaded = TRUE;
93                                break;
94                        }
95                }
96
97                if (loaded) {
98                        log_message(LOGLVL_WARNING,
99                                    "%s plugin already loaded\n",
100                                    info->name);
101                        g_module_close(mod);
102                        return FALSE;
103                }
104        } else {
105                log_message(LOGLVL_WARNING, "Can't find function `init_plugin_info' in `%s'\n", path);
106        }
107
108        if (!g_module_symbol(mod, "init_plugin", (gpointer *) &init_function)) {
109                log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path);
110                g_module_close(mod);
111                return FALSE;
112        }
113
114        if (info_function) {
115                plugins = g_list_insert_sorted_with_data(plugins, info,
116                                                         pluginscmp, NULL);
117        }
118
119        init_function();
120        return TRUE;
121}
122
123void load_plugins(void)
124{
125        GDir *dir;
126        GError *error = NULL;
127
128        dir = g_dir_open(global.conf->plugindir, 0, &error);
129
130        if (dir) {
131                const gchar *entry;
132                char *path;
133
134                while ((entry = g_dir_read_name(dir))) {
135                        if (!g_str_has_suffix(entry, "." G_MODULE_SUFFIX)) {
136                                continue;
137                        }
138
139                        path = g_build_filename(global.conf->plugindir, entry, NULL);
140                        if (!path) {
141                                log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry);
142                                continue;
143                        }
144
145                        load_plugin(path);
146
147                        g_free(path);
148                }
149
150                g_dir_close(dir);
151        }
152}
153
154GList *get_plugins()
155{
156        return plugins;
157}
158#endif
159
160GList *protocols = NULL;
161GList *disabled_protocols = NULL;
162static struct prpl *unknown_prpl;
163
164void register_protocol(struct prpl *p)
165{
166        int i;
167        gboolean refused = global.conf->protocols != NULL;
168
169        for (i = 0; global.conf->protocols && global.conf->protocols[i]; i++) {
170                if (g_strcasecmp(p->name, global.conf->protocols[i]) == 0) {
171                        refused = FALSE;
172                }
173        }
174
175        if (refused) {
176                disabled_protocols = g_list_append(disabled_protocols, p);
177        } else {
178                protocols = g_list_append(protocols, p);
179        }
180}
181
182static int proto_name_cmp(const void *proto_, const void *name)
183{
184        const struct prpl *proto = proto_;
185        return g_strcasecmp(proto->name, name);
186}
187
188struct prpl *find_protocol(const char *name)
189{
190        GList *gl = g_list_find_custom(protocols, name, proto_name_cmp);
191        return gl ? gl->data: NULL;
192}
193
194struct prpl *make_unknown_protocol(const char *name)
195{
196        struct prpl *ret = g_memdup(unknown_prpl, sizeof(struct prpl));
197        ret->name = g_strdup(name);
198        register_protocol(ret);
199        return ret;
200}
201
202gboolean is_protocol_disabled(const char *name)
203{
204        return g_list_find_custom(disabled_protocols, name, proto_name_cmp) != NULL;
205}
206
207/* Returns heap allocated string with text attempting to explain why a protocol is missing
208 * Free the return value with g_free() */
209char *explain_unknown_protocol(const char *name)
210{
211        char *extramsg = NULL;
212
213        if (is_protocol_disabled(name)) {
214                return g_strdup("Protocol disabled in the global config (bitlbee.conf)");
215        }
216
217        if (strcmp(name, "yahoo") == 0) {
218                return g_strdup("The old yahoo protocol is gone, try the funyahoo++ libpurple plugin instead.");
219        }
220
221#ifdef WITH_PURPLE
222        if ((strcmp(name, "msn") == 0) ||
223            (strcmp(name, "loubserp-mxit") == 0) ||
224            (strcmp(name, "myspace") == 0)) {
225                return g_strdup("This protocol has been removed from your libpurple version.");
226        }
227
228        if (strcmp(name, "hipchat") == 0) {
229                return g_strdup("This account type isn't supported by libpurple's jabber.");
230        }
231
232#else
233        if (strcmp(name, "aim") == 0 || strcmp(name, "icq") == 0) {
234                return g_strdup("This account uses libpurple specific aliases for oscar. "
235                                "Re-add the account with `account add oscar ...'");
236        }
237
238        extramsg = "If this is a libpurple plugin, you might need to install bitlbee-libpurple instead.";
239#endif
240        return g_strconcat("The protocol plugin is not installed or could not be loaded. "
241                           "Use the `plugins' command to list available protocols. ",
242                           extramsg, NULL);
243}
244
245void nogaim_init()
246{
247        extern void msn_initmodule();
248        extern void oscar_initmodule();
249        extern void byahoo_initmodule();
250        extern void jabber_initmodule();
251        extern void twitter_initmodule();
252        extern void purple_initmodule();
253        extern void unknown_prpl_initmodule();
254
255        unknown_prpl_initmodule(&unknown_prpl);
256
257#ifdef WITH_MSN
258        msn_initmodule();
259#endif
260
261#ifdef WITH_OSCAR
262        oscar_initmodule();
263#endif
264
265#ifdef WITH_YAHOO
266        byahoo_initmodule();
267#endif
268
269#ifdef WITH_JABBER
270        jabber_initmodule();
271#endif
272
273#ifdef WITH_TWITTER
274        twitter_initmodule();
275#endif
276
277#ifdef WITH_PURPLE
278        purple_initmodule();
279#endif
280
281#ifdef WITH_PLUGINS
282        load_plugins();
283#endif
284}
285
286GList *get_protocols()
287{
288        return protocols;
289}
290
291GList *get_protocols_disabled()
292{
293        return disabled_protocols;
294}
295
296GSList *get_connections()
297{
298        return connections;
299}
300
301struct im_connection *imcb_new(account_t *acc)
302{
303        struct im_connection *ic;
304
305        ic = g_new0(struct im_connection, 1);
306
307        ic->bee = acc->bee;
308        ic->acc = acc;
309        acc->ic = ic;
310
311        connections = g_slist_append(connections, ic);
312
313        return(ic);
314}
315
316void imc_free(struct im_connection *ic)
317{
318        account_t *a;
319
320        /* Destroy the pointer to this connection from the account list */
321        for (a = ic->bee->accounts; a; a = a->next) {
322                if (a->ic == ic) {
323                        a->ic = NULL;
324                        break;
325                }
326        }
327
328        connections = g_slist_remove(connections, ic);
329        g_free(ic);
330}
331
332static void serv_got_crap(struct im_connection *ic, char *format, ...)
333{
334        va_list params;
335        char *text;
336        account_t *a;
337
338        if (!ic->bee->ui->log) {
339                return;
340        }
341
342        va_start(params, format);
343        text = g_strdup_vprintf(format, params);
344        va_end(params);
345
346        if ((g_strcasecmp(set_getstr(&ic->bee->set, "strip_html"), "always") == 0) ||
347            ((ic->flags & OPT_DOES_HTML) && set_getbool(&ic->bee->set, "strip_html"))) {
348                strip_html(text);
349        }
350
351        /* Try to find a different connection on the same protocol. */
352        for (a = ic->bee->accounts; a; a = a->next) {
353                if (a->prpl == ic->acc->prpl && a->ic != ic) {
354                        break;
355                }
356        }
357
358        /* If we found one, include the screenname in the message. */
359        if (a) {
360                ic->bee->ui->log(ic->bee, ic->acc->tag, text);
361        } else {
362                ic->bee->ui->log(ic->bee, ic->acc->prpl->name, text);
363        }
364
365        g_free(text);
366}
367
368void imcb_log(struct im_connection *ic, char *format, ...)
369{
370        va_list params;
371        char *text;
372
373        va_start(params, format);
374        text = g_strdup_vprintf(format, params);
375        va_end(params);
376
377        if (ic->flags & OPT_LOGGED_IN) {
378                serv_got_crap(ic, "%s", text);
379        } else {
380                serv_got_crap(ic, "Logging in: %s", text);
381        }
382
383        g_free(text);
384}
385
386void imcb_error(struct im_connection *ic, char *format, ...)
387{
388        va_list params;
389        char *text;
390
391        va_start(params, format);
392        text = g_strdup_vprintf(format, params);
393        va_end(params);
394
395        if (ic->flags & OPT_LOGGED_IN) {
396                serv_got_crap(ic, "Error: %s", text);
397        } else {
398                serv_got_crap(ic, "Login error: %s", text);
399        }
400
401        g_free(text);
402}
403
404static gboolean send_keepalive(gpointer d, gint fd, b_input_condition cond)
405{
406        struct im_connection *ic = d;
407
408        if ((ic->flags & OPT_PONGS) && !(ic->flags & OPT_PONGED)) {
409                /* This protocol is expected to ack keepalives and hasn't
410                   since the last time we were here. */
411                imcb_error(ic, "Connection timeout");
412                imc_logout(ic, TRUE);
413                return FALSE;
414        }
415        ic->flags &= ~OPT_PONGED;
416
417        if (ic->acc->prpl->keepalive) {
418                ic->acc->prpl->keepalive(ic);
419        }
420
421        return TRUE;
422}
423
424void start_keepalives(struct im_connection *ic, int interval)
425{
426        b_event_remove(ic->keepalive);
427        ic->keepalive = b_timeout_add(interval, send_keepalive, ic);
428
429        /* Connecting successfully counts as a first successful pong. */
430        if (ic->flags & OPT_PONGS) {
431                ic->flags |= OPT_PONGED;
432        }
433}
434
435void imcb_connected(struct im_connection *ic)
436{
437        /* MSN servers sometimes redirect you to a different server and do
438           the whole login sequence again, so these "late" calls to this
439           function should be handled correctly. (IOW, ignored) */
440        if (ic->flags & OPT_LOGGED_IN) {
441                return;
442        }
443
444        if (ic->acc->flags & ACC_FLAG_LOCAL) {
445                GHashTableIter nicks;
446                gpointer k, v;
447                g_hash_table_iter_init(&nicks, ic->acc->nicks);
448                while (g_hash_table_iter_next(&nicks, &k, &v)) {
449                        ic->acc->prpl->add_buddy(ic, (char *) k, NULL);
450                }
451        }
452
453        imcb_log(ic, "Logged in");
454
455        ic->flags |= OPT_LOGGED_IN;
456        start_keepalives(ic, 60000);
457
458        /* Necessary to send initial presence status, even if we're not away. */
459        imc_away_send_update(ic);
460
461        /* Apparently we're connected successfully, so reset the
462           exponential backoff timer. */
463        ic->acc->auto_reconnect_delay = 0;
464
465        if (ic->bee->ui->imc_connected) {
466                ic->bee->ui->imc_connected(ic);
467        }
468}
469
470gboolean auto_reconnect(gpointer data, gint fd, b_input_condition cond)
471{
472        account_t *a = data;
473
474        a->reconnect = 0;
475        account_on(a->bee, a);
476
477        return(FALSE);          /* Only have to run the timeout once */
478}
479
480void cancel_auto_reconnect(account_t *a)
481{
482        b_event_remove(a->reconnect);
483        a->reconnect = 0;
484}
485
486void imc_logout(struct im_connection *ic, int allow_reconnect)
487{
488        bee_t *bee = ic->bee;
489        account_t *a;
490        GSList *l;
491        int delay;
492
493        /* Nested calls might happen sometimes, this is probably the best
494           place to catch them. */
495        if (ic->flags & OPT_LOGGING_OUT) {
496                return;
497        } else {
498                ic->flags |= OPT_LOGGING_OUT;
499        }
500
501        if (ic->bee->ui->imc_disconnected) {
502                ic->bee->ui->imc_disconnected(ic);
503        }
504
505        imcb_log(ic, "Signing off..");
506
507        /* TBH I don't remember anymore why I didn't just use ic->acc... */
508        for (a = bee->accounts; a; a = a->next) {
509                if (a->ic == ic) {
510                        break;
511                }
512        }
513
514        if (a && !allow_reconnect && !(ic->flags & OPT_LOGGED_IN) &&
515            set_getbool(&a->set, "oauth")) {
516                /* If this account supports OAuth, we're not logged in yet and
517                   not allowed to retry, assume there were auth issues. Give a
518                   helpful message on what might be necessary to fix this. */
519                imcb_log(ic, "If you're having problems logging in, try re-requesting "
520                         "an OAuth token: account %s set password \"\"", a->tag);
521        }
522
523        for (l = bee->users; l; ) {
524                bee_user_t *bu = l->data;
525                GSList *next = l->next;
526
527                if (bu->ic == ic) {
528                        bee_user_free(bee, bu);
529                }
530
531                l = next;
532        }
533
534        b_event_remove(ic->keepalive);
535        ic->keepalive = 0;
536        ic->acc->prpl->logout(ic);
537        b_event_remove(ic->inpa);
538
539        g_free(ic->away);
540        ic->away = NULL;
541
542        query_del_by_conn((irc_t *) ic->bee->ui_data, ic);
543
544        if (!a) {
545                /* Uhm... This is very sick. */
546        } else if (allow_reconnect && set_getbool(&bee->set, "auto_reconnect") &&
547                   set_getbool(&a->set, "auto_reconnect") &&
548                   (delay = account_reconnect_delay(a)) > 0) {
549                imcb_log(ic, "Reconnecting in %d seconds..", delay);
550                a->reconnect = b_timeout_add(delay * 1000, auto_reconnect, a);
551        }
552
553        imc_free(ic);
554}
555
556void imcb_ask(struct im_connection *ic, char *msg, void *data,
557              query_callback doit, query_callback dont)
558{
559        query_add((irc_t *) ic->bee->ui_data, ic, msg, doit, dont, g_free, data);
560}
561
562void imcb_ask_with_free(struct im_connection *ic, char *msg, void *data,
563                        query_callback doit, query_callback dont, query_callback myfree)
564{
565        query_add((irc_t *) ic->bee->ui_data, ic, msg, doit, dont, myfree, data);
566}
567
568void imcb_add_buddy(struct im_connection *ic, const char *handle, const char *group)
569{
570        bee_user_t *bu;
571        bee_t *bee = ic->bee;
572        bee_group_t *oldg;
573
574        if (!(bu = bee_user_by_handle(bee, ic, handle))) {
575                bu = bee_user_new(bee, ic, handle, 0);
576        }
577
578        oldg = bu->group;
579        bu->group = bee_group_by_name(bee, group, TRUE);
580
581        if (bee->ui->user_group && bu->group != oldg) {
582                bee->ui->user_group(bee, bu);
583        }
584}
585
586void imcb_rename_buddy(struct im_connection *ic, const char *handle, const char *fullname)
587{
588        bee_t *bee = ic->bee;
589        bee_user_t *bu = bee_user_by_handle(bee, ic, handle);
590
591        if (!bu || !fullname) {
592                return;
593        }
594
595        if (!bu->fullname || strcmp(bu->fullname, fullname) != 0) {
596                g_free(bu->fullname);
597                bu->fullname = g_strdup(fullname);
598
599                if (bee->ui->user_fullname) {
600                        bee->ui->user_fullname(bee, bu);
601                }
602        }
603}
604
605void imcb_remove_buddy(struct im_connection *ic, const char *handle, char *group)
606{
607        bee_user_free(ic->bee, bee_user_by_handle(ic->bee, ic, handle));
608}
609
610/* Implements either imcb_buddy_nick_hint() or imcb_buddy_nick_change() depending on the value of 'change' */
611static void buddy_nick_hint_or_change(struct im_connection *ic, const char *handle, const char *nick, gboolean change)
612{
613        bee_t *bee = ic->bee;
614        bee_user_t *bu = bee_user_by_handle(bee, ic, handle);
615
616        if (!bu || !nick) {
617                return;
618        }
619
620        g_free(bu->nick);
621        bu->nick = g_strdup(nick);
622
623        if (change && bee->ui->user_nick_change) {
624                bee->ui->user_nick_change(bee, bu, nick);
625        } else if (!change && bee->ui->user_nick_hint) {
626                bee->ui->user_nick_hint(bee, bu, nick);
627        }
628}
629
630/* Soft variant, for newly created users. Does nothing if it's already online */
631void imcb_buddy_nick_hint(struct im_connection *ic, const char *handle, const char *nick)
632{
633        buddy_nick_hint_or_change(ic, handle, nick, FALSE);
634}
635
636/* Hard variant, always changes the nick */
637void imcb_buddy_nick_change(struct im_connection *ic, const char *handle, const char *nick)
638{
639        buddy_nick_hint_or_change(ic, handle, nick, TRUE);
640}
641
642struct imcb_ask_cb_data {
643        struct im_connection *ic;
644        char *handle;
645};
646
647static void imcb_ask_cb_free(void *data)
648{
649        struct imcb_ask_cb_data *cbd = data;
650
651        g_free(cbd->handle);
652        g_free(cbd);
653}
654
655static void imcb_ask_auth_cb_no(void *data)
656{
657        struct imcb_ask_cb_data *cbd = data;
658
659        cbd->ic->acc->prpl->auth_deny(cbd->ic, cbd->handle);
660
661        imcb_ask_cb_free(cbd);
662}
663
664static void imcb_ask_auth_cb_yes(void *data)
665{
666        struct imcb_ask_cb_data *cbd = data;
667
668        cbd->ic->acc->prpl->auth_allow(cbd->ic, cbd->handle);
669
670        imcb_ask_cb_free(cbd);
671}
672
673void imcb_ask_auth(struct im_connection *ic, const char *handle, const char *realname)
674{
675        struct imcb_ask_cb_data *data = g_new0(struct imcb_ask_cb_data, 1);
676        char *s, *realname_ = NULL;
677
678        if (realname != NULL) {
679                realname_ = g_strdup_printf(" (%s)", realname);
680        }
681
682        s = g_strdup_printf("The user %s%s wants to add you to his/her buddy list.",
683                            handle, realname_ ? realname_ : "");
684
685        g_free(realname_);
686
687        data->ic = ic;
688        data->handle = g_strdup(handle);
689        query_add((irc_t *) ic->bee->ui_data, ic, s,
690                  imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, imcb_ask_cb_free, data);
691
692        g_free(s);
693}
694
695static void imcb_ask_add_cb_yes(void *data)
696{
697        struct imcb_ask_cb_data *cbd = data;
698
699        cbd->ic->acc->prpl->add_buddy(cbd->ic, cbd->handle, NULL);
700
701        imcb_ask_cb_free(data);
702}
703
704void imcb_ask_add(struct im_connection *ic, const char *handle, const char *realname)
705{
706        struct imcb_ask_cb_data *data;
707        char *s;
708
709        /* TODO: Make a setting for this! */
710        if (bee_user_by_handle(ic->bee, ic, handle) != NULL) {
711                return;
712        }
713
714        data = g_new0(struct imcb_ask_cb_data, 1);
715
716        s = g_strdup_printf("The user %s is not in your buddy list yet. Do you want to add him/her now?", handle);
717
718        data->ic = ic;
719        data->handle = g_strdup(handle);
720        query_add((irc_t *) ic->bee->ui_data, ic, s,
721                  imcb_ask_add_cb_yes, imcb_ask_cb_free, imcb_ask_cb_free, data);
722
723        g_free(s);
724}
725
726struct bee_user *imcb_buddy_by_handle(struct im_connection *ic, const char *handle)
727{
728        return bee_user_by_handle(ic->bee, ic, handle);
729}
730
731/* The plan is to not allow straight calls to prpl functions anymore, but do
732   them all from some wrappers. We'll start to define some down here: */
733
734int imc_chat_msg(struct groupchat *c, char *msg, int flags)
735{
736        char *buf = NULL;
737
738        if ((c->ic->flags & OPT_DOES_HTML) && (g_strncasecmp(msg, "<html>", 6) != 0)) {
739                buf = escape_html(msg);
740                msg = buf;
741        }
742
743        c->ic->acc->prpl->chat_msg(c, msg, flags);
744        g_free(buf);
745
746        return 1;
747}
748
749static char *imc_away_state_find(GList *gcm, char *away, char **message);
750
751int imc_away_send_update(struct im_connection *ic)
752{
753        char *away, *msg = NULL;
754
755        if (ic->acc->prpl->away_states == NULL ||
756            ic->acc->prpl->set_away == NULL) {
757                return 0;
758        }
759
760        away = set_getstr(&ic->acc->set, "away") ?
761               : set_getstr(&ic->bee->set, "away");
762        if (away && *away) {
763                GList *m = ic->acc->prpl->away_states(ic);
764                if (m == NULL) {
765                        return 0;
766                }
767                msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL;
768                away = imc_away_state_find(m, away, &msg) ? :
769                       (imc_away_state_find(m, "away", &msg) ? : m->data);
770        } else if (ic->acc->flags & ACC_FLAG_STATUS_MESSAGE) {
771                away = NULL;
772                msg = set_getstr(&ic->acc->set, "status") ?
773                      : set_getstr(&ic->bee->set, "status");
774        }
775
776        ic->acc->prpl->set_away(ic, away, msg);
777
778        return 1;
779}
780
781static char *imc_away_alias_list[8][5] =
782{
783        { "Away from computer", "Away", "Extended away", NULL },
784        { "NA", "N/A", "Not available", NULL },
785        { "Busy", "Do not disturb", "DND", "Occupied", NULL },
786        { "Be right back", "BRB", NULL },
787        { "On the phone", "Phone", "On phone", NULL },
788        { "Out to lunch", "Lunch", "Food", NULL },
789        { "Invisible", "Hidden" },
790        { NULL }
791};
792
793static char *imc_away_state_find(GList *gcm, char *away, char **message)
794{
795        GList *m;
796        int i, j;
797
798        for (m = gcm; m; m = m->next) {
799                if (g_strncasecmp(m->data, away, strlen(m->data)) == 0) {
800                        /* At least the Yahoo! module works better if message
801                           contains no data unless it adds something to what
802                           we have in state already. */
803                        if (strlen(m->data) == strlen(away)) {
804                                *message = NULL;
805                        }
806
807                        return m->data;
808                }
809        }
810
811        for (i = 0; *imc_away_alias_list[i]; i++) {
812                int keep_message;
813
814                for (j = 0; imc_away_alias_list[i][j]; j++) {
815                        if (g_strncasecmp(away, imc_away_alias_list[i][j], strlen(imc_away_alias_list[i][j])) == 0) {
816                                keep_message = strlen(away) != strlen(imc_away_alias_list[i][j]);
817                                break;
818                        }
819                }
820
821                if (!imc_away_alias_list[i][j]) {       /* If we reach the end, this row */
822                        continue;                       /* is not what we want. Next!    */
823
824                }
825                /* Now find an entry in this row which exists in gcm */
826                for (j = 0; imc_away_alias_list[i][j]; j++) {
827                        for (m = gcm; m; m = m->next) {
828                                if (g_strcasecmp(imc_away_alias_list[i][j], m->data) == 0) {
829                                        if (!keep_message) {
830                                                *message = NULL;
831                                        }
832
833                                        return imc_away_alias_list[i][j];
834                                }
835                        }
836                }
837
838                /* No need to look further, apparently this state doesn't
839                   have any good alias for this protocol. */
840                break;
841        }
842
843        return NULL;
844}
845
846void imc_add_allow(struct im_connection *ic, char *handle)
847{
848        if (g_slist_find_custom(ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp) == NULL) {
849                ic->permit = g_slist_prepend(ic->permit, g_strdup(handle));
850        }
851
852        ic->acc->prpl->add_permit(ic, handle);
853}
854
855void imc_rem_allow(struct im_connection *ic, char *handle)
856{
857        GSList *l;
858
859        if ((l = g_slist_find_custom(ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp))) {
860                g_free(l->data);
861                ic->permit = g_slist_delete_link(ic->permit, l);
862        }
863
864        ic->acc->prpl->rem_permit(ic, handle);
865}
866
867void imc_add_block(struct im_connection *ic, char *handle)
868{
869        if (g_slist_find_custom(ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp) == NULL) {
870                ic->deny = g_slist_prepend(ic->deny, g_strdup(handle));
871        }
872
873        ic->acc->prpl->add_deny(ic, handle);
874}
875
876void imc_rem_block(struct im_connection *ic, char *handle)
877{
878        GSList *l;
879
880        if ((l = g_slist_find_custom(ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp))) {
881                g_free(l->data);
882                ic->deny = g_slist_delete_link(ic->deny, l);
883        }
884
885        ic->acc->prpl->rem_deny(ic, handle);
886}
887
888/* Deprecated: using this function resulted in merging several handles accidentally
889 * Also the irc layer handles this decently nowadays */
890void imcb_clean_handle(struct im_connection *ic, char *handle)
891{
892}
Note: See TracBrowser for help on using the repository browser.