Changeset ae3dc99 for protocols/msn


Ignore:
Timestamp:
2010-04-24T17:02:07Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
c521362
Parents:
b5b40ff (diff), f1b7711 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging stuff from mainline (1.2.6).

Location:
protocols/msn
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    rb5b40ff rae3dc99  
    3131GSList *msn_switchboards;
    3232
    33 static char *msn_set_display_name( set_t *set, char *value );
     33static char *set_eval_display_name( set_t *set, char *value );
    3434
    3535static void msn_init( account_t *acc )
    3636{
    37         set_t *s;
    38        
    39         s = set_add( &acc->set, "display_name", NULL, msn_set_display_name, acc );
    40         s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY;
    41 
    42         s = set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
     37        set_add( &acc->set, "display_name", NULL, set_eval_display_name, acc );
     38        set_add( &acc->set, "local_display_name", "false", set_eval_bool, acc );
     39        set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
     40        set_add( &acc->set, "switchboard_keepalives", "false", set_eval_bool, acc );
    4341}
    4442
     
    171169static void msn_set_my_name( struct im_connection *ic, char *info )
    172170{
    173         msn_set_display_name( set_find( &ic->acc->set, "display_name" ), info );
     171        msn_set_display_name( ic, info );
    174172}
    175173
     
    287285}
    288286
    289 static char *msn_set_display_name( set_t *set, char *value )
     287static char *set_eval_display_name( set_t *set, char *value )
    290288{
    291289        account_t *acc = set->data;
    292290        struct im_connection *ic = acc->ic;
    293         struct msn_data *md;
    294         char buf[1024], *fn;
    295        
    296         /* Double-check. */
     291       
     292        /* Allow any name if we're offline. */
    297293        if( ic == NULL )
    298                 return NULL;
    299        
    300         md = ic->proto_data;
     294                return value;
    301295       
    302296        if( strlen( value ) > 129 )
     
    305299                return NULL;
    306300        }
    307        
    308         fn = msn_http_encode( value );
    309        
    310         g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn );
    311         msn_write( ic, buf, strlen( buf ) );
    312         g_free( fn );
    313301       
    314302        /* Returning NULL would be better, because the server still has to
    315303           confirm the name change. However, it looks a bit confusing to the
    316304           user. */
    317         return value;
     305        return msn_set_display_name( ic, value ) ? value : NULL;
    318306}
    319307
  • protocols/msn/msn.h

    rb5b40ff rae3dc99  
    3131#define TYPING_NOTIFICATION_MESSAGE "\r\r\rBEWARE, ME R TYPINK MESSAGE!!!!\r\r\r"
    3232#define GROUPCHAT_SWITCHBOARD_MESSAGE "\r\r\rME WANT TALK TO MANY PEOPLE\r\r\r"
     33#define SB_KEEPALIVE_MESSAGE "\r\r\rDONT HANG UP ON ME!\r\r\r"
    3334
    3435#ifdef DEBUG_MSN
     
    5354                           "TypingUser: %s\r\n" \
    5455                           "\r\n\r\n"
     56
     57#define SB_KEEPALIVE_HEADERS "MIME-Version: 1.0\r\n" \
     58                             "Content-Type: text/x-ping\r\n" \
     59                             "\r\n\r\n"
    5560
    5661#define PROFILE_URL "http://members.msn.com/"
     
    8489        gint inp;
    8590        struct msn_handler_data *handler;
     91        gint keepalive;
    8692       
    8793        int trId;
     
    162168char *msn_http_encode( const char *input );
    163169void msn_msgq_purge( struct im_connection *ic, GSList **list );
     170gboolean msn_set_display_name( struct im_connection *ic, const char *rawname );
    164171
    165172/* tables.c */
     
    180187gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond );
    181188int msn_sb_write_msg( struct im_connection *ic, struct msn_message *m );
     189void msn_sb_start_keepalives( struct msn_switchboard *sb, gboolean initial );
     190void msn_sb_stop_keepalives( struct msn_switchboard *sb );
    182191
    183192/* invitation.c */
  • protocols/msn/msn_util.c

    rb5b40ff rae3dc99  
    3838                imcb_error( ic, "Short write() to main server" );
    3939                imc_logout( ic, TRUE );
    40                 return( 0 );
    41         }
    42        
    43         return( 1 );
     40                return 0;
     41        }
     42       
     43        return 1;
    4444}
    4545
     
    377377        g_string_free( ret, TRUE );
    378378}
     379
     380gboolean msn_set_display_name( struct im_connection *ic, const char *rawname )
     381{
     382        char *fn = msn_http_encode( rawname );
     383        struct msn_data *md = ic->proto_data;
     384        char buf[1024];
     385       
     386        g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn );
     387        g_free( fn );
     388       
     389        return msn_write( ic, buf, strlen( buf ) ) != 0;
     390}
  • protocols/msn/ns.c

    rb5b40ff rae3dc99  
    3535
    3636static void msn_auth_got_passport_token( struct msn_auth_data *mad );
     37static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name );
    3738
    3839gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond )
     
    231232                else if( num_parts >= 7 && strcmp( cmd[2], "OK" ) == 0 )
    232233                {
    233                         set_t *s;
    234                        
    235234                        if( num_parts == 7 )
    236                         {
    237                                 http_decode( cmd[4] );
    238                                
    239                                 strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) );
    240                                 ic->displayname[sizeof(ic->displayname)-1] = 0;
    241                                
    242                                 if( ( s = set_find( &ic->acc->set, "display_name" ) ) )
    243                                 {
    244                                         g_free( s->value );
    245                                         s->value = g_strdup( cmd[4] );
    246                                 }
    247                         }
     235                                msn_ns_got_display_name( ic, cmd[4] );
    248236                        else
    249                         {
    250237                                imcb_log( ic, "Warning: Friendly name in server response was corrupted" );
    251                         }
    252238                       
    253239                        imcb_log( ic, "Authenticated, getting buddy list" );
     
    436422        else if( strcmp( cmd[0], "FLN" ) == 0 )
    437423        {
    438                 if( cmd[1] )
    439                         imcb_buddy_status( ic, cmd[1], 0, NULL, NULL );
     424                if( cmd[1] == NULL )
     425                        return 1;
     426               
     427                imcb_buddy_status( ic, cmd[1], 0, NULL, NULL );
     428               
     429                msn_sb_start_keepalives( msn_sb_by_handle( ic, cmd[1] ), TRUE );
    440430        }
    441431        else if( strcmp( cmd[0], "NLN" ) == 0 )
     
    463453                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
    464454                                   st->name, NULL );
     455               
     456                msn_sb_stop_keepalives( msn_sb_by_handle( ic, cmd[2] ) );
    465457        }
    466458        else if( strcmp( cmd[0], "RNG" ) == 0 )
     
    567559                return( 0 );
    568560        }
     561#if 0
     562        /* Discard this one completely for now since I don't care about the ack
     563           and since MSN servers can apparently screw up the formatting. */
    569564        else if( strcmp( cmd[0], "REA" ) == 0 )
    570565        {
     
    597592                }
    598593        }
     594#endif
    599595        else if( strcmp( cmd[0], "IPG" ) == 0 )
    600596        {
     
    746742        }
    747743}
     744
     745static gboolean msn_ns_got_display_name( struct im_connection *ic, char *name )
     746{
     747        set_t *s;
     748       
     749        if( ( s = set_find( &ic->acc->set, "display_name" ) ) == NULL )
     750                return FALSE; /* Shouldn't happen.. */
     751       
     752        http_decode( name );
     753       
     754        if( s->value && strcmp( s->value, name ) == 0 )
     755        {
     756                return TRUE;
     757                /* The names match, nothing to worry about. */
     758        }
     759        else if( s->value != NULL &&
     760                 ( strcmp( name, ic->acc->user ) == 0 ||
     761                   set_getbool( &ic->acc->set, "local_display_name" ) ) )
     762        {
     763                /* The server thinks our display name is our e-mail address
     764                   which is probably wrong, or the user *wants* us to do this:
     765                   Always use the locally set display_name. */
     766                return msn_set_display_name( ic, s->value );
     767        }
     768        else
     769        {
     770                if( s->value && *s->value )
     771                        imcb_log( ic, "BitlBee thinks your display name is `%s' but "
     772                                      "the MSN server says it's `%s'. Using the MSN "
     773                                      "server's name. Set local_display_name to true "
     774                                      "to use the local name.", s->value, name );
     775               
     776                if( g_utf8_validate( name, -1, NULL ) )
     777                {
     778                        g_free( s->value );
     779                        s->value = g_strdup( name );
     780                }
     781                else
     782                {
     783                        imcb_log( ic, "Warning: Friendly name in server response was corrupted" );
     784                }
     785               
     786                return TRUE;
     787        }
     788}
  • protocols/msn/sb.c

    rb5b40ff rae3dc99  
    180180                        i = strlen( buf );
    181181                }
     182                else if( strcmp( text, SB_KEEPALIVE_MESSAGE ) == 0 )
     183                {
     184                        buf = g_strdup( SB_KEEPALIVE_HEADERS );
     185                        i = strlen( buf );
     186                }
    182187                else
    183188                {
     
    256261       
    257262        msn_msgq_purge( ic, &sb->msgq );
     263        msn_sb_stop_keepalives( sb );
    258264       
    259265        if( sb->key ) g_free( sb->key );
     
    477483               
    478484                sb->ready = 1;
     485               
     486                msn_sb_start_keepalives( sb, FALSE );
    479487        }
    480488        else if( strcmp( cmd[0], "CAL" ) == 0 )
     
    526534                        }
    527535                       
     536                        msn_sb_start_keepalives( sb, FALSE );
     537                       
    528538                        return( st );
    529539                }
     
    587597                if( sb->who )
    588598                {
     599                        msn_sb_stop_keepalives( sb );
     600                       
    589601                        /* This is a single-person chat, and the other person is leaving. */
    590602                        g_free( sb->who );
     
    749761        return( 1 );
    750762}
     763
     764static gboolean msn_sb_keepalive( gpointer data, gint source, b_input_condition cond )
     765{
     766        struct msn_switchboard *sb = data;
     767        return sb->ready && msn_sb_sendmessage( sb, SB_KEEPALIVE_MESSAGE );
     768}
     769
     770void msn_sb_start_keepalives( struct msn_switchboard *sb, gboolean initial )
     771{
     772        struct buddy *b;
     773       
     774        if( sb && sb->who && sb->keepalive == 0 &&
     775            ( b = imcb_find_buddy( sb->ic, sb->who ) ) && !b->present &&
     776            set_getbool( &sb->ic->acc->set, "switchboard_keepalives" ) )
     777        {
     778                if( initial )
     779                        msn_sb_keepalive( sb, 0, 0 );
     780               
     781                sb->keepalive = b_timeout_add( 20000, msn_sb_keepalive, sb );
     782        }
     783}
     784
     785void msn_sb_stop_keepalives( struct msn_switchboard *sb )
     786{
     787        if( sb && sb->keepalive > 0 )
     788        {
     789                b_event_remove( sb->keepalive );
     790                sb->keepalive = 0;
     791        }
     792}
Note: See TracChangeset for help on using the changeset viewer.