Changeset 553767c


Ignore:
Timestamp:
2010-05-17T20:30:45Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
8822d23
Parents:
2309152
Message:

Move direct ft stuff to an unused file: This gets too hairy and too fragile.
I don't have time to work out all the details, I doubt if this is supposed
to work reliably yet at all. Let's go for the simple via-disk approach for
now.

Location:
protocols/purple
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/ft.c

    r2309152 r553767c  
    2222\***************************************************************************/
    2323
     24/* Do file transfers via disk for now, since libpurple was really designed
     25   for straight-to/from disk fts and is only just learning how to pass the
     26   file contents the the UI instead (2.6.0 and higher it seems, and with
     27   varying levels of success). */
     28
    2429#include "bitlbee.h"
    2530
     
    4247struct im_connection *purple_ic_by_pa( PurpleAccount *pa );
    4348
    44 /* Glorious hack: We seem to have to remind at least some libpurple plugins
    45    that we're ready because this info may get lost if we give it too early.
    46    So just do it ten times a second. :-/ */
    47 static gboolean prplcb_xfer_write_request_cb( gpointer data, gint fd, b_input_condition cond )
    48 {
    49         struct prpl_xfer_data *px = data;
    50        
    51         purple_xfer_ui_ready( px->xfer );
    52        
    53         return purple_xfer_get_type( px->xfer ) == PURPLE_XFER_RECEIVE;
    54 }
    55 
    5649static gboolean prpl_xfer_write_request( struct file_transfer *ft )
    5750{
    58         struct prpl_xfer_data *px = ft->data;
    59         px->ready_timer = b_timeout_add( 100, prplcb_xfer_write_request_cb, px );
    60         return TRUE;
     51        return FALSE;
    6152}
    6253
     
    6556        struct prpl_xfer_data *px = ft->data;
    6657       
    67         px->buf = g_memdup( buffer, len );
    68         px->buf_len = len;
    69 
    70         //purple_xfer_ui_ready( px->xfer );
    71         px->ready_timer = b_timeout_add( 0, prplcb_xfer_write_request_cb, px );
    72        
    73         return TRUE;
     58        return FALSE;
    7459}
    7560
     
    8570        struct prpl_xfer_data *px = ft->data;
    8671        purple_xfer_request_denied( px->xfer );
     72}
     73
     74static gboolean prplcb_xfer_new_send_cb( gpointer data, gint fd, b_input_condition cond );
     75
     76static void prplcb_xfer_new( PurpleXfer *xfer )
     77{
     78        if( purple_xfer_get_type( xfer ) == PURPLE_XFER_RECEIVE )
     79        {
     80                /* This should suppress the stupid file dialog. */
     81                purple_xfer_set_local_filename( xfer, "/tmp/wtf123" );
     82               
     83                /* Sadly the xfer struct is still empty ATM so come back after
     84                   the caller is done. */
     85                b_timeout_add( 0, prplcb_xfer_new_send_cb, xfer );
     86        }
     87        else
     88        {
     89                /*
     90                struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
     91               
     92                px->ft = next_ft;
     93                px->ft->data = px;
     94                px->xfer = xfer;
     95                px->xfer->ui_data = px;
     96               
     97                purple_xfer_set_filename( xfer, px->ft->file_name );
     98                purple_xfer_set_size( xfer, px->ft->file_size );
     99               
     100                next_ft = NULL;
     101                */
     102        }
    87103}
    88104
     
    112128}
    113129
    114 static void prplcb_xfer_new( PurpleXfer *xfer )
    115 {
    116         if( purple_xfer_get_type( xfer ) == PURPLE_XFER_RECEIVE )
    117         {
    118                 /* This should suppress the stupid file dialog. */
    119                 purple_xfer_set_local_filename( xfer, "/tmp/wtf123" );
    120                
    121                 /* Sadly the xfer struct is still empty ATM so come back after
    122                    the caller is done. */
    123                 b_timeout_add( 0, prplcb_xfer_new_send_cb, xfer );
    124         }
    125         else
    126         {
    127                 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
    128                
    129                 px->ft = next_ft;
    130                 px->ft->data = px;
    131                 px->xfer = xfer;
    132                 px->xfer->ui_data = px;
    133                
    134                 purple_xfer_set_filename( xfer, px->ft->file_name );
    135                 purple_xfer_set_size( xfer, px->ft->file_size );
    136                
    137                 next_ft = NULL;
    138         }
    139 }
    140 
    141130static void prplcb_xfer_progress( PurpleXfer *xfer, double percent )
    142131{
     
    149138}
    150139
    151 static gssize prplcb_xfer_write( PurpleXfer *xfer, const guchar *buffer, gssize size )
    152 {
    153         struct prpl_xfer_data *px = xfer->ui_data;
    154         gboolean st;
    155        
    156         fprintf( stderr, "xfer_write %d %d\n", size, px->buf_len );
    157        
    158         b_event_remove( px->ready_timer );
    159         px->ready_timer = 0;
    160        
    161         st = px->ft->write( px->ft, (char*) buffer, size );
    162        
    163         if( st && xfer->bytes_remaining == size )
    164                 imcb_file_finished( px->ft );
    165        
    166         return st ? size : 0;
    167 }
    168 
    169 gssize prplcb_xfer_read( PurpleXfer *xfer, guchar **buffer, gssize size )
    170 {
    171         struct prpl_xfer_data *px = xfer->ui_data;
    172        
    173         fprintf( stderr, "xfer_read %d %d\n", size, px->buf_len );
    174 
    175         if( px->buf )
    176         {
    177                 *buffer = px->buf;
    178                 px->buf = NULL;
    179                
    180                 px->ft->write_request( px->ft );
    181                
    182                 return px->buf_len;
    183         }
    184        
    185         return 0;
    186 }
    187 
    188140PurpleXferUiOps bee_xfer_uiops =
    189141{
     
    194146        prplcb_xfer_dbg,
    195147        prplcb_xfer_dbg,
    196         prplcb_xfer_write,
    197         prplcb_xfer_read,
     148        NULL,
     149        NULL,
    198150        prplcb_xfer_dbg,
    199151};
     
    215167        px = ft->data;
    216168        imcb_file_recv_start( ft );
    217        
    218         px->ready_timer = b_timeout_add( 100, prplcb_xfer_send_cb, px );
    219169}
    220 
    221 static gboolean prplcb_xfer_send_cb( gpointer data, gint fd, b_input_condition cond )
    222 {
    223         struct prpl_xfer_data *px = data;
    224        
    225         if( px->ft->status & FT_STATUS_TRANSFERRING )
    226         {
    227                 fprintf( stderr, "The ft, it is ready...\n" );
    228                 px->ft->write_request( px->ft );
    229                
    230                 return FALSE;
    231         }
    232        
    233         return TRUE;
    234 }
Note: See TracChangeset for help on using the changeset viewer.