source: protocols/msn/ns.c @ 27a057c

Last change on this file since 27a057c was 27a057c, checked in by dequis <dx@…>, at 2015-05-31T02:40:05Z

msn: fix leak when reconnecting ssl

  • Property mode set to 100644
File size: 18.3 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/* MSN module - Notification server callbacks                           */
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;
22  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
23  Fifth Floor, Boston, MA  02110-1301  USA
24*/
25
26#include <ctype.h>
27#include <sys/utsname.h>
28#include "nogaim.h"
29#include "msn.h"
30#include "md5.h"
31#include "sha1.h"
32#include "soap.h"
33#include "xmltree.h"
34#include "ssl_client.h"
35
36static gboolean msn_ns_connected(gpointer data, int source, void *scd, b_input_condition cond);
37static gboolean msn_ns_callback(gpointer data, gint source, b_input_condition cond);
38
39static void msn_ns_send_adl_start(struct im_connection *ic);
40static void msn_ns_send_adl(struct im_connection *ic);
41static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd);
42static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action);
43static void msn_ns_nfy(struct msn_data *md, char *who, char **parts, char *action, gboolean is_put);
44
45int msn_ns_write(struct im_connection *ic, const char *fmt, ...)
46{
47        struct msn_data *md = ic->proto_data;
48        va_list params;
49        char *out;
50        size_t len;
51        int st;
52
53        va_start(params, fmt);
54        out = g_strdup_vprintf(fmt, params);
55        va_end(params);
56
57        if (getenv("BITLBEE_DEBUG")) {
58                fprintf(stderr, "\n\x1b[91m>>>[NS] %s\n\x1b[97m", out);
59        }
60
61        len = strlen(out);
62
63        if (md->is_http) {
64                st = len;
65                msn_gw_write(md->gw, out, len);
66        } else {
67                st = ssl_write(md->ssl, out, len);
68        }
69
70        g_free(out);
71        if (st != len) {
72                imcb_error(ic, "Short write() to main server");
73                imc_logout(ic, TRUE);
74                return 0;
75        }
76
77        return 1;
78}
79
80int msn_ns_write_cmd(struct im_connection *ic, const char *cmd, const char *params, const char *payload)
81{
82        struct msn_data *md = ic->proto_data;
83        int trid = ++md->trId;
84        const char *headers = "\r\n"; /* not needed yet */
85        size_t len = strlen(headers) + strlen(payload);
86
87        if (params && *params) {
88                return msn_ns_write(ic, "%s %d %s %zd\r\n%s%s", cmd, trid, params, len, headers, payload);
89        } else {
90                return msn_ns_write(ic, "%s %d %zd\r\n%s%s", cmd, trid, len, headers, payload);
91        }
92}
93
94gboolean msn_ns_connect(struct im_connection *ic, const char *host, int port)
95{
96        struct msn_data *md = ic->proto_data;
97
98        if (md->is_http) {
99                md->gw = msn_gw_new(ic);
100                md->gw->callback = msn_ns_callback;
101                msn_ns_connected(md, 0, NULL, B_EV_IO_READ);
102        } else {
103                if (md->fd >= 0) {
104                        closesocket(md->fd);
105                }
106
107                if (md->ssl) {
108                        ssl_disconnect(md->ssl);
109                        b_event_remove(md->inpa);
110                }
111
112                md->ssl = ssl_connect((char *) host, port, TRUE, msn_ns_connected, md);
113                md->fd = md->ssl ? ssl_getfd(md->ssl) : -1;
114                if (md->fd < 0) {
115                        imcb_error(ic, "Could not connect to server");
116                        imc_logout(ic, TRUE);
117                        return FALSE;
118                }
119        }
120
121        return TRUE;
122}
123
124static gboolean msn_ns_connected(gpointer data, int source, void *scd, b_input_condition cond)
125{
126        struct msn_data *md = data;
127        struct im_connection *ic = md->ic;
128
129        if (!scd && !md->is_http) {
130                md->ssl = NULL;
131                imcb_error(ic, "Could not connect to server");
132                imc_logout(ic, TRUE);
133                return FALSE;
134        }
135
136        g_free(md->rxq);
137        md->rxlen = 0;
138        md->rxq = g_new0(char, 1);
139
140        if (md->uuid == NULL) {
141                struct utsname name;
142                sha1_state_t sha[1];
143
144                /* UUID == SHA1("BitlBee" + my hostname + MSN username) */
145                sha1_init(sha);
146                sha1_append(sha, (void *) "BitlBee", 7);
147                if (uname(&name) == 0) {
148                        sha1_append(sha, (void *) name.nodename, strlen(name.nodename));
149                }
150                sha1_append(sha, (void *) ic->acc->user, strlen(ic->acc->user));
151                md->uuid = sha1_random_uuid(sha);
152                memcpy(md->uuid, "b171be3e", 8);   /* :-P */
153        }
154
155        if (msn_ns_write_cmd(ic, "CNT", "CON", "<connect><ver>2</ver><agent><os>winnt</os><osVer>5.2</osVer><proc>x86</proc><lcid>en-us</lcid></agent></connect>")) {
156                if (!md->is_http) {
157                        md->inpa = b_input_add(md->fd, B_EV_IO_READ, msn_ns_callback, ic);
158                }
159                imcb_log(ic, "Connected to server, waiting for reply");
160        }
161
162        return FALSE;
163}
164
165void msn_ns_close(struct msn_data *md)
166{
167        if (md->gw) {
168                msn_gw_free(md->gw);
169        }
170
171        if (md->ssl) {
172                ssl_disconnect(md->ssl);
173                b_event_remove(md->inpa);
174        }
175
176        md->ssl = NULL;
177        md->fd = md->inpa = -1;
178
179        g_free(md->rxq);
180        g_free(md->cmd_text);
181
182        md->rxlen = 0;
183        md->rxq = NULL;
184        md->cmd_text = NULL;
185}
186
187static gboolean msn_ns_callback(gpointer data, gint source, b_input_condition cond)
188{
189        struct im_connection *ic = data;
190        struct msn_data *md;
191        char *bytes;
192        int st;
193
194        if (g_slist_find(msn_connections, ic) == NULL) {
195                return FALSE;
196        }
197
198        md = ic->proto_data;
199
200        if (md->is_http) {
201                st = msn_gw_read(md->gw, &bytes);
202        } else {
203                bytes = g_malloc(1024);
204                st = ssl_read(md->ssl, bytes, 1024);
205        }
206
207        if (st == 0 || (st < 0 && (md->is_http || !ssl_sockerr_again(md->ssl)))) {
208                imcb_error(ic, "Error while reading from server");
209                imc_logout(ic, TRUE);
210                g_free(bytes);
211                return FALSE;
212        }
213
214        msn_queue_feed(md, bytes, st);
215
216        g_free(bytes);
217
218        if (!md->is_http && ssl_pending(md->ssl)) {
219                return msn_ns_callback(data, source, cond);
220        }
221
222        return msn_handler(md);
223}
224
225int msn_ns_command(struct msn_data *md, char **cmd, int num_parts, char *msg, int msglen)
226{
227        struct im_connection *ic = md->ic;
228        struct xt_node *xml;
229
230        if (strcmp(cmd[0], "XFR") == 0) {
231                struct xt_node *target;
232                char *server, *p;
233                int port, st;
234
235                if (!(xml = xt_from_string(msg + 2, msglen - 2)) ||
236                    !(target = xt_find_node(xml->children, "target")) ||
237                    !(server = target->text) ||
238                    !(p = strchr(server, ':'))) {
239                        return 1;
240                }
241               
242                server = target->text;
243                *p = 0;
244                port = atoi(p + 1);
245
246                b_event_remove(md->inpa);
247                md->inpa = -1;
248
249                imcb_log(ic, "Transferring to other server");
250
251                st = msn_ns_connect(ic, server, port);
252
253                xt_free_node(xml);
254
255                return st;
256
257        } else if (strcmp(cmd[0], "CNT") == 0) {
258                msn_soap_passport_sso_request(ic);
259
260                /* continues in msn_auth_got_passport_token */
261
262        } else if (strcmp(cmd[0], "ATH") == 0) {
263                char *payload;
264
265                if (md->flags & MSN_DONE_BND) {
266                        return 1;
267                }
268
269                md->flags |= MSN_DONE_BND;
270
271                // BND
272                payload = g_markup_printf_escaped(
273                        "<msgr><ver>1</ver><client><name>Skype</name><ver>2/4.3.0.37/174</ver></client>"
274                        "<epid>%s</epid></msgr>\r\n",
275                        md->uuid);
276
277                msn_ns_write_cmd(ic, "BND", "CON\\MSGR", payload);
278
279                g_free(payload);
280
281        } else if (strcmp(cmd[0], "BND") == 0) {
282                struct xt_node *node;
283                char *nonce, *resp, *payload;
284
285                if (!(xml = xt_from_string(msg + 2, msglen - 2)) ||
286                    !(node = xt_find_node(xml->children, "nonce")) ||
287                    !(nonce = node->text)) {
288                        return 1;
289                }
290
291                resp = msn_p11_challenge(nonce);
292
293                // PUT MSGR\CHALLENGE
294                payload = g_markup_printf_escaped(
295                        "<challenge><appId>%s</appId><response>%s</response></challenge>",
296                        MSNP11_PROD_ID, resp);
297
298                msn_ns_write_cmd(ic, "PUT", "MSGR\\CHALLENGE", payload);
299
300                imcb_log(ic, "Authenticated, getting buddy list");
301                msn_soap_memlist_request(ic);
302
303                xt_free_node(xml);
304                g_free(payload);
305                g_free(resp);
306
307        } else if (strcmp(cmd[0], "PUT") == 0) {
308                /* We could keep track TrIDs... or we could guess what this PUT means */
309                if ((md->flags & MSN_DONE_BND) && !(md->flags & MSN_DONE_ADL)) {
310                        msn_ns_send_adl(ic);
311                        return msn_ns_finish_login(ic);
312                }
313        } else if (strcmp(cmd[0], "OUT") == 0) {
314                imcb_error(ic, "Session terminated by remote server (%s)", cmd[1] ? cmd[1] : "reason unknown");
315                imc_logout(ic, TRUE);
316                return(0);
317        } else if (strcmp(cmd[0], "QNG") == 0) {
318                ic->flags |= OPT_PONGED;
319        } else if (g_ascii_isdigit(cmd[0][0])) {
320                int num = atoi(cmd[0]);
321                const struct msn_status_code *err = msn_status_by_number(num);
322
323                imcb_error(ic, "Error reported by MSN server: %s", err->text);
324
325                if (err->flags & STATUS_FATAL) {
326                        imc_logout(ic, TRUE);
327                        return(0);
328                }
329        } else if ((strcmp(cmd[0], "SDG") == 0) || (strcmp(cmd[0], "NFY") == 0)) {
330                msn_ns_structured_message(md, msg, msglen, cmd);
331        } else {
332                imcb_error(ic, "Received unknown command from main server: %s", cmd[0]);
333        }
334
335        return(1);
336}
337
338int msn_ns_message(struct msn_data *md, char *msg, int msglen, char **cmd, int num_parts)
339{
340        struct im_connection *ic = md->ic;
341        char *body;
342        int blen = 0;
343
344        if ((body = strstr(msg, "\r\n\r\n"))) {
345                body += 4;
346                blen = msglen - (body - msg);
347        }
348
349        if (strcmp(cmd[0], "MSG") == 0) {
350                if (g_strcasecmp(cmd[1], "Hotmail") == 0) {
351                        char *ct = get_rfc822_header(msg, "Content-Type:", msglen);
352
353                        if (!ct) {
354                                return(1);
355                        }
356
357                        if (g_strncasecmp(ct, "application/x-msmsgssystemmessage", 33) == 0) {
358                                char *mtype;
359                                char *arg1;
360
361                                if (!body) {
362                                        return(1);
363                                }
364
365                                mtype = get_rfc822_header(body, "Type:", blen);
366                                arg1 = get_rfc822_header(body, "Arg1:", blen);
367
368                                if (mtype && strcmp(mtype, "1") == 0) {
369                                        if (arg1) {
370                                                imcb_log(ic, "The server is going down for maintenance in %s minutes.",
371                                                         arg1);
372                                        }
373                                }
374
375                                g_free(arg1);
376                                g_free(mtype);
377                        } else if (g_strncasecmp(ct, "text/x-msmsgsprofile", 20) == 0) {
378                                /* We don't care about this profile for now... */
379                        } else if (g_strncasecmp(ct, "text/x-msmsgsinitialemailnotification", 37) == 0) {
380                                if (set_getbool(&ic->acc->set, "mail_notifications")) {
381                                        char *inbox = get_rfc822_header(body, "Inbox-Unread:", blen);
382                                        char *folders = get_rfc822_header(body, "Folders-Unread:", blen);
383
384                                        if (inbox && folders) {
385                                                imcb_notify_email(ic,
386                                                        "INBOX contains %s new messages, plus %s messages in other folders.", inbox,
387                                                        folders);
388                                        }
389
390                                        g_free(inbox);
391                                        g_free(folders);
392                                }
393                        } else if (g_strncasecmp(ct, "text/x-msmsgsemailnotification", 30) == 0) {
394                                if (set_getbool(&ic->acc->set, "mail_notifications")) {
395                                        char *from = get_rfc822_header(body, "From-Addr:", blen);
396                                        char *fromname = get_rfc822_header(body, "From:", blen);
397
398                                        if (from && fromname) {
399                                                imcb_notify_email(ic, "Received an e-mail message from %s <%s>.", fromname, from);
400                                        }
401
402                                        g_free(from);
403                                        g_free(fromname);
404                                }
405                        } else if (g_strncasecmp(ct, "text/x-msmsgsactivemailnotification", 35) == 0) {
406                                /* Notification that a message has been read... Ignore it */
407                        }
408
409                        g_free(ct);
410                }
411        } else if (strcmp(cmd[0], "ADL") == 0) {
412                struct xt_node *adl, *d, *c;
413
414                if (!(adl = xt_from_string(msg, msglen))) {
415                        return 1;
416                }
417
418                for (d = adl->children; d; d = d->next) {
419                        char *dn;
420                        if (strcmp(d->name, "d") != 0 ||
421                            (dn = xt_find_attr(d, "n")) == NULL) {
422                                continue;
423                        }
424                        for (c = d->children; c; c = c->next) {
425                                bee_user_t *bu;
426                                struct msn_buddy_data *bd;
427                                char *cn, *handle, *f, *l;
428                                int flags;
429
430                                if (strcmp(c->name, "c") != 0 ||
431                                    (l = xt_find_attr(c, "l")) == NULL ||
432                                    (cn = xt_find_attr(c, "n")) == NULL) {
433                                        continue;
434                                }
435
436                                /* FIXME: Use "t" here, guess I should just add it
437                                   as a prefix like elsewhere in the protocol. */
438                                handle = g_strdup_printf("%s@%s", cn, dn);
439                                if (!((bu = bee_user_by_handle(ic->bee, ic, handle)) ||
440                                      (bu = bee_user_new(ic->bee, ic, handle, 0)))) {
441                                        g_free(handle);
442                                        continue;
443                                }
444                                g_free(handle);
445                                bd = bu->data;
446
447                                if ((f = xt_find_attr(c, "f"))) {
448                                        http_decode(f);
449                                        imcb_rename_buddy(ic, bu->handle, f);
450                                }
451
452                                flags = atoi(l) & 15;
453                                if (bd->flags != flags) {
454                                        bd->flags = flags;
455                                        msn_buddy_ask(bu);
456                                }
457                        }
458                }
459        }
460
461        return 1;
462}
463
464static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd)
465{
466        char **parts = NULL;
467        char *semicolon = NULL;
468        char *action = NULL;
469        char *from = NULL;
470        char *who = NULL;
471
472        parts = g_strsplit(msg, "\r\n\r\n", 4);
473
474        if (!(from = get_rfc822_header(parts[0], "From", 0))) {
475                goto cleanup;
476        }
477
478        /* either the semicolon or the end of the string */
479        semicolon = strchr(from, ';') ? : (from + strlen(from));
480
481        who = g_strndup(from + 2, semicolon - from - 2);
482
483        if ((strcmp(cmd[0], "SDG") == 0) && (action = get_rfc822_header(parts[2], "Message-Type", 0))) {
484                msn_ns_sdg(md, who, parts, action);
485
486        } else if ((strcmp(cmd[0], "NFY") == 0) && (action = get_rfc822_header(parts[2], "Uri", 0))) {
487                gboolean is_put = (strcmp(cmd[2], "MSGR\\PUT") == 0);
488                msn_ns_nfy(md, who, parts, action, is_put);
489        }
490
491cleanup:
492        g_strfreev(parts);
493        g_free(action);
494        g_free(from);
495        g_free(who);
496}
497
498static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action)
499{
500        struct im_connection *ic = md->ic;
501
502        if (strcmp(action, "Control/Typing") == 0) {
503                imcb_buddy_typing(ic, who, OPT_TYPING);
504        } else if (strcmp(action, "Text") == 0) {
505                imcb_buddy_msg(ic, who, parts[3], 0, 0);
506        }
507}
508
509static void msn_ns_nfy(struct msn_data *md, char *who, char **parts, char *action, gboolean is_put)
510{
511        struct im_connection *ic = md->ic;
512        struct xt_node *body = NULL;
513        struct xt_node *s = NULL;
514        const char *state = NULL;
515        char *nick = NULL;
516        char *psm = NULL;
517        int flags = OPT_LOGGED_IN;
518
519        if (strcmp(action, "/user") != 0) {
520                return;
521        }
522
523        if (!(body = xt_from_string(parts[3], 0))) {
524                goto cleanup;
525        }
526
527        s = body->children;
528        while ((s = xt_find_node(s, "s"))) {
529                struct xt_node *s2;
530                char *n = xt_find_attr(s, "n");  /* service name: IM, PE, etc */
531
532                if (strcmp(n, "IM") == 0) {
533                        /* IM has basic presence information */
534                        if (!is_put) {
535                                /* NFY DEL with a <s> usually means log out from the last endpoint */
536                                flags &= ~OPT_LOGGED_IN;
537                                break;
538                        }
539
540                        s2 = xt_find_node(s->children, "Status");
541                        if (s2 && s2->text_len) {
542                                const struct msn_away_state *msn_state = msn_away_state_by_code(s2->text);
543                                state = msn_state->name;
544                                if (msn_state != msn_away_state_list) {
545                                        flags |= OPT_AWAY;
546                                }
547                        }
548                } else if (strcmp(n, "PE") == 0) {
549                        if ((s2 = xt_find_node(s->children, "PSM")) && s2->text_len) {
550                                psm = s2->text;
551                        }
552                        if ((s2 = xt_find_node(s->children, "FriendlyName")) && s2->text_len) {
553                                nick = s2->text;
554                        }
555                }
556                s = s->next;
557        }
558
559        imcb_buddy_status(ic, who, flags, state, psm);
560
561        if (nick) {
562                imcb_rename_buddy(ic, who, nick);
563        }
564
565cleanup:
566        xt_free_node(body);
567}
568
569void msn_auth_got_passport_token(struct im_connection *ic, const char *token, const char *error)
570{
571        struct msn_data *md;
572        char *payload = NULL;
573
574        /* Dead connection? */
575        if (g_slist_find(msn_connections, ic) == NULL) {
576                return;
577        }
578
579        md = ic->proto_data;
580
581        if (!token) {
582                imcb_error(ic, "Error during Passport authentication: %s", error);
583                imc_logout(ic, TRUE);
584                return;
585        }
586
587        // ATH
588        payload = g_markup_printf_escaped(
589                "<user><ssl-compact-ticket>%s</ssl-compact-ticket>"
590                "<ssl-site-name>chatservice.live.com</ssl-site-name></user>",
591                md->tokens[0]);
592
593        msn_ns_write_cmd(ic, "ATH", "CON\\USER", payload);
594
595        g_free(payload);
596
597        /* continues in msn_ns_command */
598}
599
600void msn_auth_got_contact_list(struct im_connection *ic)
601{
602        /* Dead connection? */
603        if (g_slist_find(msn_connections, ic) == NULL) {
604                return;
605        }
606
607        msn_ns_send_adl_start(ic);
608        msn_ns_finish_login(ic);
609}
610
611static gboolean msn_ns_send_adl_1(gpointer key, gpointer value, gpointer data)
612{
613        struct xt_node *adl = data, *d, *c, *s;
614        struct bee_user *bu = value;
615        struct msn_buddy_data *bd = bu->data;
616        struct msn_data *md = bu->ic->proto_data;
617        char handle[strlen(bu->handle) + 1];
618        char *domain;
619        char l[4];
620
621        if ((bd->flags & (MSN_BUDDY_FL | MSN_BUDDY_AL)) == 0 || (bd->flags & MSN_BUDDY_ADL_SYNCED)) {
622                return FALSE;
623        }
624
625        strcpy(handle, bu->handle);
626        if ((domain = strchr(handle, '@')) == NULL) {    /* WTF */
627                return FALSE;
628        }
629        *domain = '\0';
630        domain++;
631
632        if ((d = adl->children) == NULL ||
633            g_strcasecmp(xt_find_attr(d, "n"), domain) != 0) {
634                d = xt_new_node("d", NULL, NULL);
635                xt_add_attr(d, "n", domain);
636                xt_insert_child(adl, d);
637        }
638
639        g_snprintf(l, sizeof(l), "%d", bd->flags & (MSN_BUDDY_FL | MSN_BUDDY_AL));
640        c = xt_new_node("c", NULL, NULL);
641        xt_add_attr(c, "n", handle);
642        xt_add_attr(c, "t", "1");   /* FIXME: Network type, i.e. 32 for Y!MSG */
643        s = xt_new_node("s", NULL, NULL);
644        xt_add_attr(s, "n", "IM");
645        xt_add_attr(s, "l", l);
646        xt_insert_child(c, s);
647        xt_insert_child(d, c);
648
649        /* Do this in batches of 100. */
650        bd->flags |= MSN_BUDDY_ADL_SYNCED;
651        return (--md->adl_todo % 140) == 0;
652}
653
654static void msn_ns_send_adl(struct im_connection *ic)
655{
656        struct xt_node *adl;
657        struct msn_data *md = ic->proto_data;
658        char *adls;
659
660        adl = xt_new_node("ml", NULL, NULL);
661        xt_add_attr(adl, "l", "1");
662        g_tree_foreach(md->domaintree, msn_ns_send_adl_1, adl);
663        if (adl->children == NULL) {
664                /* This tells the caller that we're done now. */
665                md->adl_todo = -1;
666                xt_free_node(adl);
667                return;
668        }
669
670        adls = xt_to_string(adl);
671        xt_free_node(adl);
672        msn_ns_write_cmd(ic, "PUT", "MSGR\\CONTACTS", adls);
673        g_free(adls);
674}
675
676static void msn_ns_send_adl_start(struct im_connection *ic)
677{
678        struct msn_data *md;
679        GSList *l;
680
681        /* Dead connection? */
682        if (g_slist_find(msn_connections, ic) == NULL) {
683                return;
684        }
685
686        md = ic->proto_data;
687        md->adl_todo = 0;
688        for (l = ic->bee->users; l; l = l->next) {
689                bee_user_t *bu = l->data;
690                struct msn_buddy_data *bd = bu->data;
691
692                if (bu->ic != ic || (bd->flags & (MSN_BUDDY_FL | MSN_BUDDY_AL)) == 0) {
693                        continue;
694                }
695
696                bd->flags &= ~MSN_BUDDY_ADL_SYNCED;
697                md->adl_todo++;
698        }
699
700        msn_ns_send_adl(ic);
701}
702
703int msn_ns_finish_login(struct im_connection *ic)
704{
705        struct msn_data *md = ic->proto_data;
706
707        if (ic->flags & OPT_LOGGED_IN) {
708                return 1;
709        }
710
711        if (md->adl_todo < 0) {
712                md->flags |= MSN_DONE_ADL;
713        }
714
715        if ((md->flags & MSN_DONE_ADL) && (md->flags & MSN_GOT_PROFILE)) {
716                imcb_connected(ic);
717        }
718
719        return 1;
720}
721
722static int msn_ns_send_sdg(struct im_connection *ic, bee_user_t *bu, const char *message_type, const char *text)
723{
724        struct msn_data *md = ic->proto_data;
725        int retval = 0;
726        char *buf;
727
728        buf = g_strdup_printf(MSN_MESSAGE_HEADERS, bu->handle, ic->acc->user, md->uuid, message_type, strlen(text), text);
729        retval = msn_ns_write_cmd(ic, "SDG", "MSGR", buf);
730        g_free(buf);
731        return retval;
732}
733
734int msn_ns_send_typing(struct im_connection *ic, bee_user_t *bu)
735{
736        return msn_ns_send_sdg(ic, bu, "Control/Typing", "");
737}
738
739int msn_ns_send_message(struct im_connection *ic, bee_user_t *bu, const char *text)
740{
741        return msn_ns_send_sdg(ic, bu, "Text", text);
742}
743
Note: See TracBrowser for help on using the repository browser.