source: protocols/msn/ns.c @ 7815a2b

Last change on this file since 7815a2b was 7815a2b, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-04-07T02:15:44Z

Check MSN display names given by the server for UTF-8-correctness before
using them since invalid XML ending up in user configs can get very ugly.

  • Property mode set to 100644
File size: 18.9 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2004 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 "passport.h"
30#include "md5.h"
31
32static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond );
33static int msn_ns_command( gpointer data, char **cmd, int num_parts );
34static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );
35
36static void msn_auth_got_passport_token( struct msn_auth_data *mad );
37static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name );
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 MSNP8 CVR0\r\n", ++md->trId );
76        if( msn_write( ic, s, strlen( s ) ) )
77        {
78                ic->inpa = b_input_add( md->fd, GAIM_INPUT_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], "MSNP8", 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 TWN 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 == 5 && strcmp( cmd[2], "TWN" ) == 0 && strcmp( cmd[3], "S" ) == 0 )
223                {
224                        /* Time for some Passport black magic... */
225                        if( !passport_get_token( msn_auth_got_passport_token, ic, ic->acc->user, ic->acc->pass, cmd[4] ) )
226                        {
227                                imcb_error( ic, "Error while contacting Passport server" );
228                                imc_logout( ic, TRUE );
229                                return( 0 );
230                        }
231                }
232                else if( num_parts >= 7 && strcmp( cmd[2], "OK" ) == 0 )
233                {
234                        if( num_parts == 7 )
235                                msn_ns_got_display_name( ic, cmd[4] );
236                        else
237                                imcb_log( ic, "Warning: Friendly name in server response was corrupted" );
238                       
239                        imcb_log( ic, "Authenticated, getting buddy list" );
240                       
241                        g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId );
242                        return( msn_write( ic, buf, strlen( buf ) ) );
243                }
244                else
245                {
246                        imcb_error( ic, "Unknown authentication type" );
247                        imc_logout( ic, FALSE );
248                        return( 0 );
249                }
250        }
251        else if( strcmp( cmd[0], "MSG" ) == 0 )
252        {
253                if( num_parts != 4 )
254                {
255                        imcb_error( ic, "Syntax error" );
256                        imc_logout( ic, TRUE );
257                        return( 0 );
258                }
259               
260                md->handler->msglen = atoi( cmd[3] );
261               
262                if( md->handler->msglen <= 0 )
263                {
264                        imcb_error( ic, "Syntax error" );
265                        imc_logout( ic, TRUE );
266                        return( 0 );
267                }
268        }
269        else if( strcmp( cmd[0], "SYN" ) == 0 )
270        {
271                if( num_parts == 5 )
272                {
273                        int i, groupcount;
274                       
275                        groupcount = atoi( cmd[4] );
276                        if( groupcount > 0 )
277                        {
278                                /* valgrind says this is leaking memory, I'm guessing
279                                   that this happens during server redirects. */
280                                if( md->grouplist )
281                                {
282                                        for( i = 0; i < md->groupcount; i ++ )
283                                                g_free( md->grouplist[i] );
284                                        g_free( md->grouplist );
285                                }
286                               
287                                md->groupcount = groupcount;
288                                md->grouplist = g_new0( char *, md->groupcount );
289                        }
290                       
291                        md->buddycount = atoi( cmd[3] );
292                        if( !*cmd[3] || md->buddycount == 0 )
293                                msn_logged_in( ic );
294                }
295                else
296                {
297                        /* Hrrm... This SYN reply doesn't really look like something we expected.
298                           Let's assume everything is okay. */
299                       
300                        msn_logged_in( ic );
301                }
302        }
303        else if( strcmp( cmd[0], "LST" ) == 0 )
304        {
305                int list;
306               
307                if( num_parts != 4 && num_parts != 5 )
308                {
309                        imcb_error( ic, "Syntax error" );
310                        imc_logout( ic, TRUE );
311                        return( 0 );
312                }
313               
314                http_decode( cmd[2] );
315                list = atoi( cmd[3] );
316               
317                if( list & 1 ) /* FL */
318                {
319                        char *group = NULL;
320                        int num;
321                       
322                        if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 && num < md->groupcount )
323                                group = md->grouplist[num];
324                       
325                        imcb_add_buddy( ic, cmd[1], group );
326                        imcb_rename_buddy( ic, cmd[1], cmd[2] );
327                }
328                if( list & 2 ) /* AL */
329                {
330                        ic->permit = g_slist_append( ic->permit, g_strdup( cmd[1] ) );
331                }
332                if( list & 4 ) /* BL */
333                {
334                        ic->deny = g_slist_append( ic->deny, g_strdup( cmd[1] ) );
335                }
336                if( list & 8 ) /* RL */
337                {
338                        if( ( list & 6 ) == 0 )
339                                msn_buddy_ask( ic, cmd[1], cmd[2] );
340                }
341               
342                if( --md->buddycount == 0 )
343                {
344                        if( ic->flags & OPT_LOGGED_IN )
345                        {
346                                imcb_log( ic, "Successfully transferred to different server" );
347                                g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 );
348                                return( msn_write( ic, buf, strlen( buf ) ) );
349                        }
350                        else
351                        {
352                                msn_logged_in( ic );
353                        }
354                }
355        }
356        else if( strcmp( cmd[0], "LSG" ) == 0 )
357        {
358                int num;
359               
360                if( num_parts != 4 )
361                {
362                        imcb_error( ic, "Syntax error" );
363                        imc_logout( ic, TRUE );
364                        return( 0 );
365                }
366               
367                http_decode( cmd[2] );
368                num = atoi( cmd[1] );
369               
370                if( num < md->groupcount )
371                        md->grouplist[num] = g_strdup( cmd[2] );
372        }
373        else if( strcmp( cmd[0], "CHL" ) == 0 )
374        {
375                md5_state_t state;
376                md5_byte_t digest[16];
377                int i;
378               
379                if( num_parts != 3 )
380                {
381                        imcb_error( ic, "Syntax error" );
382                        imc_logout( ic, TRUE );
383                        return( 0 );
384                }
385               
386                md5_init( &state );
387                md5_append( &state, (const md5_byte_t *) cmd[2], strlen( cmd[2] ) );
388                md5_append( &state, (const md5_byte_t *) QRY_CODE, strlen( QRY_CODE ) );
389                md5_finish( &state, digest );
390               
391                g_snprintf( buf, sizeof( buf ), "QRY %d %s %d\r\n", ++md->trId, QRY_NAME, 32 );
392                for( i = 0; i < 16; i ++ )
393                        g_snprintf( buf + strlen( buf ), 3, "%02x", digest[i] );
394               
395                return( msn_write( ic, buf, strlen( buf ) ) );
396        }
397        else if( strcmp( cmd[0], "ILN" ) == 0 )
398        {
399                const struct msn_away_state *st;
400               
401                if( num_parts != 6 )
402                {
403                        imcb_error( ic, "Syntax error" );
404                        imc_logout( ic, TRUE );
405                        return( 0 );
406                }
407               
408                http_decode( cmd[4] );
409                imcb_rename_buddy( ic, cmd[3], cmd[4] );
410               
411                st = msn_away_state_by_code( cmd[2] );
412                if( !st )
413                {
414                        /* FIXME: Warn/Bomb about unknown away state? */
415                        st = msn_away_state_list + 1;
416                }
417               
418                imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN | 
419                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
420                                   st->name, NULL );
421        }
422        else if( strcmp( cmd[0], "FLN" ) == 0 )
423        {
424                if( cmd[1] )
425                        imcb_buddy_status( ic, cmd[1], 0, NULL, NULL );
426        }
427        else if( strcmp( cmd[0], "NLN" ) == 0 )
428        {
429                const struct msn_away_state *st;
430               
431                if( num_parts != 5 )
432                {
433                        imcb_error( ic, "Syntax error" );
434                        imc_logout( ic, TRUE );
435                        return( 0 );
436                }
437               
438                http_decode( cmd[3] );
439                imcb_rename_buddy( ic, cmd[2], cmd[3] );
440               
441                st = msn_away_state_by_code( cmd[1] );
442                if( !st )
443                {
444                        /* FIXME: Warn/Bomb about unknown away state? */
445                        st = msn_away_state_list + 1;
446                }
447               
448                imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN | 
449                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
450                                   st->name, NULL );
451        }
452        else if( strcmp( cmd[0], "RNG" ) == 0 )
453        {
454                struct msn_switchboard *sb;
455                char *server;
456                int session, port;
457               
458                if( num_parts != 7 )
459                {
460                        imcb_error( ic, "Syntax error" );
461                        imc_logout( ic, TRUE );
462                        return( 0 );
463                }
464               
465                session = atoi( cmd[1] );
466               
467                server = strchr( cmd[2], ':' );
468                if( !server )
469                {
470                        imcb_error( ic, "Syntax error" );
471                        imc_logout( ic, TRUE );
472                        return( 0 );
473                }
474                *server = 0;
475                port = atoi( server + 1 );
476                server = cmd[2];
477               
478                if( strcmp( cmd[3], "CKI" ) != 0 )
479                {
480                        imcb_error( ic, "Unknown authentication method for switchboard" );
481                        imc_logout( ic, TRUE );
482                        return( 0 );
483                }
484               
485                debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] );
486               
487                if( ( sb = msn_sb_create( ic, server, port, cmd[4], session ) ) == NULL )
488                {
489                        /* Although this isn't strictly fatal for the NS connection, it's
490                           definitely something serious (we ran out of file descriptors?). */
491                        imcb_error( ic, "Could not create new switchboard" );
492                        imc_logout( ic, TRUE );
493                        return( 0 );
494                }
495                else
496                {
497                        sb->who = g_strdup( cmd[5] );
498                }
499        }
500        else if( strcmp( cmd[0], "ADD" ) == 0 )
501        {
502                if( num_parts == 6 && strcmp( cmd[2], "RL" ) == 0 )
503                {
504                        GSList *l;
505                       
506                        http_decode( cmd[5] );
507                       
508                        if( strchr( cmd[4], '@' ) == NULL )
509                        {
510                                imcb_error( ic, "Syntax error" );
511                                imc_logout( ic, TRUE );
512                                return 0;
513                        }
514                       
515                        /* We got added by someone. If we don't have this
516                           person in permit/deny yet, inform the user. */
517                        for( l = ic->permit; l; l = l->next )
518                                if( g_strcasecmp( l->data, cmd[4] ) == 0 )
519                                        return 1;
520                       
521                        for( l = ic->deny; l; l = l->next )
522                                if( g_strcasecmp( l->data, cmd[4] ) == 0 )
523                                        return 1;
524                       
525                        msn_buddy_ask( ic, cmd[4], cmd[5] );
526                }
527                else if( num_parts >= 6 && strcmp( cmd[2], "FL" ) == 0 )
528                {
529                        http_decode( cmd[5] );
530                        imcb_add_buddy( ic, cmd[4], NULL );
531                        imcb_rename_buddy( ic, cmd[4], cmd[5] );
532                }
533        }
534        else if( strcmp( cmd[0], "OUT" ) == 0 )
535        {
536                int allow_reconnect = TRUE;
537               
538                if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 )
539                {
540                        imcb_error( ic, "Someone else logged in with your account" );
541                        allow_reconnect = FALSE;
542                }
543                else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 )
544                {
545                        imcb_error( ic, "Terminating session because of server shutdown" );
546                }
547                else
548                {
549                        imcb_error( ic, "Session terminated by remote server (reason unknown)" );
550                }
551               
552                imc_logout( ic, allow_reconnect );
553                return( 0 );
554        }
555#if 0
556        /* Discard this one completely for now since I don't care about the ack
557           and since MSN servers can apparently screw up the formatting. */
558        else if( strcmp( cmd[0], "REA" ) == 0 )
559        {
560                if( num_parts != 5 )
561                {
562                        imcb_error( ic, "Syntax error" );
563                        imc_logout( ic, TRUE );
564                        return( 0 );
565                }
566               
567                if( g_strcasecmp( cmd[3], ic->acc->user ) == 0 )
568                {
569                        set_t *s;
570                       
571                        http_decode( cmd[4] );
572                        strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) );
573                        ic->displayname[sizeof(ic->displayname)-1] = 0;
574                       
575                        if( ( s = set_find( &ic->acc->set, "display_name" ) ) )
576                        {
577                                g_free( s->value );
578                                s->value = g_strdup( cmd[4] );
579                        }
580                }
581                else
582                {
583                        /* This is not supposed to happen, but let's handle it anyway... */
584                        http_decode( cmd[4] );
585                        imcb_rename_buddy( ic, cmd[3], cmd[4] );
586                }
587        }
588#endif
589        else if( strcmp( cmd[0], "IPG" ) == 0 )
590        {
591                imcb_error( ic, "Received IPG command, we don't handle them yet." );
592               
593                md->handler->msglen = atoi( cmd[1] );
594               
595                if( md->handler->msglen <= 0 )
596                {
597                        imcb_error( ic, "Syntax error" );
598                        imc_logout( ic, TRUE );
599                        return( 0 );
600                }
601        }
602        else if( isdigit( cmd[0][0] ) )
603        {
604                int num = atoi( cmd[0] );
605                const struct msn_status_code *err = msn_status_by_number( num );
606               
607                imcb_error( ic, "Error reported by MSN server: %s", err->text );
608               
609                if( err->flags & STATUS_FATAL )
610                {
611                        imc_logout( ic, TRUE );
612                        return( 0 );
613                }
614        }
615        else
616        {
617                /* debug( "Received unknown command from main server: %s", cmd[0] ); */
618        }
619       
620        return( 1 );
621}
622
623static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts )
624{
625        struct im_connection *ic = data;
626        char *body;
627        int blen = 0;
628       
629        if( !num_parts )
630                return( 1 );
631       
632        if( ( body = strstr( msg, "\r\n\r\n" ) ) )
633        {
634                body += 4;
635                blen = msglen - ( body - msg );
636        }
637       
638        if( strcmp( cmd[0], "MSG" ) == 0 )
639        {
640                if( g_strcasecmp( cmd[1], "Hotmail" ) == 0 )
641                {
642                        char *ct = msn_findheader( msg, "Content-Type:", msglen );
643                       
644                        if( !ct )
645                                return( 1 );
646                       
647                        if( g_strncasecmp( ct, "application/x-msmsgssystemmessage", 33 ) == 0 )
648                        {
649                                char *mtype;
650                                char *arg1;
651                               
652                                if( !body )
653                                        return( 1 );
654                               
655                                mtype = msn_findheader( body, "Type:", blen );
656                                arg1 = msn_findheader( body, "Arg1:", blen );
657                               
658                                if( mtype && strcmp( mtype, "1" ) == 0 )
659                                {
660                                        if( arg1 )
661                                                imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 );
662                                }
663                               
664                                g_free( arg1 );
665                                g_free( mtype );
666                        }
667                        else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 )
668                        {
669                                /* We don't care about this profile for now... */
670                        }
671                        else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 )
672                        {
673                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
674                                {
675                                        char *inbox = msn_findheader( body, "Inbox-Unread:", blen );
676                                        char *folders = msn_findheader( body, "Folders-Unread:", blen );
677
678                                        if( inbox && folders )
679                                                imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
680                                       
681                                        g_free( inbox );
682                                        g_free( folders );
683                                }
684                        }
685                        else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )
686                        {
687                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
688                                {
689                                        char *from = msn_findheader( body, "From-Addr:", blen );
690                                        char *fromname = msn_findheader( body, "From:", blen );
691                                       
692                                        if( from && fromname )
693                                                imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from );
694
695                                        g_free( from );
696                                        g_free( fromname );
697                                }
698                        }
699                        else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 )
700                        {
701                                /* Sorry, but this one really is *USELESS* */
702                        }
703                        else
704                        {
705                                debug( "Can't handle %s packet from notification server", ct );
706                        }
707                       
708                        g_free( ct );
709                }
710        }
711       
712        return( 1 );
713}
714
715static void msn_auth_got_passport_token( struct msn_auth_data *mad )
716{
717        struct im_connection *ic = mad->data;
718        struct msn_data *md;
719       
720        /* Dead connection? */
721        if( g_slist_find( msn_connections, ic ) == NULL )
722                return;
723       
724        md = ic->proto_data;
725        if( mad->token )
726        {
727                char buf[1024];
728               
729                g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, mad->token );
730                msn_write( ic, buf, strlen( buf ) );
731        }
732        else
733        {
734                imcb_error( ic, "Error during Passport authentication: %s", mad->error );
735                imc_logout( ic, TRUE );
736        }
737}
738
739static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name )
740{
741        set_t *s;
742       
743        if( ( s = set_find( &ic->acc->set, "display_name" ) ) == NULL )
744                return FALSE; /* Shouldn't happen.. */
745       
746        http_decode( name );
747       
748        if( s->value && strcmp( s->value, name ) == 0 )
749        {
750                return TRUE;
751                /* The names match, nothing to worry about. */
752        }
753        else if( s->value != NULL &&
754                 ( strcmp( name, ic->acc->user ) == 0 ||
755                   set_getbool( &ic->acc->set, "local_display_name" ) ) )
756        {
757                /* The server thinks our display name is our e-mail address
758                   which is probably wrong, or the user *wants* us to do this:
759                   Always use the locally set display_name. */
760                return msn_set_display_name( ic, s->value );
761        }
762        else
763        {
764                if( s->value && *s->value )
765                        imcb_log( ic, "BitlBee thinks your display name is `%s' but "
766                                      "the MSN server says it's `%s'. Using the MSN "
767                                      "server's name. Set local_display_name to true "
768                                      "to use the local name.", s->value, name );
769               
770                if( g_utf8_validate( name, -1, NULL ) )
771                {
772                        g_free( s->value );
773                        s->value = g_strdup( name );
774                }
775                else
776                {
777                        imcb_log( ic, "Warning: Friendly name in server response was corrupted" );
778                }
779               
780                return TRUE;
781        }
782}
Note: See TracBrowser for help on using the repository browser.