source: protocols/msn/msn.c @ d550358

Last change on this file since d550358 was d550358, checked in by dequis <dx@…>, at 2015-04-10T17:10:40Z

msn: remove unsupported commands, OIMs and dead code

  • Property mode set to 100644
File size: 10.2 KB
RevLine 
[5ebff60]1/********************************************************************\
[b7d3cc34]2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
[0e788f5]4  * Copyright 2002-2013 Wilmer van der Gaast and others                *
[b7d3cc34]5  \********************************************************************/
6
7/* MSN module - Main file; functions to be called from BitlBee          */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
[6f10697]22  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
23  Fifth Floor, Boston, MA  02110-1301  USA
[b7d3cc34]24*/
25
26#include "nogaim.h"
[4452e69]27#include "soap.h"
[b7d3cc34]28#include "msn.h"
29
[c6ca3ee]30int msn_chat_id;
31GSList *msn_connections;
32
[5ebff60]33static char *set_eval_display_name(set_t *set, char *value);
[911f2eb]34
[5ebff60]35static void msn_init(account_t *acc)
[911f2eb]36{
[4452e69]37        set_t *s;
[5ebff60]38
39        s = set_add(&acc->set, "display_name", NULL, set_eval_display_name, acc);
[bb5ce568]40        s->flags |= SET_NOSAVE | ACC_SET_ONLINE_ONLY;
[5ebff60]41
[a6b00fc]42        s = set_add(&acc->set, "server", NULL, set_eval_account, acc);
[bc7a0d4]43        s->flags |= SET_NOSAVE | ACC_SET_OFFLINE_ONLY;
44
[5ebff60]45        s = set_add(&acc->set, "port", MSN_NS_PORT, set_eval_int, acc);
[bc7a0d4]46        s->flags |= ACC_SET_OFFLINE_ONLY;
47
[5ebff60]48        set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc);
49
[06eef80]50        acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE |
51                      ACC_FLAG_HANDLE_DOMAINS;
[911f2eb]52}
53
[5ebff60]54static void msn_login(account_t *acc)
[b7d3cc34]55{
[5ebff60]56        struct im_connection *ic = imcb_new(acc);
57        struct msn_data *md = g_new0(struct msn_data, 1);
[a6b00fc]58        char *server = set_getstr(&ic->acc->set, "server");
[5ebff60]59
[0da65d5]60        ic->proto_data = md;
[e132b60]61        ic->flags |= OPT_PONGS | OPT_PONGED;
[5ebff60]62
[a6b00fc]63        if (!server) {
64                imcb_error(ic, "The msn protocol is disabled in this version because most servers disabled MSNP18 over port 1863.");
65                imcb_error(ic, "If you find a working server, you can change the 'server' setting of this account. Good luck!");
66                imcb_error(ic, "See also: http://ismsndeadyet.com/"); // shameless plug
67                imc_logout(ic, FALSE);
68                return;
69        }
70
[5ebff60]71        if (strchr(acc->user, '@') == NULL) {
72                imcb_error(ic, "Invalid account name");
73                imc_logout(ic, FALSE);
[b7d3cc34]74                return;
75        }
[5ebff60]76
[0da65d5]77        md->ic = ic;
[2a29eac]78        md->away_state = msn_away_state_list;
[5ebff60]79        md->domaintree = g_tree_new(msn_domaintree_cmp);
[11e42dc]80        md->fd = -1;
[5ebff60]81
82        msn_connections = g_slist_prepend(msn_connections, ic);
83
84        imcb_log(ic, "Connecting");
[11e42dc]85        msn_ns_connect(ic, server,
[5ebff60]86                       set_getint(&ic->acc->set, "port"));
[b7d3cc34]87}
88
[5ebff60]89static void msn_logout(struct im_connection *ic)
[b7d3cc34]90{
[0da65d5]91        struct msn_data *md = ic->proto_data;
[b7d3cc34]92        GSList *l;
[80175a1]93        int i;
[5ebff60]94
95        if (md) {
[11e42dc]96                msn_ns_close(md);
[5ebff60]97
98                msn_soapq_flush(ic, FALSE);
99
100                for (i = 0; i < sizeof(md->tokens) / sizeof(md->tokens[0]); i++) {
101                        g_free(md->tokens[i]);
102                }
103                g_free(md->lock_key);
104                g_free(md->pp_policy);
105                g_free(md->uuid);
106
107                while (md->groups) {
[ff27648]108                        struct msn_group *mg = md->groups->data;
[05816dd]109                        md->groups = g_slist_remove(md->groups, mg);
[5ebff60]110                        g_free(mg->id);
111                        g_free(mg->name);
112                        g_free(mg);
113                }
114
115                g_free(md->profile_rid);
116
117                if (md->domaintree) {
118                        g_tree_destroy(md->domaintree);
[ff27648]119                }
[ca7de3a]120                md->domaintree = NULL;
[5ebff60]121
122                while (md->grpq) {
[70ac477]123                        struct msn_groupadd *ga = md->grpq->data;
[05816dd]124                        md->grpq = g_slist_remove(md->grpq, ga);
[5ebff60]125                        g_free(ga->group);
126                        g_free(ga->who);
127                        g_free(ga);
[70ac477]128                }
[5ebff60]129
130                g_free(md);
131        }
132
133        for (l = ic->permit; l; l = l->next) {
134                g_free(l->data);
135        }
136        g_slist_free(ic->permit);
137
138        for (l = ic->deny; l; l = l->next) {
139                g_free(l->data);
[b7d3cc34]140        }
[5ebff60]141        g_slist_free(ic->deny);
142
143        msn_connections = g_slist_remove(msn_connections, ic);
[b7d3cc34]144}
145
[5ebff60]146static int msn_buddy_msg(struct im_connection *ic, char *who, char *message, int away)
[b7d3cc34]147{
[5ebff60]148        struct bee_user *bu = bee_user_by_handle(ic->bee, ic, who);
149
[70ac477]150#ifdef DEBUG
[5ebff60]151        if (strcmp(who, "raw") == 0) {
152                msn_ns_write(ic, -1, "%s\r\n", message);
[11e42dc]153                return 0;
[b7d3cc34]154        }
[11e42dc]155#endif
[5ebff60]156
[11e42dc]157        msn_ns_sendmessage(ic, bu, message);
[5ebff60]158        return(0);
[b7d3cc34]159}
160
[5ebff60]161static GList *msn_away_states(struct im_connection *ic)
[b7d3cc34]162{
[5e202b0]163        static GList *l = NULL;
[b7d3cc34]164        int i;
[5ebff60]165
166        if (l == NULL) {
167                for (i = 0; *msn_away_state_list[i].code; i++) {
168                        if (*msn_away_state_list[i].name) {
169                                l = g_list_append(l, (void *) msn_away_state_list[i].name);
170                        }
171                }
172        }
173
[5e202b0]174        return l;
[b7d3cc34]175}
176
[5ebff60]177static void msn_set_away(struct im_connection *ic, char *state, char *message)
[b7d3cc34]178{
[0da65d5]179        struct msn_data *md = ic->proto_data;
[d80822c]180        char *nick, *psm, *idle, *statecode, *body, *buf;
[5ebff60]181
182        if (state == NULL) {
[b051d39]183                md->away_state = msn_away_state_list;
[5ebff60]184        } else if ((md->away_state = msn_away_state_by_name(state)) == NULL) {
[daae10f]185                md->away_state = msn_away_state_list + 1;
[5ebff60]186        }
187
[d80822c]188        statecode = (char *) md->away_state->code;
189        nick = set_getstr(&ic->acc->set, "display_name");
190        psm = message ? message : "";
191        idle = strcmp(statecode, "IDL") ? "false" : "true";
192
193        body = g_markup_printf_escaped(MSN_PUT_USER_BODY,
194                nick, psm, psm, md->uuid, statecode, md->uuid, idle, statecode,
195                MSN_CAP1, MSN_CAP2, MSN_CAP1, MSN_CAP2
196        );
197
198        buf = g_strdup_printf(MSN_PUT_HEADERS, ic->acc->user, ic->acc->user, md->uuid,
199                "/user", "application/user+xml",
200                strlen(body), body);
201        msn_ns_write(ic, -1, "PUT %d %zd\r\n%s", ++md->trId, strlen(buf), buf);
[5ebff60]202
[d80822c]203        g_free(buf);
204        g_free(body);
[b7d3cc34]205}
206
[5ebff60]207static void msn_get_info(struct im_connection *ic, char *who)
[b7d3cc34]208{
209        /* Just make an URL and let the user fetch the info */
[5ebff60]210        imcb_log(ic, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who);
[b7d3cc34]211}
212
[5ebff60]213static void msn_add_buddy(struct im_connection *ic, char *who, char *group)
[b7d3cc34]214{
[5ebff60]215        struct bee_user *bu = bee_user_by_handle(ic->bee, ic, who);
216
217        msn_buddy_list_add(ic, MSN_BUDDY_FL, who, who, group);
218        if (bu && bu->group) {
219                msn_buddy_list_remove(ic, MSN_BUDDY_FL, who, bu->group->name);
220        }
[b7d3cc34]221}
222
[5ebff60]223static void msn_remove_buddy(struct im_connection *ic, char *who, char *group)
[b7d3cc34]224{
[5ebff60]225        msn_buddy_list_remove(ic, MSN_BUDDY_FL, who, NULL);
[b7d3cc34]226}
227
[5ebff60]228static void msn_chat_msg(struct groupchat *c, char *message, int flags)
[b7d3cc34]229{
[11e42dc]230        /* TODO: groupchats*/
[b7d3cc34]231}
232
[5ebff60]233static void msn_chat_invite(struct groupchat *c, char *who, char *message)
[b7d3cc34]234{
[11e42dc]235        /* TODO: groupchats*/
[b7d3cc34]236}
237
[5ebff60]238static void msn_chat_leave(struct groupchat *c)
[b7d3cc34]239{
[11e42dc]240        /* TODO: groupchats*/
[b7d3cc34]241}
242
[5ebff60]243static struct groupchat *msn_chat_with(struct im_connection *ic, char *who)
[b7d3cc34]244{
[11e42dc]245        /* TODO: groupchats*/
[5ebff60]246        struct groupchat *c = imcb_chat_new(ic, who);
[11e42dc]247        return c;
[b7d3cc34]248}
249
[5ebff60]250static void msn_keepalive(struct im_connection *ic)
[b7d3cc34]251{
[5ebff60]252        msn_ns_write(ic, -1, "PNG\r\n");
[b7d3cc34]253}
254
[5ebff60]255static void msn_add_permit(struct im_connection *ic, char *who)
[b7d3cc34]256{
[5ebff60]257        msn_buddy_list_add(ic, MSN_BUDDY_AL, who, who, NULL);
[b7d3cc34]258}
259
[5ebff60]260static void msn_rem_permit(struct im_connection *ic, char *who)
[b7d3cc34]261{
[5ebff60]262        msn_buddy_list_remove(ic, MSN_BUDDY_AL, who, NULL);
[b7d3cc34]263}
264
[5ebff60]265static void msn_add_deny(struct im_connection *ic, char *who)
[b7d3cc34]266{
[5ebff60]267        msn_buddy_list_add(ic, MSN_BUDDY_BL, who, who, NULL);
[b7d3cc34]268}
269
[5ebff60]270static void msn_rem_deny(struct im_connection *ic, char *who)
[b7d3cc34]271{
[5ebff60]272        msn_buddy_list_remove(ic, MSN_BUDDY_BL, who, NULL);
[b7d3cc34]273}
274
[5ebff60]275static int msn_send_typing(struct im_connection *ic, char *who, int typing)
[b7d3cc34]276{
[5ebff60]277        struct bee_user *bu = bee_user_by_handle(ic->bee, ic, who);
278
279        if (!(bu->flags & BEE_USER_ONLINE)) {
[4255320]280                return 0;
[5ebff60]281        } else if (typing & OPT_TYPING) {
282                return(msn_buddy_msg(ic, who, TYPING_NOTIFICATION_MESSAGE, 0));
283        } else {
[4255320]284                return 1;
[5ebff60]285        }
[b7d3cc34]286}
287
[5ebff60]288static char *set_eval_display_name(set_t *set, char *value)
[911f2eb]289{
290        account_t *acc = set->data;
[0da65d5]291        struct im_connection *ic = acc->ic;
[80175a1]292        struct msn_data *md = ic->proto_data;
[5ebff60]293
294        if (md->flags & MSN_EMAIL_UNVERIFIED) {
295                imcb_log(ic, "Warning: Your e-mail address is unverified. MSN doesn't allow "
296                         "changing your display name until your e-mail address is verified.");
297        }
298
299        if (md->flags & MSN_GOT_PROFILE_DN) {
300                msn_soap_profile_set_dn(ic, value);
301        } else {
302                msn_soap_addressbook_set_display_name(ic, value);
303        }
304
305        return msn_ns_set_display_name(ic, value) ? value : NULL;
[911f2eb]306}
307
[5ebff60]308static void msn_buddy_data_add(bee_user_t *bu)
[7f34ce2]309{
[ca7de3a]310        struct msn_data *md = bu->ic->proto_data;
[208db4b]311        struct msn_buddy_data *bd;
312        char *handle;
[5ebff60]313
314        bd = bu->data = g_new0(struct msn_buddy_data, 1);
315        g_tree_insert(md->domaintree, bu->handle, bu);
316
317        for (handle = bu->handle; g_ascii_isdigit(*handle); handle++) {
318                ;
319        }
320        if (*handle == ':') {
[208db4b]321                /* Pass a nick hint so hopefully the stupid numeric prefix
322                   won't show up to the user.  */
[5ebff60]323                char *s = strchr(++handle, '@');
324                if (s) {
325                        handle = g_strndup(handle, s - handle);
326                        imcb_buddy_nick_hint(bu->ic, bu->handle, handle);
327                        g_free(handle);
[208db4b]328                }
[5ebff60]329
[208db4b]330                bd->flags |= MSN_BUDDY_FED;
331        }
[7f34ce2]332}
333
[5ebff60]334static void msn_buddy_data_free(bee_user_t *bu)
[7f34ce2]335{
[ca7de3a]336        struct msn_data *md = bu->ic->proto_data;
[c1d40e7]337        struct msn_buddy_data *bd = bu->data;
[5ebff60]338
339        g_free(bd->cid);
340        g_free(bd);
341
342        g_tree_remove(md->domaintree, bu->handle);
[7f34ce2]343}
344
[5ebff60]345GList *msn_buddy_action_list(bee_user_t *bu)
[9c84617]346{
347        static GList *ret = NULL;
[5ebff60]348
349        if (ret == NULL) {
[9c84617]350                static const struct buddy_action ba[2] = {
351                        { "NUDGE", "Draw attention" },
352                };
[5ebff60]353
354                ret = g_list_prepend(ret, (void *) ba + 0);
[9c84617]355        }
[5ebff60]356
[9c84617]357        return ret;
358}
359
[5ebff60]360void *msn_buddy_action(struct bee_user *bu, const char *action, char * const args[], void *data)
[9c84617]361{
[5ebff60]362        if (g_strcasecmp(action, "NUDGE") == 0) {
363                msn_buddy_msg(bu->ic, bu->handle, NUDGE_MESSAGE, 0);
364        }
365
[9c84617]366        return NULL;
367}
368
[0da65d5]369void msn_initmodule()
[b7d3cc34]370{
[7b23afd]371        struct prpl *ret = g_new0(struct prpl, 1);
[5ebff60]372
[7b23afd]373        ret->name = "msn";
[76c89dc7]374        ret->mms = 1409;         /* this guess taken from libotr UPGRADING file */
[b7d3cc34]375        ret->login = msn_login;
[0da65d5]376        ret->init = msn_init;
377        ret->logout = msn_logout;
[f6c963b]378        ret->buddy_msg = msn_buddy_msg;
[b7d3cc34]379        ret->away_states = msn_away_states;
380        ret->set_away = msn_set_away;
381        ret->get_info = msn_get_info;
382        ret->add_buddy = msn_add_buddy;
383        ret->remove_buddy = msn_remove_buddy;
[f6c963b]384        ret->chat_msg = msn_chat_msg;
[b7d3cc34]385        ret->chat_invite = msn_chat_invite;
386        ret->chat_leave = msn_chat_leave;
[0da65d5]387        ret->chat_with = msn_chat_with;
[b7d3cc34]388        ret->keepalive = msn_keepalive;
389        ret->add_permit = msn_add_permit;
390        ret->rem_permit = msn_rem_permit;
391        ret->add_deny = msn_add_deny;
392        ret->rem_deny = msn_rem_deny;
393        ret->send_typing = msn_send_typing;
[5b52a48]394        ret->handle_cmp = g_strcasecmp;
[7f34ce2]395        ret->buddy_data_add = msn_buddy_data_add;
396        ret->buddy_data_free = msn_buddy_data_free;
[9c84617]397        ret->buddy_action_list = msn_buddy_action_list;
398        ret->buddy_action = msn_buddy_action;
[5ebff60]399
[7b23afd]400        register_protocol(ret);
[b7d3cc34]401}
Note: See TracBrowser for help on using the repository browser.