Changeset 8e9e2b7 for protocols/msn/sb.c


Ignore:
Timestamp:
2010-10-03T02:45:26Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
04f0c10
Parents:
88de0c9 (diff), 2af3e23 (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 mainline, which includes a huge msnp13 merge.

Not 100% sure about the OpenSSL merge, should double check that but I'm
currently offline.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/sb.c

    r88de0c9 r8e9e2b7  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2005 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    2727#include "nogaim.h"
    2828#include "msn.h"
    29 #include "passport.h"
    3029#include "md5.h"
     30#include "soap.h"
    3131#include "invitation.h"
    3232
    3333static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond );
    34 static int msn_sb_command( gpointer data, char **cmd, int num_parts );
    35 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );
    36 
    37 int msn_sb_write( struct msn_switchboard *sb, char *s, int len )
    38 {
     34static int msn_sb_command( struct msn_handler_data *handler, char **cmd, int num_parts );
     35static int msn_sb_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts );
     36
     37int msn_sb_write( struct msn_switchboard *sb, const char *fmt, ... )
     38{
     39        va_list params;
     40        char *out;
     41        size_t len;
    3942        int st;
    4043       
    41         st = write( sb->fd, s, len );
     44        va_start( params, fmt );
     45        out = g_strdup_vprintf( fmt, params );
     46        va_end( params );
     47       
     48        if( getenv( "BITLBEE_DEBUG" ) )
     49                fprintf( stderr, "->SB%d:%s", sb->fd, out );
     50       
     51        len = strlen( out );
     52        st = write( sb->fd, out, len );
     53        g_free( out );
    4254        if( st != len )
    4355        {
    4456                msn_sb_destroy( sb );
    45                 return( 0 );
    46         }
    47        
    48         return( 1 );
     57                return 0;
     58        }
     59       
     60        return 1;
    4961}
    5062
     
    5365        struct msn_data *md = ic->proto_data;
    5466        struct msn_switchboard *sb;
    55         char buf[1024];
    5667
    5768        /* FIXME: *CHECK* the reliability of using spare sb's! */
     
    6172               
    6273                sb->who = g_strdup( m->who );
    63                 g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, m->who );
    64                 if( msn_sb_write( sb, buf, strlen( buf ) ) )
     74                if( msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, m->who ) )
    6575                {
    6676                        /* He/She should join the switchboard soon, let's queue the message. */
     
    7383       
    7484        /* If we reach this line, there was no spare switchboard, so let's make one. */
    75         g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
    76         if( !msn_write( ic, buf, strlen( buf ) ) )
     85        if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) )
    7786        {
    7887                g_free( m->who );
     
    165174        if( sb->ready )
    166175        {
    167                 char *packet, *buf;
     176                char *buf;
    168177                int i, j;
    169178               
     
    201210               
    202211                /* Build the final packet (MSG command + the message). */
    203                 packet = g_strdup_printf( "MSG %d N %d\r\n%s", ++sb->trId, i, buf );
    204                 g_free( buf );
    205                 if( msn_sb_write( sb, packet, strlen( packet ) ) )
    206                 {
    207                         g_free( packet );
    208                         return( 1 );
     212                if( msn_sb_write( sb, "MSG %d N %d\r\n%s", ++sb->trId, i, buf ) )
     213                {
     214                        g_free( buf );
     215                        return 1;
    209216                }
    210217                else
    211218                {
    212                         g_free( packet );
    213                         return( 0 );
     219                        g_free( buf );
     220                        return 0;
    214221                }
    215222        }
     
    326333                g_snprintf( buf, sizeof( buf ), "ANS %d %s %s %d\r\n", ++sb->trId, ic->acc->user, sb->key, sb->session );
    327334       
    328         if( msn_sb_write( sb, buf, strlen( buf ) ) )
     335        if( msn_sb_write( sb, "%s", buf ) )
    329336                sb->inp = b_input_add( sb->fd, B_EV_IO_READ, msn_sb_callback, sb );
    330337        else
     
    346353        {
    347354                time_t now = time( NULL );
    348                 char buf[1024];
    349355               
    350356                if( now - md->first_sb_failure > 600 )
     
    378384                debug( "Moved queued messages back to the main queue, "
    379385                       "creating a new switchboard to retry." );
    380                 g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId );
    381                 if( !msn_write( ic, buf, strlen( buf ) ) )
     386                if( !msn_ns_write( ic, -1, "XFR %d SB\r\n", ++md->trId ) )
    382387                        return FALSE;
    383388        }
     
    387392}
    388393
    389 static int msn_sb_command( gpointer data, char **cmd, int num_parts )
    390 {
    391         struct msn_switchboard *sb = data;
     394static int msn_sb_command( struct msn_handler_data *handler, char **cmd, int num_parts )
     395{
     396        struct msn_switchboard *sb = handler->data;
    392397        struct im_connection *ic = sb->ic;
    393         char buf[1024];
    394398       
    395399        if( !num_parts )
     
    407411        else if( strcmp( cmd[0], "USR" ) == 0 )
    408412        {
    409                 if( num_parts != 5 )
     413                if( num_parts < 5 )
    410414                {
    411415                        msn_sb_destroy( sb );
     
    420424               
    421425                if( sb->who )
    422                 {
    423                         g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, sb->who );
    424                         return( msn_sb_write( sb, buf, strlen( buf ) ) );
    425                 }
     426                        return msn_sb_write( sb, "CAL %d %s\r\n", ++sb->trId, sb->who );
    426427                else
    427                 {
    428428                        debug( "Just created a switchboard, but I don't know what to do with it." );
    429                 }
    430429        }
    431430        else if( strcmp( cmd[0], "IRO" ) == 0 )
     
    433432                int num, tot;
    434433               
    435                 if( num_parts != 6 )
     434                if( num_parts < 6 )
    436435                {
    437436                        msn_sb_destroy( sb );
     
    470469        else if( strcmp( cmd[0], "ANS" ) == 0 )
    471470        {
    472                 if( num_parts != 3 )
     471                if( num_parts < 3 )
    473472                {
    474473                        msn_sb_destroy( sb );
     
    489488        else if( strcmp( cmd[0], "CAL" ) == 0 )
    490489        {
    491                 if( num_parts != 4 || !isdigit( cmd[3][0] ) )
     490                if( num_parts < 4 || !isdigit( cmd[3][0] ) )
    492491                {
    493492                        msn_sb_destroy( sb );
     
    499498        else if( strcmp( cmd[0], "JOI" ) == 0 )
    500499        {
    501                 if( num_parts != 3 )
     500                if( num_parts < 3 )
    502501                {
    503502                        msn_sb_destroy( sb );
     
    560559        else if( strcmp( cmd[0], "MSG" ) == 0 )
    561560        {
    562                 if( num_parts != 4 )
     561                if( num_parts < 4 )
    563562                {
    564563                        msn_sb_destroy( sb );
     
    625624                const struct msn_status_code *err = msn_status_by_number( num );
    626625               
    627                 imcb_error( ic, "Error reported by switchboard server: %s", err->text );
     626                /* If the person is offline, send an offline message instead,
     627                   and don't report an error. */
     628                if( num == 217 )
     629                        msn_soap_oim_send_queue( ic, &sb->msgq );
     630                else
     631                        imcb_error( ic, "Error reported by switchboard server: %s", err->text );
    628632               
    629633                if( err->flags & STATUS_SB_FATAL )
     
    661665}
    662666
    663 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts )
    664 {
    665         struct msn_switchboard *sb = data;
     667static int msn_sb_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts )
     668{
     669        struct msn_switchboard *sb = handler->data;
    666670        struct im_connection *ic = sb->ic;
    667671        char *body;
     
    741745                else if( g_strncasecmp( ct, "application/x-msnmsgrp2p", 24 ) == 0 )
    742746                {
    743                         imcb_error( sb->ic, "Cannot receive file from %s: BitlBee does not "
    744                                         "support msnmsgrp2p yet.", sb->who );
     747                        /* Not currently implemented. Don't warn about it since
     748                           this seems to be used for avatars now. */
    745749                        g_free( ct );
    746750                }
Note: See TracChangeset for help on using the changeset viewer.