source: protocols/msn/ns.c @ 95fdf22

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

msn: remove some MSNP21 commands

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