source: protocols/nogaim.c @ 66b7741

Last change on this file since 66b7741 was a7baf40, checked in by dequis <dx@…>, at 2016-11-19T07:59:14Z

Remove yahoo (the old protocol). Use funyahoo++ instead.

RIP

The previous commit already handled the part of telling users.

  • Property mode set to 100644
File size: 21.1 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 jabber_initmodule();
250        extern void twitter_initmodule();
251        extern void purple_initmodule();
252        extern void unknown_prpl_initmodule();
253
254        unknown_prpl_initmodule(&unknown_prpl);
255
256#ifdef WITH_MSN
257        msn_initmodule();
258#endif
259
260#ifdef WITH_OSCAR
261        oscar_initmodule();
262#endif
263
264#ifdef WITH_JABBER
265        jabber_initmodule();
266#endif
267
268#ifdef WITH_TWITTER
269        twitter_initmodule();
270#endif
271
272#ifdef WITH_PURPLE
273        purple_initmodule();
274#endif
275
276#ifdef WITH_PLUGINS
277        load_plugins();
278#endif
279}
280
281GList *get_protocols()
282{
283        return protocols;
284}
285
286GList *get_protocols_disabled()
287{
288        return disabled_protocols;
289}
290
291GSList *get_connections()
292{
293        return connections;
294}
295
296struct im_connection *imcb_new(account_t *acc)
297{
298        struct im_connection *ic;
299
300        ic = g_new0(struct im_connection, 1);
301
302        ic->bee = acc->bee;
303        ic->acc = acc;
304        acc->ic = ic;
305
306        connections = g_slist_append(connections, ic);
307
308        return(ic);
309}
310
311void imc_free(struct im_connection *ic)
312{
313        account_t *a;
314
315        /* Destroy the pointer to this connection from the account list */
316        for (a = ic->bee->accounts; a; a = a->next) {
317                if (a->ic == ic) {
318                        a->ic = NULL;
319                        break;
320                }
321        }
322
323        connections = g_slist_remove(connections, ic);
324        g_free(ic);
325}
326
327static void serv_got_crap(struct im_connection *ic, char *format, ...)
328{
329        va_list params;
330        char *text;
331        account_t *a;
332
333        if (!ic->bee->ui->log) {
334                return;
335        }
336
337        va_start(params, format);
338        text = g_strdup_vprintf(format, params);
339        va_end(params);
340
341        if ((g_strcasecmp(set_getstr(&ic->bee->set, "strip_html"), "always") == 0) ||
342            ((ic->flags & OPT_DOES_HTML) && set_getbool(&ic->bee->set, "strip_html"))) {
343                strip_html(text);
344        }
345
346        /* Try to find a different connection on the same protocol. */
347        for (a = ic->bee->accounts; a; a = a->next) {
348                if (a->prpl == ic->acc->prpl && a->ic != ic) {
349                        break;
350                }
351        }
352
353        /* If we found one, include the screenname in the message. */
354        if (a) {
355                ic->bee->ui->log(ic->bee, ic->acc->tag, text);
356        } else {
357                ic->bee->ui->log(ic->bee, ic->acc->prpl->name, text);
358        }
359
360        g_free(text);
361}
362
363void imcb_log(struct im_connection *ic, char *format, ...)
364{
365        va_list params;
366        char *text;
367
368        va_start(params, format);
369        text = g_strdup_vprintf(format, params);
370        va_end(params);
371
372        if (ic->flags & OPT_LOGGED_IN) {
373                serv_got_crap(ic, "%s", text);
374        } else {
375                serv_got_crap(ic, "Logging in: %s", text);
376        }
377
378        g_free(text);
379}
380
381void imcb_error(struct im_connection *ic, char *format, ...)
382{
383        va_list params;
384        char *text;
385
386        va_start(params, format);
387        text = g_strdup_vprintf(format, params);
388        va_end(params);
389
390        if (ic->flags & OPT_LOGGED_IN) {
391                serv_got_crap(ic, "Error: %s", text);
392        } else {
393                serv_got_crap(ic, "Login error: %s", text);
394        }
395
396        g_free(text);
397}
398
399static gboolean send_keepalive(gpointer d, gint fd, b_input_condition cond)
400{
401        struct im_connection *ic = d;
402
403        if ((ic->flags & OPT_PONGS) && !(ic->flags & OPT_PONGED)) {
404                /* This protocol is expected to ack keepalives and hasn't
405                   since the last time we were here. */
406                imcb_error(ic, "Connection timeout");
407                imc_logout(ic, TRUE);
408                return FALSE;
409        }
410        ic->flags &= ~OPT_PONGED;
411
412        if (ic->acc->prpl->keepalive) {
413                ic->acc->prpl->keepalive(ic);
414        }
415
416        return TRUE;
417}
418
419void start_keepalives(struct im_connection *ic, int interval)
420{
421        b_event_remove(ic->keepalive);
422        ic->keepalive = b_timeout_add(interval, send_keepalive, ic);
423
424        /* Connecting successfully counts as a first successful pong. */
425        if (ic->flags & OPT_PONGS) {
426                ic->flags |= OPT_PONGED;
427        }
428}
429
430void imcb_connected(struct im_connection *ic)
431{
432        /* MSN servers sometimes redirect you to a different server and do
433           the whole login sequence again, so these "late" calls to this
434           function should be handled correctly. (IOW, ignored) */
435        if (ic->flags & OPT_LOGGED_IN) {
436                return;
437        }
438
439        if (ic->acc->flags & ACC_FLAG_LOCAL) {
440                GHashTableIter nicks;
441                gpointer k, v;
442                g_hash_table_iter_init(&nicks, ic->acc->nicks);
443                while (g_hash_table_iter_next(&nicks, &k, &v)) {
444                        ic->acc->prpl->add_buddy(ic, (char *) k, NULL);
445                }
446        }
447
448        imcb_log(ic, "Logged in");
449
450        ic->flags |= OPT_LOGGED_IN;
451        start_keepalives(ic, 60000);
452
453        /* Necessary to send initial presence status, even if we're not away. */
454        imc_away_send_update(ic);
455
456        /* Apparently we're connected successfully, so reset the
457           exponential backoff timer. */
458        ic->acc->auto_reconnect_delay = 0;
459
460        if (ic->bee->ui->imc_connected) {
461                ic->bee->ui->imc_connected(ic);
462        }
463}
464
465gboolean auto_reconnect(gpointer data, gint fd, b_input_condition cond)
466{
467        account_t *a = data;
468
469        a->reconnect = 0;
470        account_on(a->bee, a);
471
472        return(FALSE);          /* Only have to run the timeout once */
473}
474
475void cancel_auto_reconnect(account_t *a)
476{
477        b_event_remove(a->reconnect);
478        a->reconnect = 0;
479}
480
481void imc_logout(struct im_connection *ic, int allow_reconnect)
482{
483        bee_t *bee = ic->bee;
484        account_t *a;
485        GSList *l;
486        int delay;
487
488        /* Nested calls might happen sometimes, this is probably the best
489           place to catch them. */
490        if (ic->flags & OPT_LOGGING_OUT) {
491                return;
492        } else {
493                ic->flags |= OPT_LOGGING_OUT;
494        }
495
496        if (ic->bee->ui->imc_disconnected) {
497                ic->bee->ui->imc_disconnected(ic);
498        }
499
500        imcb_log(ic, "Signing off..");
501
502        /* TBH I don't remember anymore why I didn't just use ic->acc... */
503        for (a = bee->accounts; a; a = a->next) {
504                if (a->ic == ic) {
505                        break;
506                }
507        }
508
509        if (a && !allow_reconnect && !(ic->flags & OPT_LOGGED_IN) &&
510            set_getbool(&a->set, "oauth")) {
511                /* If this account supports OAuth, we're not logged in yet and
512                   not allowed to retry, assume there were auth issues. Give a
513                   helpful message on what might be necessary to fix this. */
514                imcb_log(ic, "If you're having problems logging in, try re-requesting "
515                         "an OAuth token: account %s set password \"\"", a->tag);
516        }
517
518        for (l = bee->users; l; ) {
519                bee_user_t *bu = l->data;
520                GSList *next = l->next;
521
522                if (bu->ic == ic) {
523                        bee_user_free(bee, bu);
524                }
525
526                l = next;
527        }
528
529        b_event_remove(ic->keepalive);
530        ic->keepalive = 0;
531        ic->acc->prpl->logout(ic);
532        b_event_remove(ic->inpa);
533
534        g_free(ic->away);
535        ic->away = NULL;
536
537        query_del_by_conn((irc_t *) ic->bee->ui_data, ic);
538
539        if (!a) {
540                /* Uhm... This is very sick. */
541        } else if (allow_reconnect && set_getbool(&bee->set, "auto_reconnect") &&
542                   set_getbool(&a->set, "auto_reconnect") &&
543                   (delay = account_reconnect_delay(a)) > 0) {
544                imcb_log(ic, "Reconnecting in %d seconds..", delay);
545                a->reconnect = b_timeout_add(delay * 1000, auto_reconnect, a);
546        }
547
548        imc_free(ic);
549}
550
551void imcb_ask(struct im_connection *ic, char *msg, void *data,
552              query_callback doit, query_callback dont)
553{
554        query_add((irc_t *) ic->bee->ui_data, ic, msg, doit, dont, g_free, data);
555}
556
557void imcb_ask_with_free(struct im_connection *ic, char *msg, void *data,
558                        query_callback doit, query_callback dont, query_callback myfree)
559{
560        query_add((irc_t *) ic->bee->ui_data, ic, msg, doit, dont, myfree, data);
561}
562
563void imcb_add_buddy(struct im_connection *ic, const char *handle, const char *group)
564{
565        bee_user_t *bu;
566        bee_t *bee = ic->bee;
567        bee_group_t *oldg;
568
569        if (!(bu = bee_user_by_handle(bee, ic, handle))) {
570                bu = bee_user_new(bee, ic, handle, 0);
571        }
572
573        oldg = bu->group;
574        bu->group = bee_group_by_name(bee, group, TRUE);
575
576        if (bee->ui->user_group && bu->group != oldg) {
577                bee->ui->user_group(bee, bu);
578        }
579}
580
581void imcb_rename_buddy(struct im_connection *ic, const char *handle, const char *fullname)
582{
583        bee_t *bee = ic->bee;
584        bee_user_t *bu = bee_user_by_handle(bee, ic, handle);
585
586        if (!bu || !fullname) {
587                return;
588        }
589
590        if (!bu->fullname || strcmp(bu->fullname, fullname) != 0) {
591                g_free(bu->fullname);
592                bu->fullname = g_strdup(fullname);
593
594                if (bee->ui->user_fullname) {
595                        bee->ui->user_fullname(bee, bu);
596                }
597        }
598}
599
600void imcb_remove_buddy(struct im_connection *ic, const char *handle, char *group)
601{
602        bee_user_free(ic->bee, bee_user_by_handle(ic->bee, ic, handle));
603}
604
605/* Implements either imcb_buddy_nick_hint() or imcb_buddy_nick_change() depending on the value of 'change' */
606static void buddy_nick_hint_or_change(struct im_connection *ic, const char *handle, const char *nick, gboolean change)
607{
608        bee_t *bee = ic->bee;
609        bee_user_t *bu = bee_user_by_handle(bee, ic, handle);
610
611        if (!bu || !nick) {
612                return;
613        }
614
615        g_free(bu->nick);
616        bu->nick = g_strdup(nick);
617
618        if (change && bee->ui->user_nick_change) {
619                bee->ui->user_nick_change(bee, bu, nick);
620        } else if (!change && bee->ui->user_nick_hint) {
621                bee->ui->user_nick_hint(bee, bu, nick);
622        }
623}
624
625/* Soft variant, for newly created users. Does nothing if it's already online */
626void imcb_buddy_nick_hint(struct im_connection *ic, const char *handle, const char *nick)
627{
628        buddy_nick_hint_or_change(ic, handle, nick, FALSE);
629}
630
631/* Hard variant, always changes the nick */
632void imcb_buddy_nick_change(struct im_connection *ic, const char *handle, const char *nick)
633{
634        buddy_nick_hint_or_change(ic, handle, nick, TRUE);
635}
636
637struct imcb_ask_cb_data {
638        struct im_connection *ic;
639        char *handle;
640};
641
642static void imcb_ask_cb_free(void *data)
643{
644        struct imcb_ask_cb_data *cbd = data;
645
646        g_free(cbd->handle);
647        g_free(cbd);
648}
649
650static void imcb_ask_auth_cb_no(void *data)
651{
652        struct imcb_ask_cb_data *cbd = data;
653
654        cbd->ic->acc->prpl->auth_deny(cbd->ic, cbd->handle);
655
656        imcb_ask_cb_free(cbd);
657}
658
659static void imcb_ask_auth_cb_yes(void *data)
660{
661        struct imcb_ask_cb_data *cbd = data;
662
663        cbd->ic->acc->prpl->auth_allow(cbd->ic, cbd->handle);
664
665        imcb_ask_cb_free(cbd);
666}
667
668void imcb_ask_auth(struct im_connection *ic, const char *handle, const char *realname)
669{
670        struct imcb_ask_cb_data *data = g_new0(struct imcb_ask_cb_data, 1);
671        char *s, *realname_ = NULL;
672
673        if (realname != NULL) {
674                realname_ = g_strdup_printf(" (%s)", realname);
675        }
676
677        s = g_strdup_printf("The user %s%s wants to add you to his/her buddy list.",
678                            handle, realname_ ? realname_ : "");
679
680        g_free(realname_);
681
682        data->ic = ic;
683        data->handle = g_strdup(handle);
684        query_add((irc_t *) ic->bee->ui_data, ic, s,
685                  imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, imcb_ask_cb_free, data);
686
687        g_free(s);
688}
689
690static void imcb_ask_add_cb_yes(void *data)
691{
692        struct imcb_ask_cb_data *cbd = data;
693
694        cbd->ic->acc->prpl->add_buddy(cbd->ic, cbd->handle, NULL);
695
696        imcb_ask_cb_free(data);
697}
698
699void imcb_ask_add(struct im_connection *ic, const char *handle, const char *realname)
700{
701        struct imcb_ask_cb_data *data;
702        char *s;
703
704        /* TODO: Make a setting for this! */
705        if (bee_user_by_handle(ic->bee, ic, handle) != NULL) {
706                return;
707        }
708
709        data = g_new0(struct imcb_ask_cb_data, 1);
710
711        s = g_strdup_printf("The user %s is not in your buddy list yet. Do you want to add him/her now?", handle);
712
713        data->ic = ic;
714        data->handle = g_strdup(handle);
715        query_add((irc_t *) ic->bee->ui_data, ic, s,
716                  imcb_ask_add_cb_yes, imcb_ask_cb_free, imcb_ask_cb_free, data);
717
718        g_free(s);
719}
720
721struct bee_user *imcb_buddy_by_handle(struct im_connection *ic, const char *handle)
722{
723        return bee_user_by_handle(ic->bee, ic, handle);
724}
725
726/* The plan is to not allow straight calls to prpl functions anymore, but do
727   them all from some wrappers. We'll start to define some down here: */
728
729int imc_chat_msg(struct groupchat *c, char *msg, int flags)
730{
731        char *buf = NULL;
732
733        if ((c->ic->flags & OPT_DOES_HTML) && (g_strncasecmp(msg, "<html>", 6) != 0)) {
734                buf = escape_html(msg);
735                msg = buf;
736        }
737
738        c->ic->acc->prpl->chat_msg(c, msg, flags);
739        g_free(buf);
740
741        return 1;
742}
743
744static char *imc_away_state_find(GList *gcm, char *away, char **message);
745
746int imc_away_send_update(struct im_connection *ic)
747{
748        char *away, *msg = NULL;
749
750        if (ic->acc->prpl->away_states == NULL ||
751            ic->acc->prpl->set_away == NULL) {
752                return 0;
753        }
754
755        away = set_getstr(&ic->acc->set, "away") ?
756               : set_getstr(&ic->bee->set, "away");
757        if (away && *away) {
758                GList *m = ic->acc->prpl->away_states(ic);
759                if (m == NULL) {
760                        return 0;
761                }
762                msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL;
763                away = imc_away_state_find(m, away, &msg) ? :
764                       (imc_away_state_find(m, "away", &msg) ? : m->data);
765        } else if (ic->acc->flags & ACC_FLAG_STATUS_MESSAGE) {
766                away = NULL;
767                msg = set_getstr(&ic->acc->set, "status") ?
768                      : set_getstr(&ic->bee->set, "status");
769        }
770
771        ic->acc->prpl->set_away(ic, away, msg);
772
773        return 1;
774}
775
776static char *imc_away_alias_list[8][5] =
777{
778        { "Away from computer", "Away", "Extended away", NULL },
779        { "NA", "N/A", "Not available", NULL },
780        { "Busy", "Do not disturb", "DND", "Occupied", NULL },
781        { "Be right back", "BRB", NULL },
782        { "On the phone", "Phone", "On phone", NULL },
783        { "Out to lunch", "Lunch", "Food", NULL },
784        { "Invisible", "Hidden" },
785        { NULL }
786};
787
788static char *imc_away_state_find(GList *gcm, char *away, char **message)
789{
790        GList *m;
791        int i, j;
792
793        for (m = gcm; m; m = m->next) {
794                if (g_strncasecmp(m->data, away, strlen(m->data)) == 0) {
795                        /* At least the Yahoo! module works better if message
796                           contains no data unless it adds something to what
797                           we have in state already. */
798                        if (strlen(m->data) == strlen(away)) {
799                                *message = NULL;
800                        }
801
802                        return m->data;
803                }
804        }
805
806        for (i = 0; *imc_away_alias_list[i]; i++) {
807                int keep_message;
808
809                for (j = 0; imc_away_alias_list[i][j]; j++) {
810                        if (g_strncasecmp(away, imc_away_alias_list[i][j], strlen(imc_away_alias_list[i][j])) == 0) {
811                                keep_message = strlen(away) != strlen(imc_away_alias_list[i][j]);
812                                break;
813                        }
814                }
815
816                if (!imc_away_alias_list[i][j]) {       /* If we reach the end, this row */
817                        continue;                       /* is not what we want. Next!    */
818
819                }
820                /* Now find an entry in this row which exists in gcm */
821                for (j = 0; imc_away_alias_list[i][j]; j++) {
822                        for (m = gcm; m; m = m->next) {
823                                if (g_strcasecmp(imc_away_alias_list[i][j], m->data) == 0) {
824                                        if (!keep_message) {
825                                                *message = NULL;
826                                        }
827
828                                        return imc_away_alias_list[i][j];
829                                }
830                        }
831                }
832
833                /* No need to look further, apparently this state doesn't
834                   have any good alias for this protocol. */
835                break;
836        }
837
838        return NULL;
839}
840
841void imc_add_allow(struct im_connection *ic, char *handle)
842{
843        if (g_slist_find_custom(ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp) == NULL) {
844                ic->permit = g_slist_prepend(ic->permit, g_strdup(handle));
845        }
846
847        ic->acc->prpl->add_permit(ic, handle);
848}
849
850void imc_rem_allow(struct im_connection *ic, char *handle)
851{
852        GSList *l;
853
854        if ((l = g_slist_find_custom(ic->permit, handle, (GCompareFunc) ic->acc->prpl->handle_cmp))) {
855                g_free(l->data);
856                ic->permit = g_slist_delete_link(ic->permit, l);
857        }
858
859        ic->acc->prpl->rem_permit(ic, handle);
860}
861
862void imc_add_block(struct im_connection *ic, char *handle)
863{
864        if (g_slist_find_custom(ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp) == NULL) {
865                ic->deny = g_slist_prepend(ic->deny, g_strdup(handle));
866        }
867
868        ic->acc->prpl->add_deny(ic, handle);
869}
870
871void imc_rem_block(struct im_connection *ic, char *handle)
872{
873        GSList *l;
874
875        if ((l = g_slist_find_custom(ic->deny, handle, (GCompareFunc) ic->acc->prpl->handle_cmp))) {
876                g_free(l->data);
877                ic->deny = g_slist_delete_link(ic->deny, l);
878        }
879
880        ic->acc->prpl->rem_deny(ic, handle);
881}
882
883/* Deprecated: using this function resulted in merging several handles accidentally
884 * Also the irc layer handles this decently nowadays */
885void imcb_clean_handle(struct im_connection *ic, char *handle)
886{
887}
Note: See TracBrowser for help on using the repository browser.