Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/msn.c

    r17a6ee9 rc6ca3ee  
    8181        if( md )
    8282        {
    83                 /** Disabling MSN ft support for now.
    84                 while( md->filetransfers ) {
    85                         imcb_file_canceled( md->filetransfers->data, "Closing connection" );
    86                 }
    87                 */
    88                
    8983                if( md->fd >= 0 )
    9084                        closesocket( md->fd );
     
    123117{
    124118        struct msn_switchboard *sb;
     119        struct msn_data *md = ic->proto_data;
    125120       
    126121        if( ( sb = msn_sb_by_handle( ic, who ) ) )
     
    131126        {
    132127                struct msn_message *m;
     128                char buf[1024];
    133129               
    134130                /* Create a message. We have to arrange a usable switchboard, and send the message later. */
     
    137133                m->text = g_strdup( message );
    138134               
    139                 return msn_sb_write_msg( ic, m );
     135                /* FIXME: *CHECK* the reliability of using spare sb's! */
     136                if( ( sb = msn_sb_spare( ic ) ) )
     137                {
     138                        debug( "Trying to use a spare switchboard to message %s", who );
     139                       
     140                        sb->who = g_strdup( who );
     141                        g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
     142                        if( msn_sb_write( sb, buf, strlen( buf ) ) )
     143                        {
     144                                /* He/She should join the switchboard soon, let's queue the message. */
     145                                sb->msgq = g_slist_append( sb->msgq, m );
     146                                return( 1 );
     147                        }
     148                }
     149               
     150                debug( "Creating a new switchboard to message %s", who );
     151               
     152                /* If we reach this line, there was no spare switchboard, so let's make one. */
     153                g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
     154                if( !msn_write( ic, buf, strlen( buf ) ) )
     155                {
     156                        g_free( m->who );
     157                        g_free( m->text );
     158                        g_free( m );
     159                       
     160                        return( 0 );
     161                }
     162               
     163                /* And queue the message to md. We'll pick it up when the switchboard comes up. */
     164                md->msgq = g_slist_append( md->msgq, m );
     165               
     166                /* FIXME: If the switchboard creation fails, the message will not be sent. */
     167               
     168                return( 1 );
    140169        }
    141170       
     
    149178       
    150179        if( l == NULL )
    151                 for( i = 0; *msn_away_state_list[i].code; i ++ )
    152                         if( *msn_away_state_list[i].name )
    153                                 l = g_list_append( l, (void*) msn_away_state_list[i].name );
     180                for( i = 0; msn_away_state_list[i].number > -1; i ++ )
     181                        l = g_list_append( l, (void*) msn_away_state_list[i].name );
    154182       
    155183        return l;
     
    160188        char buf[1024];
    161189        struct msn_data *md = ic->proto_data;
    162        
    163         if( state )
    164                 md->away_state = msn_away_state_by_name( state ) ? :
    165                                  msn_away_state_list + 1;
     190        const struct msn_away_state *st;
     191       
     192        if( strcmp( state, GAIM_AWAY_CUSTOM ) == 0 )
     193                st = msn_away_state_by_name( "Away" );
    166194        else
    167                 md->away_state = msn_away_state_list;
    168        
    169         g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, md->away_state->code );
     195                st = msn_away_state_by_name( state );
     196       
     197        if( !st ) st = msn_away_state_list;
     198        md->away_state = st;
     199       
     200        g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, st->code );
    170201        msn_write( ic, buf, strlen( buf ) );
    171202}
     
    225256{
    226257        struct msn_switchboard *sb;
     258        struct msn_data *md = ic->proto_data;
     259        char buf[1024];
    227260       
    228261        if( ( sb = msn_sb_by_handle( ic, who ) ) )
     
    234267        {
    235268                struct msn_message *m;
     269               
     270                if( ( sb = msn_sb_spare( ic ) ) )
     271                {
     272                        debug( "Trying to reuse an existing switchboard as a groupchat with %s", who );
     273                        g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who );
     274                        if( msn_sb_write( sb, buf, strlen( buf ) ) )
     275                                return msn_sb_to_chat( sb );
     276                }
     277               
     278                /* If the stuff above failed for some reason: */
     279                debug( "Creating a new switchboard to groupchat with %s", who );
     280               
     281                /* Request a new switchboard. */
     282                g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
     283                if( !msn_write( ic, buf, strlen( buf ) ) )
     284                        return( 0 );
    236285               
    237286                /* Create a magic message. This is quite hackish, but who cares? :-P */
     
    240289                m->text = g_strdup( GROUPCHAT_SWITCHBOARD_MESSAGE );
    241290               
    242                 msn_sb_write_msg( ic, m );
    243 
     291                /* Queue the magic message and cross your fingers. */
     292                md->msgq = g_slist_append( md->msgq, m );
     293               
     294                /* FIXME: Can I try to return something here already? */
    244295                return NULL;
    245296        }
     
    346397        ret->send_typing = msn_send_typing;
    347398        ret->handle_cmp = g_strcasecmp;
    348         //ret->transfer_request = msn_ftp_transfer_request;
    349399
    350400        register_protocol(ret);
Note: See TracChangeset for help on using the changeset viewer.