source: protocols/msn/ns.c @ d912fe4

Last change on this file since d912fe4 was 193dc74, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-08-14T16:16:52Z

Responses to add requests work now.

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