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

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

msn: ...don't try to write ATH right after calling imc_logout()

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