Changeset e7dc02a for protocols


Ignore:
Timestamp:
2010-05-19T00:57:58Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
75c3ff7
Parents:
31fc06fb
Message:

Similar hacky code to send files. This indirect sending stuff sucks badly
for numerous reasons. Maybe libpurple 2.7.0 is less crappy and will
eventually allow (working) direct ft's again.

This somewhat works, but filename info is lost with some protocols.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/ft.c

    r31fc06fb re7dc02a  
    3838        PurpleXfer *xfer;
    3939        file_transfer_t *ft;
     40        struct im_connection *ic;
    4041        int fd;
    41         char *fn;
     42        char *fn, *orig_fn, *handle;
    4243        gboolean ui_wants_data;
    4344};
     
    8384        else
    8485        {
    85                 /*
    86                 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
    87                
    88                 px->fd = -1;
    89                 px->ft = next_ft;
    90                 px->ft->data = px;
     86                struct file_transfer *ft = next_ft;
     87                struct prpl_xfer_data *px = ft->data;
     88               
     89                xfer->ui_data = px;
    9190                px->xfer = xfer;
    92                 px->xfer->ui_data = px;
    93                
    94                 purple_xfer_set_filename( xfer, px->ft->file_name );
    95                 purple_xfer_set_size( xfer, px->ft->file_size );
     91               
     92                purple_xfer_set_filename( xfer, px->orig_fn );
     93                purple_xfer_set_local_filename( xfer, px->fn );
    9694               
    9795                next_ft = NULL;
    98                 */
    9996        }
    10097}
     
    180177       
    181178        g_free( px->fn );
     179        g_free( px->orig_fn );
     180        g_free( px->handle );
    182181        if( px->fd >= 0 )
    183182                close( px->fd );
     
    188187{
    189188        struct prpl_xfer_data *px = xfer->ui_data;
     189       
     190        if( px == NULL )
     191                return;
     192       
     193        if( purple_xfer_get_type( xfer ) == PURPLE_XFER_SEND )
     194        {
     195                if( *px->fn )
     196                {
     197                        //unlink( px->fn );
     198                        *px->fn = '\0';
     199                }
     200               
     201                return;
     202        }
    190203       
    191204        if( px->fd == -1 && percent > 0 )
     
    216229}
    217230
     231static void prplcb_xfer_add( PurpleXfer *xfer )
     232{
     233        if( purple_xfer_get_type( xfer ) == PURPLE_XFER_SEND )
     234        {
     235                struct prpl_xfer_data *px = xfer->ui_data;
     236               
     237                purple_xfer_set_filename( xfer, px->orig_fn );
     238        }
     239}
     240
    218241static void prplcb_xfer_dbg( PurpleXfer *xfer )
    219242{
     
    223246
    224247/* Sending files (UI->IM): */
    225 static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len )
    226 {
    227         return FALSE;
    228 }
     248static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len );
     249static gboolean purple_transfer_request_cb( gpointer data, gint fd, b_input_condition cond );
    229250
    230251void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle )
    231252{
    232         PurpleAccount *pa = ic->proto_data;
    233         struct prpl_xfer_data *px;
     253        struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
     254       
     255        ft->data = px;
     256        px->ft = ft;
     257        px->fn = g_strdup( "/tmp/bitlbee-purple-ft.XXXXXX" );
     258        px->fd = mkstemp( px->fn );
     259       
     260        px->ic = ic;
     261        px->handle = g_strdup( handle );
     262        px->orig_fn = g_strdup( ft->file_name );
     263       
     264        imcb_log( ic, "Due to libpurple limitations, the file has to be cached locally before proceeding with the actual file transfer. Please wait..." );
     265       
     266        b_timeout_add( 0, purple_transfer_request_cb, ft );
     267}
     268
     269static void purple_transfer_forward( struct file_transfer *ft )
     270{
     271        struct prpl_xfer_data *px = ft->data;
     272        PurpleAccount *pa = px->ic->proto_data;
    234273       
    235274        /* xfer_new() will pick up this variable. It's a hack but we're not
    236275           multi-threaded anyway. */
    237276        next_ft = ft;
    238         serv_send_file( purple_account_get_connection( pa ), handle, ft->file_name );
    239        
    240         ft->write = prpl_xfer_write;
    241        
    242         px = ft->data;
    243         imcb_file_recv_start( ft );
    244 }
    245 
     277        serv_send_file( purple_account_get_connection( pa ), px->handle, px->fn );
     278}
     279
     280static gboolean purple_transfer_request_cb( gpointer data, gint fd, b_input_condition cond )
     281{
     282        file_transfer_t *ft = data;
     283       
     284        if( ft->write == NULL )
     285        {
     286                ft->write = prpl_xfer_write;
     287                imcb_file_recv_start( ft );
     288        }
     289       
     290        ft->write_request( ft );
     291       
     292        return FALSE;
     293}
     294
     295static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len )
     296{
     297        struct prpl_xfer_data *px = ft->data;
     298       
     299        if( write( px->fd, buffer, len ) != len )
     300        {
     301                imcb_file_canceled( ft, "Error while writing temporary file" );
     302                return FALSE;
     303        }
     304       
     305        if( lseek( px->fd, 0, SEEK_CUR ) >= ft->file_size )
     306        {
     307                close( px->fd );
     308                px->fd = -1;
     309               
     310                purple_transfer_forward( ft );
     311                imcb_file_finished( ft );
     312                px->ft = NULL;
     313        }
     314        else
     315                b_timeout_add( 0, purple_transfer_request_cb, ft );
     316       
     317        return TRUE;
     318}
    246319
    247320
     
    251324        prplcb_xfer_new,
    252325        prplcb_xfer_destroy,
    253         prplcb_xfer_dbg,
     326        prplcb_xfer_add,
    254327        prplcb_xfer_progress,
    255328        prplcb_xfer_dbg,
Note: See TracChangeset for help on using the changeset viewer.