source: protocols/msn/ns.c @ e5854a8

Last change on this file since e5854a8 was e5854a8, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-08-14T14:50:10Z

Show incoming auth. requests (although responding to them currently causes
a disconnect).

  • Property mode set to 100644
File size: 18.7 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                else if( num_parts >= 3 )
282                {
283                        md->handler->msglen = atoi( cmd[2] );
284                }
285        }
286        else if( strcmp( cmd[0], "PRP" ) == 0 )
287        {
288                imcb_connected( ic );
289        }
290        else if( strcmp( cmd[0], "CHL" ) == 0 )
291        {
292                char *resp;
293               
294                if( num_parts < 3 )
295                {
296                        imcb_error( ic, "Syntax error" );
297                        imc_logout( ic, TRUE );
298                        return( 0 );
299                }
300               
301                resp = msn_p11_challenge( cmd[2] );
302                g_snprintf( buf, sizeof( buf ), "QRY %d %s %zd\r\n%s",
303                            ++md->trId, MSNP11_PROD_ID,
304                            strlen( resp ), resp );
305                g_free( resp );
306               
307                return( msn_write( ic, buf, strlen( buf ) ) );
308        }
309        else if( strcmp( cmd[0], "ILN" ) == 0 )
310        {
311                const struct msn_away_state *st;
312               
313                if( num_parts < 6 )
314                {
315                        imcb_error( ic, "Syntax error" );
316                        imc_logout( ic, TRUE );
317                        return( 0 );
318                }
319               
320                http_decode( cmd[5] );
321                imcb_rename_buddy( ic, cmd[3], cmd[5] );
322               
323                st = msn_away_state_by_code( cmd[2] );
324                if( !st )
325                {
326                        /* FIXME: Warn/Bomb about unknown away state? */
327                        st = msn_away_state_list + 1;
328                }
329               
330                imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN | 
331                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
332                                   st->name, NULL );
333        }
334        else if( strcmp( cmd[0], "FLN" ) == 0 )
335        {
336                if( cmd[1] == NULL )
337                        return 1;
338               
339                imcb_buddy_status( ic, cmd[1], 0, NULL, NULL );
340               
341                msn_sb_start_keepalives( msn_sb_by_handle( ic, cmd[1] ), TRUE );
342        }
343        else if( strcmp( cmd[0], "NLN" ) == 0 )
344        {
345                const struct msn_away_state *st;
346               
347                if( num_parts < 5 )
348                {
349                        imcb_error( ic, "Syntax error" );
350                        imc_logout( ic, TRUE );
351                        return( 0 );
352                }
353               
354                http_decode( cmd[4] );
355                imcb_rename_buddy( ic, cmd[2], cmd[4] );
356               
357                st = msn_away_state_by_code( cmd[1] );
358                if( !st )
359                {
360                        /* FIXME: Warn/Bomb about unknown away state? */
361                        st = msn_away_state_list + 1;
362                }
363               
364                imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN | 
365                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
366                                   st->name, NULL );
367               
368                msn_sb_stop_keepalives( msn_sb_by_handle( ic, cmd[2] ) );
369        }
370        else if( strcmp( cmd[0], "RNG" ) == 0 )
371        {
372                struct msn_switchboard *sb;
373                char *server;
374                int session, port;
375               
376                if( num_parts < 7 )
377                {
378                        imcb_error( ic, "Syntax error" );
379                        imc_logout( ic, TRUE );
380                        return( 0 );
381                }
382               
383                session = atoi( cmd[1] );
384               
385                server = strchr( cmd[2], ':' );
386                if( !server )
387                {
388                        imcb_error( ic, "Syntax error" );
389                        imc_logout( ic, TRUE );
390                        return( 0 );
391                }
392                *server = 0;
393                port = atoi( server + 1 );
394                server = cmd[2];
395               
396                if( strcmp( cmd[3], "CKI" ) != 0 )
397                {
398                        imcb_error( ic, "Unknown authentication method for switchboard" );
399                        imc_logout( ic, TRUE );
400                        return( 0 );
401                }
402               
403                debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] );
404               
405                if( ( sb = msn_sb_create( ic, server, port, cmd[4], session ) ) == NULL )
406                {
407                        /* Although this isn't strictly fatal for the NS connection, it's
408                           definitely something serious (we ran out of file descriptors?). */
409                        imcb_error( ic, "Could not create new switchboard" );
410                        imc_logout( ic, TRUE );
411                        return( 0 );
412                }
413                else
414                {
415                        sb->who = g_strdup( cmd[5] );
416                }
417        }
418        else if( strcmp( cmd[0], "OUT" ) == 0 )
419        {
420                int allow_reconnect = TRUE;
421               
422                if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 )
423                {
424                        imcb_error( ic, "Someone else logged in with your account" );
425                        allow_reconnect = FALSE;
426                }
427                else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 )
428                {
429                        imcb_error( ic, "Terminating session because of server shutdown" );
430                }
431                else
432                {
433                        imcb_error( ic, "Session terminated by remote server (reason unknown)" );
434                }
435               
436                imc_logout( ic, allow_reconnect );
437                return( 0 );
438        }
439        else if( strcmp( cmd[0], "IPG" ) == 0 )
440        {
441                imcb_error( ic, "Received IPG command, we don't handle them yet." );
442               
443                md->handler->msglen = atoi( cmd[1] );
444               
445                if( md->handler->msglen <= 0 )
446                {
447                        imcb_error( ic, "Syntax error" );
448                        imc_logout( ic, TRUE );
449                        return( 0 );
450                }
451        }
452#if 0
453        else if( strcmp( cmd[0], "ADG" ) == 0 )
454        {
455                char *group = g_strdup( cmd[3] );
456                int groupnum, i;
457                GSList *l, *next;
458               
459                http_decode( group );
460                if( sscanf( cmd[4], "%d", &groupnum ) == 1 )
461                {
462                        if( groupnum >= md->groupcount )
463                        {
464                                md->grouplist = g_renew( char *, md->grouplist, groupnum + 1 );
465                                for( i = md->groupcount; i <= groupnum; i ++ )
466                                        md->grouplist[i] = NULL;
467                                md->groupcount = groupnum + 1;
468                        }
469                        g_free( md->grouplist[groupnum] );
470                        md->grouplist[groupnum] = group;
471                }
472                else
473                {
474                        /* Shouldn't happen, but if it does, give up on the group. */
475                        g_free( group );
476                        imcb_error( ic, "Syntax error" );
477                        imc_logout( ic, TRUE );
478                        return 0;
479                }
480               
481                for( l = md->grpq; l; l = next )
482                {
483                        struct msn_groupadd *ga = l->data;
484                        next = l->next;
485                        if( g_strcasecmp( ga->group, group ) == 0 )
486                        {
487                                if( !msn_buddy_list_add( ic, "FL", ga->who, ga->who, group ) )
488                                        return 0;
489                               
490                                g_free( ga->group );
491                                g_free( ga->who );
492                                g_free( ga );
493                                md->grpq = g_slist_remove( md->grpq, ga );
494                        }
495                }
496        }
497#endif
498        else if( strcmp( cmd[0], "GCF" ) == 0 )
499        {
500                /* Coming up is cmd[2] bytes of stuff we're supposed to
501                   censore. Meh. */
502                md->handler->msglen = atoi( cmd[2] );
503        }
504        else if( strcmp( cmd[0], "UBX" ) == 0 )
505        {
506                /* Status message. */
507                if( num_parts >= 4 )
508                        md->handler->msglen = atoi( cmd[3] );
509        }
510        else if( strcmp( cmd[0], "NOT" ) == 0 )
511        {
512                /* Some kind of notification, poorly documented but
513                   apparently used to announce address book changes. */
514                if( num_parts >= 2 )
515                        md->handler->msglen = atoi( cmd[1] );
516        }
517        else if( isdigit( cmd[0][0] ) )
518        {
519                int num = atoi( cmd[0] );
520                const struct msn_status_code *err = msn_status_by_number( num );
521               
522                imcb_error( ic, "Error reported by MSN server: %s", err->text );
523               
524                if( err->flags & STATUS_FATAL )
525                {
526                        imc_logout( ic, TRUE );
527                        return( 0 );
528                }
529        }
530        else
531        {
532                /* debug( "Received unknown command from main server: %s", cmd[0] ); */
533        }
534       
535        return( 1 );
536}
537
538static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts )
539{
540        struct im_connection *ic = data;
541        char *body;
542        int blen = 0;
543       
544        if( !num_parts )
545                return( 1 );
546       
547        if( ( body = strstr( msg, "\r\n\r\n" ) ) )
548        {
549                body += 4;
550                blen = msglen - ( body - msg );
551        }
552       
553        if( strcmp( cmd[0], "MSG" ) == 0 )
554        {
555                if( g_strcasecmp( cmd[1], "Hotmail" ) == 0 )
556                {
557                        char *ct = msn_findheader( msg, "Content-Type:", msglen );
558                       
559                        if( !ct )
560                                return( 1 );
561                       
562                        if( g_strncasecmp( ct, "application/x-msmsgssystemmessage", 33 ) == 0 )
563                        {
564                                char *mtype;
565                                char *arg1;
566                               
567                                if( !body )
568                                        return( 1 );
569                               
570                                mtype = msn_findheader( body, "Type:", blen );
571                                arg1 = msn_findheader( body, "Arg1:", blen );
572                               
573                                if( mtype && strcmp( mtype, "1" ) == 0 )
574                                {
575                                        if( arg1 )
576                                                imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 );
577                                }
578                               
579                                g_free( arg1 );
580                                g_free( mtype );
581                        }
582                        else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 )
583                        {
584                                /* We don't care about this profile for now... */
585                        }
586                        else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 )
587                        {
588                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
589                                {
590                                        char *inbox = msn_findheader( body, "Inbox-Unread:", blen );
591                                        char *folders = msn_findheader( body, "Folders-Unread:", blen );
592
593                                        if( inbox && folders )
594                                                imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
595                                       
596                                        g_free( inbox );
597                                        g_free( folders );
598                                }
599                        }
600                        else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )
601                        {
602                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
603                                {
604                                        char *from = msn_findheader( body, "From-Addr:", blen );
605                                        char *fromname = msn_findheader( body, "From:", blen );
606                                       
607                                        if( from && fromname )
608                                                imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from );
609
610                                        g_free( from );
611                                        g_free( fromname );
612                                }
613                        }
614                        else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 )
615                        {
616                                /* Sorry, but this one really is *USELESS* */
617                        }
618                        else
619                        {
620                                debug( "Can't handle %s packet from notification server", ct );
621                        }
622                       
623                        g_free( ct );
624                }
625        }
626        else if( strcmp( cmd[0], "UBX" ) == 0 )
627        {
628                struct xt_node *psm;
629                char *psm_text = NULL;
630               
631                psm = xt_from_string( msg );
632                if( psm && strcmp( psm->name, "Data" ) == 0 &&
633                    ( psm = xt_find_node( psm->children, "PSM" ) ) )
634                        psm_text = psm->text;
635               
636                imcb_buddy_status_msg( ic, cmd[1], psm_text );
637                xt_free_node( psm );
638        }
639        else if( strcmp( cmd[0], "ADL" ) == 0 )
640        {
641                struct xt_node *adl, *d, *c;
642               
643                if( !( adl = xt_from_string( msg ) ) )
644                        return 1;
645               
646                for( d = adl->children; d; d = d->next )
647                {
648                        char *dn;
649                        if( strcmp( d->name, "d" ) != 0 ||
650                            ( dn = xt_find_attr( d, "n" ) ) == NULL )
651                                continue;
652                        for( c = d->children; c; c = c->next )
653                        {
654                                bee_user_t *bu;
655                                struct msn_buddy_data *bd;
656                                char *cn, *handle, *f, *l;
657                                int flags;
658                               
659                                if( strcmp( c->name, "c" ) != 0 ||
660                                    ( l = xt_find_attr( c, "l" ) ) == NULL ||
661                                    ( cn = xt_find_attr( c, "n" ) ) == NULL )
662                                        continue;
663                               
664                                handle = g_strdup_printf( "%s@%s", cn, dn );
665                                if( !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) ||
666                                       ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) )
667                                {
668                                        g_free( handle );
669                                        continue;
670                                }
671                                g_free( handle );
672                                bd = bu->data;
673                               
674                                if( ( f = xt_find_attr( c, "f" ) ) )
675                                {
676                                        http_decode( f );
677                                        imcb_rename_buddy( ic, bu->handle, f );
678                                }
679                               
680                                flags = atoi( l ) & 15;
681                                if( bd->flags != flags )
682                                {
683                                        bd->flags = flags;
684                                        msn_buddy_ask( bu );
685                                }
686                        }
687                }
688        }
689       
690        return( 1 );
691}
692
693void msn_auth_got_passport_token( struct im_connection *ic, char *token )
694{
695        struct msn_data *md;
696       
697        /* Dead connection? */
698        if( g_slist_find( msn_connections, ic ) == NULL )
699                return;
700       
701        md = ic->proto_data;
702       
703        {
704                char buf[1024];
705               
706                g_snprintf( buf, sizeof( buf ), "USR %d SSO S %s %s\r\n", ++md->trId, md->tokens[0], token );
707                msn_write( ic, buf, strlen( buf ) );
708        }
709}
710
711void msn_auth_got_contact_list( struct im_connection *ic )
712{
713        char buf[64];
714        struct msn_data *md;
715       
716        /* Dead connection? */
717        if( g_slist_find( msn_connections, ic ) == NULL )
718                return;
719       
720        md = ic->proto_data;
721       
722       
723        g_snprintf( buf, sizeof( buf ), "BLP %d %s\r\n", ++md->trId, "BL" );
724        msn_write( ic, buf, strlen( buf ) );
725}
726
727static gboolean msn_ns_send_adl_1( gpointer key, gpointer value, gpointer data )
728{
729        struct xt_node *adl = data, *d, *c;
730        struct bee_user *bu = value;
731        struct msn_buddy_data *bd = bu->data;
732        char handle[strlen(bu->handle)];
733        char *domain;
734        char l[4];
735       
736        if( ( bd->flags & 7 ) == 0 )
737                return FALSE;
738       
739        strcpy( handle, bu->handle );
740        if( ( domain = strchr( handle, '@' ) ) == NULL ) /* WTF */
741                return FALSE; 
742        *domain = '\0';
743        domain ++;
744       
745        if( ( d = adl->children ) == NULL ||
746            g_strcasecmp( xt_find_attr( d, "n" ), domain ) != 0 )
747        {
748                d = xt_new_node( "d", NULL, NULL );
749                xt_add_attr( d, "n", domain );
750                xt_insert_child( adl, d );
751        }
752       
753        g_snprintf( l, sizeof( l ), "%d", bd->flags & 7 );
754        c = xt_new_node( "c", NULL, NULL );
755        xt_add_attr( c, "n", handle );
756        xt_add_attr( c, "l", l );
757        xt_add_attr( c, "t", "1" ); /* 1 means normal, 4 means mobile? */
758        xt_insert_child( d, c );
759       
760        return FALSE;
761}
762
763static void msn_ns_send_adl( struct im_connection *ic )
764{
765        struct xt_node *adl;
766        struct msn_data *md;
767        char *adls, buf[64];
768       
769        /* Dead connection? */
770        if( g_slist_find( msn_connections, ic ) == NULL )
771                return;
772       
773        md = ic->proto_data;
774       
775        adl = xt_new_node( "ml", NULL, NULL );
776        xt_add_attr( adl, "l", "1" );
777        g_tree_foreach( md->domaintree, msn_ns_send_adl_1, adl );
778        adls = xt_to_string( adl );
779       
780        g_snprintf( buf, sizeof( buf ), "ADL %d %zd\r\n", ++md->trId, strlen( adls ) );
781        if( msn_write( ic, buf, strlen( buf ) ) )
782                msn_write( ic, adls, strlen( adls ) );
783       
784        g_free( adls );
785        xt_free_node( adl );
786}
Note: See TracBrowser for help on using the repository browser.