source: protocols/msn/ns.c @ 85dabae

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

msn: add msn_ns_write_cmd to write MSNP24-formatted commands

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