source: protocols/msn/ns.c @ 4452e69

Last change on this file since 4452e69 was 4452e69, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-08-14T13:06:11Z

Allow changing the display_name, now permanently!

  • 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-2010 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., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#include <ctype.h>
27#include "nogaim.h"
28#include "msn.h"
29#include "md5.h"
30#include "soap.h"
31#include "xmltree.h"
32
33static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond );
34static int msn_ns_command( gpointer data, char **cmd, int num_parts );
35static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );
36
37static void msn_ns_send_adl( struct im_connection *ic );
38
39gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond )
40{
41        struct im_connection *ic = data;
42        struct msn_data *md;
43        char s[1024];
44       
45        if( !g_slist_find( msn_connections, ic ) )
46                return FALSE;
47       
48        if( source == -1 )
49        {
50                imcb_error( ic, "Could not connect to server" );
51                imc_logout( ic, TRUE );
52                return FALSE;
53        }
54       
55        md = ic->proto_data;
56       
57        if( !md->handler )
58        {
59                md->handler = g_new0( struct msn_handler_data, 1 );
60                md->handler->data = ic;
61                md->handler->exec_command = msn_ns_command;
62                md->handler->exec_message = msn_ns_message;
63        }
64        else
65        {
66                if( md->handler->rxq )
67                        g_free( md->handler->rxq );
68               
69                md->handler->rxlen = 0;
70        }
71       
72        md->handler->fd = md->fd;
73        md->handler->rxq = g_new0( char, 1 );
74       
75        g_snprintf( s, sizeof( s ), "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER );
76        if( msn_write( ic, s, strlen( s ) ) )
77        {
78                ic->inpa = b_input_add( md->fd, B_EV_IO_READ, msn_ns_callback, ic );
79                imcb_log( ic, "Connected to server, waiting for reply" );
80        }
81       
82        return FALSE;
83}
84
85static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond )
86{
87        struct im_connection *ic = data;
88        struct msn_data *md = ic->proto_data;
89       
90        if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */
91        {
92                imcb_error( ic, "Error while reading from server" );
93                imc_logout( ic, TRUE );
94               
95                return FALSE;
96        }
97        else
98                return TRUE;
99}
100
101static int msn_ns_command( gpointer data, char **cmd, int num_parts )
102{
103        struct im_connection *ic = data;
104        struct msn_data *md = ic->proto_data;
105        char buf[1024];
106       
107        if( num_parts == 0 )
108        {
109                /* Hrrm... Empty command...? Ignore? */
110                return( 1 );
111        }
112       
113        if( strcmp( cmd[0], "VER" ) == 0 )
114        {
115                if( cmd[2] && strncmp( cmd[2], MSNP_VER, 5 ) != 0 )
116                {
117                        imcb_error( ic, "Unsupported protocol" );
118                        imc_logout( ic, FALSE );
119                        return( 0 );
120                }
121               
122                g_snprintf( buf, sizeof( buf ), "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n",
123                                                ++md->trId, ic->acc->user );
124                return( msn_write( ic, buf, strlen( buf ) ) );
125        }
126        else if( strcmp( cmd[0], "CVR" ) == 0 )
127        {
128                /* We don't give a damn about the information we just received */
129                g_snprintf( buf, sizeof( buf ), "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user );
130                return( msn_write( ic, buf, strlen( buf ) ) );
131        }
132        else if( strcmp( cmd[0], "XFR" ) == 0 )
133        {
134                char *server;
135                int port;
136               
137                if( num_parts >= 6 && strcmp( cmd[2], "NS" ) == 0 )
138                {
139                        b_event_remove( ic->inpa );
140                        ic->inpa = 0;
141                        closesocket( md->fd );
142                       
143                        server = strchr( cmd[3], ':' );
144                        if( !server )
145                        {
146                                imcb_error( ic, "Syntax error" );
147                                imc_logout( ic, TRUE );
148                                return( 0 );
149                        }
150                        *server = 0;
151                        port = atoi( server + 1 );
152                        server = cmd[3];
153                       
154                        imcb_log( ic, "Transferring to other server" );
155                       
156                        md->fd = proxy_connect( server, port, msn_ns_connected, ic );
157                }
158                else if( num_parts >= 6 && strcmp( cmd[2], "SB" ) == 0 )
159                {
160                        struct msn_switchboard *sb;
161                       
162                        server = strchr( cmd[3], ':' );
163                        if( !server )
164                        {
165                                imcb_error( ic, "Syntax error" );
166                                imc_logout( ic, TRUE );
167                                return( 0 );
168                        }
169                        *server = 0;
170                        port = atoi( server + 1 );
171                        server = cmd[3];
172                       
173                        if( strcmp( cmd[4], "CKI" ) != 0 )
174                        {
175                                imcb_error( ic, "Unknown authentication method for switchboard" );
176                                imc_logout( ic, TRUE );
177                                return( 0 );
178                        }
179                       
180                        debug( "Connecting to a new switchboard with key %s", cmd[5] );
181
182                        if( ( sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ) ) == NULL )
183                        {
184                                /* Although this isn't strictly fatal for the NS connection, it's
185                                   definitely something serious (we ran out of file descriptors?). */
186                                imcb_error( ic, "Could not create new switchboard" );
187                                imc_logout( ic, TRUE );
188                                return( 0 );
189                        }
190                       
191                        if( md->msgq )
192                        {
193                                struct msn_message *m = md->msgq->data;
194                                GSList *l;
195                               
196                                sb->who = g_strdup( m->who );
197                               
198                                /* Move all the messages to the first user in the message
199                                   queue to the switchboard message queue. */
200                                l = md->msgq;
201                                while( l )
202                                {
203                                        m = l->data;
204                                        l = l->next;
205                                        if( strcmp( m->who, sb->who ) == 0 )
206                                        {
207                                                sb->msgq = g_slist_append( sb->msgq, m );
208                                                md->msgq = g_slist_remove( md->msgq, m );
209                                        }
210                                }
211                        }
212                }
213                else
214                {
215                        imcb_error( ic, "Syntax error" );
216                        imc_logout( ic, TRUE );
217                        return( 0 );
218                }
219        }
220        else if( strcmp( cmd[0], "USR" ) == 0 )
221        {
222                if( num_parts >= 6 && strcmp( cmd[2], "SSO" ) == 0 &&
223                    strcmp( cmd[3], "S" ) == 0 )
224                {
225                        msn_soap_passport_sso_request( ic, cmd[4], cmd[5] );
226                }
227                else if( strcmp( cmd[2], "OK" ) == 0 )
228                {
229                        imcb_log( ic, "Authenticated, getting buddy list" );
230                        msn_soap_memlist_request( ic );
231                }
232                else
233                {
234                        imcb_error( ic, "Unknown authentication type" );
235                        imc_logout( ic, FALSE );
236                        return( 0 );
237                }
238        }
239        else if( strcmp( cmd[0], "MSG" ) == 0 )
240        {
241                if( num_parts < 4 )
242                {
243                        imcb_error( ic, "Syntax error" );
244                        imc_logout( ic, TRUE );
245                        return( 0 );
246                }
247               
248                md->handler->msglen = atoi( cmd[3] );
249               
250                if( md->handler->msglen <= 0 )
251                {
252                        imcb_error( ic, "Syntax error" );
253                        imc_logout( ic, TRUE );
254                        return( 0 );
255                }
256        }
257        else if( strcmp( cmd[0], "BLP" ) == 0 )
258        {
259                msn_ns_send_adl( ic );
260        }
261        else if( strcmp( cmd[0], "ADL" ) == 0 )
262        {
263                if( num_parts >= 3 && strcmp( cmd[2], "OK" ) == 0 )
264                {
265                        char buf[1024];
266                        char *fn_raw = set_getstr( &ic->acc->set, "display_name" );
267                        char *fn;
268                       
269                        if( fn_raw == NULL )
270                                fn_raw = ic->acc->user;
271                        fn = g_malloc( strlen( fn_raw ) * 3 + 1 );
272                        strcpy( fn, fn_raw );
273                        http_encode( fn );
274                       
275                        g_snprintf( buf, sizeof( buf ), "PRP %d MFN %s\r\n",
276                                    ++md->trId, fn );
277                        g_free( fn );
278                       
279                        msn_write( ic, buf, strlen( buf ) );
280                }
281        }
282        else if( strcmp( cmd[0], "PRP" ) == 0 )
283        {
284                imcb_connected( ic );
285        }
286        else if( strcmp( cmd[0], "CHL" ) == 0 )
287        {
288                char *resp;
289               
290                if( num_parts < 3 )
291                {
292                        imcb_error( ic, "Syntax error" );
293                        imc_logout( ic, TRUE );
294                        return( 0 );
295                }
296               
297                resp = msn_p11_challenge( cmd[2] );
298                g_snprintf( buf, sizeof( buf ), "QRY %d %s %zd\r\n%s",
299                            ++md->trId, MSNP11_PROD_ID,
300                            strlen( resp ), resp );
301                g_free( resp );
302               
303                return( msn_write( ic, buf, strlen( buf ) ) );
304        }
305        else if( strcmp( cmd[0], "ILN" ) == 0 )
306        {
307                const struct msn_away_state *st;
308               
309                if( num_parts < 6 )
310                {
311                        imcb_error( ic, "Syntax error" );
312                        imc_logout( ic, TRUE );
313                        return( 0 );
314                }
315               
316                http_decode( cmd[5] );
317                imcb_rename_buddy( ic, cmd[3], cmd[5] );
318               
319                st = msn_away_state_by_code( cmd[2] );
320                if( !st )
321                {
322                        /* FIXME: Warn/Bomb about unknown away state? */
323                        st = msn_away_state_list + 1;
324                }
325               
326                imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN | 
327                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
328                                   st->name, NULL );
329        }
330        else if( strcmp( cmd[0], "FLN" ) == 0 )
331        {
332                if( cmd[1] == NULL )
333                        return 1;
334               
335                imcb_buddy_status( ic, cmd[1], 0, NULL, NULL );
336               
337                msn_sb_start_keepalives( msn_sb_by_handle( ic, cmd[1] ), TRUE );
338        }
339        else if( strcmp( cmd[0], "NLN" ) == 0 )
340        {
341                const struct msn_away_state *st;
342               
343                if( num_parts < 5 )
344                {
345                        imcb_error( ic, "Syntax error" );
346                        imc_logout( ic, TRUE );
347                        return( 0 );
348                }
349               
350                http_decode( cmd[3] );
351                imcb_rename_buddy( ic, cmd[2], cmd[3] );
352               
353                st = msn_away_state_by_code( cmd[1] );
354                if( !st )
355                {
356                        /* FIXME: Warn/Bomb about unknown away state? */
357                        st = msn_away_state_list + 1;
358                }
359               
360                imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN | 
361                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
362                                   st->name, NULL );
363               
364                msn_sb_stop_keepalives( msn_sb_by_handle( ic, cmd[2] ) );
365        }
366        else if( strcmp( cmd[0], "RNG" ) == 0 )
367        {
368                struct msn_switchboard *sb;
369                char *server;
370                int session, port;
371               
372                if( num_parts < 7 )
373                {
374                        imcb_error( ic, "Syntax error" );
375                        imc_logout( ic, TRUE );
376                        return( 0 );
377                }
378               
379                session = atoi( cmd[1] );
380               
381                server = strchr( cmd[2], ':' );
382                if( !server )
383                {
384                        imcb_error( ic, "Syntax error" );
385                        imc_logout( ic, TRUE );
386                        return( 0 );
387                }
388                *server = 0;
389                port = atoi( server + 1 );
390                server = cmd[2];
391               
392                if( strcmp( cmd[3], "CKI" ) != 0 )
393                {
394                        imcb_error( ic, "Unknown authentication method for switchboard" );
395                        imc_logout( ic, TRUE );
396                        return( 0 );
397                }
398               
399                debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] );
400               
401                if( ( sb = msn_sb_create( ic, server, port, cmd[4], session ) ) == NULL )
402                {
403                        /* Although this isn't strictly fatal for the NS connection, it's
404                           definitely something serious (we ran out of file descriptors?). */
405                        imcb_error( ic, "Could not create new switchboard" );
406                        imc_logout( ic, TRUE );
407                        return( 0 );
408                }
409                else
410                {
411                        sb->who = g_strdup( cmd[5] );
412                }
413        }
414        else if( strcmp( cmd[0], "ADD" ) == 0 )
415        {
416                if( num_parts >= 6 && strcmp( cmd[2], "RL" ) == 0 )
417                {
418                        GSList *l;
419                       
420                        http_decode( cmd[5] );
421                       
422                        if( strchr( cmd[4], '@' ) == NULL )
423                        {
424                                imcb_error( ic, "Syntax error" );
425                                imc_logout( ic, TRUE );
426                                return 0;
427                        }
428                       
429                        /* We got added by someone. If we don't have this
430                           person in permit/deny yet, inform the user. */
431                        for( l = ic->permit; l; l = l->next )
432                                if( g_strcasecmp( l->data, cmd[4] ) == 0 )
433                                        return 1;
434                       
435                        for( l = ic->deny; l; l = l->next )
436                                if( g_strcasecmp( l->data, cmd[4] ) == 0 )
437                                        return 1;
438                       
439                        msn_buddy_ask( ic, cmd[4], cmd[5] );
440                }
441                else if( num_parts >= 6 && strcmp( cmd[2], "FL" ) == 0 )
442                {
443                        const char *group = NULL;
444                        int num;
445                       
446                        if( cmd[6] != NULL && sscanf( cmd[6], "%d", &num ) == 1 && num < md->groupcount )
447                                group = md->grouplist[num];
448                       
449                        http_decode( cmd[5] );
450                        imcb_add_buddy( ic, cmd[4], group );
451                        imcb_rename_buddy( ic, cmd[4], cmd[5] );
452                }
453        }
454        else if( strcmp( cmd[0], "OUT" ) == 0 )
455        {
456                int allow_reconnect = TRUE;
457               
458                if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 )
459                {
460                        imcb_error( ic, "Someone else logged in with your account" );
461                        allow_reconnect = FALSE;
462                }
463                else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 )
464                {
465                        imcb_error( ic, "Terminating session because of server shutdown" );
466                }
467                else
468                {
469                        imcb_error( ic, "Session terminated by remote server (reason unknown)" );
470                }
471               
472                imc_logout( ic, allow_reconnect );
473                return( 0 );
474        }
475        else if( strcmp( cmd[0], "IPG" ) == 0 )
476        {
477                imcb_error( ic, "Received IPG command, we don't handle them yet." );
478               
479                md->handler->msglen = atoi( cmd[1] );
480               
481                if( md->handler->msglen <= 0 )
482                {
483                        imcb_error( ic, "Syntax error" );
484                        imc_logout( ic, TRUE );
485                        return( 0 );
486                }
487        }
488        else if( strcmp( cmd[0], "ADG" ) == 0 )
489        {
490                char *group = g_strdup( cmd[3] );
491                int groupnum, i;
492                GSList *l, *next;
493               
494                http_decode( group );
495                if( sscanf( cmd[4], "%d", &groupnum ) == 1 )
496                {
497                        if( groupnum >= md->groupcount )
498                        {
499                                md->grouplist = g_renew( char *, md->grouplist, groupnum + 1 );
500                                for( i = md->groupcount; i <= groupnum; i ++ )
501                                        md->grouplist[i] = NULL;
502                                md->groupcount = groupnum + 1;
503                        }
504                        g_free( md->grouplist[groupnum] );
505                        md->grouplist[groupnum] = group;
506                }
507                else
508                {
509                        /* Shouldn't happen, but if it does, give up on the group. */
510                        g_free( group );
511                        imcb_error( ic, "Syntax error" );
512                        imc_logout( ic, TRUE );
513                        return 0;
514                }
515               
516                for( l = md->grpq; l; l = next )
517                {
518                        struct msn_groupadd *ga = l->data;
519                        next = l->next;
520                        if( g_strcasecmp( ga->group, group ) == 0 )
521                        {
522                                if( !msn_buddy_list_add( ic, "FL", ga->who, ga->who, group ) )
523                                        return 0;
524                               
525                                g_free( ga->group );
526                                g_free( ga->who );
527                                g_free( ga );
528                                md->grpq = g_slist_remove( md->grpq, ga );
529                        }
530                }
531        }
532        else if( strcmp( cmd[0], "GCF" ) == 0 )
533        {
534                /* Coming up is cmd[2] bytes of stuff we're supposed to
535                   censore. Meh. */
536                md->handler->msglen = atoi( cmd[2] );
537        }
538        else if( strcmp( cmd[0], "UBX" ) == 0 )
539        {
540                /* Status message. Parser coming soon. */
541                if( num_parts >= 4 )
542                        md->handler->msglen = atoi( cmd[3] );
543        }
544        else if( strcmp( cmd[0], "NOT" ) == 0 )
545        {
546                /* Some kind of notification, not sure if it still exists
547                   but we have to skip the payload or stuff breaks. */
548                if( num_parts >= 3 )
549                        md->handler->msglen = atoi( cmd[2] );
550        }
551        else if( isdigit( cmd[0][0] ) )
552        {
553                int num = atoi( cmd[0] );
554                const struct msn_status_code *err = msn_status_by_number( num );
555               
556                imcb_error( ic, "Error reported by MSN server: %s", err->text );
557               
558                if( err->flags & STATUS_FATAL )
559                {
560                        imc_logout( ic, TRUE );
561                        return( 0 );
562                }
563        }
564        else
565        {
566                /* debug( "Received unknown command from main server: %s", cmd[0] ); */
567        }
568       
569        return( 1 );
570}
571
572static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts )
573{
574        struct im_connection *ic = data;
575        char *body;
576        int blen = 0;
577       
578        if( !num_parts )
579                return( 1 );
580       
581        if( ( body = strstr( msg, "\r\n\r\n" ) ) )
582        {
583                body += 4;
584                blen = msglen - ( body - msg );
585        }
586       
587        if( strcmp( cmd[0], "MSG" ) == 0 )
588        {
589                if( g_strcasecmp( cmd[1], "Hotmail" ) == 0 )
590                {
591                        char *ct = msn_findheader( msg, "Content-Type:", msglen );
592                       
593                        if( !ct )
594                                return( 1 );
595                       
596                        if( g_strncasecmp( ct, "application/x-msmsgssystemmessage", 33 ) == 0 )
597                        {
598                                char *mtype;
599                                char *arg1;
600                               
601                                if( !body )
602                                        return( 1 );
603                               
604                                mtype = msn_findheader( body, "Type:", blen );
605                                arg1 = msn_findheader( body, "Arg1:", blen );
606                               
607                                if( mtype && strcmp( mtype, "1" ) == 0 )
608                                {
609                                        if( arg1 )
610                                                imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 );
611                                }
612                               
613                                g_free( arg1 );
614                                g_free( mtype );
615                        }
616                        else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 )
617                        {
618                                /* We don't care about this profile for now... */
619                        }
620                        else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 )
621                        {
622                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
623                                {
624                                        char *inbox = msn_findheader( body, "Inbox-Unread:", blen );
625                                        char *folders = msn_findheader( body, "Folders-Unread:", blen );
626
627                                        if( inbox && folders )
628                                                imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
629                                       
630                                        g_free( inbox );
631                                        g_free( folders );
632                                }
633                        }
634                        else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )
635                        {
636                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
637                                {
638                                        char *from = msn_findheader( body, "From-Addr:", blen );
639                                        char *fromname = msn_findheader( body, "From:", blen );
640                                       
641                                        if( from && fromname )
642                                                imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from );
643
644                                        g_free( from );
645                                        g_free( fromname );
646                                }
647                        }
648                        else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 )
649                        {
650                                /* Sorry, but this one really is *USELESS* */
651                        }
652                        else
653                        {
654                                debug( "Can't handle %s packet from notification server", ct );
655                        }
656                       
657                        g_free( ct );
658                }
659        }
660        else if( strcmp( cmd[0], "UBX" ) == 0 )
661        {
662                struct xt_node *psm;
663                char *psm_text = NULL;
664               
665                psm = xt_from_string( msg );
666                if( psm && strcmp( psm->name, "Data" ) == 0 &&
667                    ( psm = xt_find_node( psm->children, "PSM" ) ) )
668                        psm_text = psm->text;
669               
670                imcb_buddy_status_msg( ic, cmd[1], psm_text );
671                xt_free_node( psm );
672        }
673       
674        return( 1 );
675}
676
677void msn_auth_got_passport_token( struct im_connection *ic, char *token )
678{
679        struct msn_data *md;
680       
681        /* Dead connection? */
682        if( g_slist_find( msn_connections, ic ) == NULL )
683                return;
684       
685        md = ic->proto_data;
686       
687        {
688                char buf[1024];
689               
690                g_snprintf( buf, sizeof( buf ), "USR %d SSO S %s %s\r\n", ++md->trId, md->tokens[0], token );
691                msn_write( ic, buf, strlen( buf ) );
692        }
693}
694
695void msn_auth_got_contact_list( struct im_connection *ic )
696{
697        char buf[64];
698        struct msn_data *md;
699       
700        /* Dead connection? */
701        if( g_slist_find( msn_connections, ic ) == NULL )
702                return;
703       
704        md = ic->proto_data;
705       
706       
707        g_snprintf( buf, sizeof( buf ), "BLP %d %s\r\n", ++md->trId, "BL" );
708        msn_write( ic, buf, strlen( buf ) );
709}
710
711static gboolean msn_ns_send_adl_1( gpointer key, gpointer value, gpointer data )
712{
713        struct xt_node *adl = data, *d, *c;
714        struct bee_user *bu = value;
715        struct msn_buddy_data *bd = bu->data;
716        char handle[strlen(bu->handle)];
717        char *domain;
718        char l[4];
719       
720        strcpy( handle, bu->handle );
721        if( ( domain = strchr( handle, '@' ) ) == NULL ) /* WTF */
722                return FALSE; 
723        *domain = '\0';
724        domain ++;
725       
726        if( ( d = adl->children ) == NULL ||
727            g_strcasecmp( xt_find_attr( d, "n" ), domain ) != 0 )
728        {
729                d = xt_new_node( "d", NULL, NULL );
730                xt_add_attr( d, "n", domain );
731                xt_insert_child( adl, d );
732        }
733       
734        g_snprintf( l, sizeof( l ), "%d", bd->flags & 7 );
735        c = xt_new_node( "c", NULL, NULL );
736        xt_add_attr( c, "n", handle );
737        xt_add_attr( c, "l", l );
738        xt_add_attr( c, "t", "1" ); /* 1 means normal, 4 means mobile? */
739        xt_insert_child( d, c );
740       
741        return FALSE;
742}
743
744static void msn_ns_send_adl( struct im_connection *ic )
745{
746        struct xt_node *adl;
747        struct msn_data *md;
748        char *adls, buf[64];
749       
750        /* Dead connection? */
751        if( g_slist_find( msn_connections, ic ) == NULL )
752                return;
753       
754        md = ic->proto_data;
755       
756        adl = xt_new_node( "ml", NULL, NULL );
757        xt_add_attr( adl, "l", "1" );
758        g_tree_foreach( md->domaintree, msn_ns_send_adl_1, adl );
759        adls = xt_to_string( adl );
760       
761        g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n", ++md->trId, strlen( adls ) );
762        if( msn_write( ic, buf, strlen( buf ) ) )
763                msn_write( ic, adls, strlen( adls ) );
764       
765        g_free( adls );
766        xt_free_node( adl );
767}
Note: See TracBrowser for help on using the repository browser.