source: protocols/msn/ns.c @ 3c28bd4

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

msn: check for dead connections in msn_ns_callback

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