Changeset 75c3ff7 for protocols/purple


Ignore:
Timestamp:
2010-05-21T00:09:29Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
2c5fabc
Parents:
e7dc02a
Message:

Fixed sending with proper filenames by creating a temporary directory with
the file in it; protocol modules are mostly hardcoded to use the filename
from the filesystem with no way to override this.

Also improved robustness a little bit.

Location:
protocols/purple
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/ft.c

    re7dc02a r75c3ff7  
    4040        struct im_connection *ic;
    4141        int fd;
    42         char *fn, *orig_fn, *handle;
     42        char *fn, *handle;
    4343        gboolean ui_wants_data;
    4444};
     
    8989                xfer->ui_data = px;
    9090                px->xfer = xfer;
    91                
    92                 purple_xfer_set_filename( xfer, px->orig_fn );
    93                 purple_xfer_set_local_filename( xfer, px->fn );
    9491               
    9592                next_ft = NULL;
     
    152149        if( lseek( px->fd, 0, SEEK_CUR ) == px->xfer->size )
    153150        {
    154                 purple_xfer_end( px->xfer );
     151                /*purple_xfer_end( px->xfer );*/
    155152                imcb_file_finished( ft );
    156153        }
     
    177174       
    178175        g_free( px->fn );
    179         g_free( px->orig_fn );
    180176        g_free( px->handle );
    181177        if( px->fd >= 0 )
     
    195191                if( *px->fn )
    196192                {
    197                         //unlink( px->fn );
     193                        char *slash;
     194                       
     195                        unlink( px->fn );
     196                        if( ( slash = strrchr( px->fn, '/' ) ) )
     197                        {
     198                                *slash = '\0';
     199                                rmdir( px->fn );
     200                        }
    198201                        *px->fn = '\0';
    199202                }
     
    226229        struct prpl_xfer_data *px = xfer->ui_data;
    227230       
    228         imcb_file_canceled( px->ft, "Canceled by remote end" );
    229 }
    230 
    231 static 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         }
     231        if( px->ft )
     232                imcb_file_canceled( px->ft, "Canceled by remote end" );
     233        else
     234                /* px->ft == NULL for sends, because of the two stages. :-/ */
     235                imcb_error( px->ic, "File transfer cancelled by remote end" );
    239236}
    240237
     
    252249{
    253250        struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
     251        char *dir, *basename;
    254252       
    255253        ft->data = px;
    256254        px->ft = ft;
    257         px->fn = g_strdup( "/tmp/bitlbee-purple-ft.XXXXXX" );
    258         px->fd = mkstemp( px->fn );
     255       
     256        dir = g_strdup( "/tmp/bitlbee-purple-ft.XXXXXX" );
     257        if( !mkdtemp( dir ) )
     258        {
     259                imcb_error( ic, "Could not create temporary file for file transfer" );
     260                g_free( px );
     261                g_free( dir );
     262                return;
     263        }
     264       
     265        if( ( basename = strrchr( ft->file_name, '/' ) ) )
     266                basename++;
     267        else
     268                basename = ft->file_name;
     269        px->fn = g_strdup_printf( "%s/%s", dir, basename );
     270        px->fd = open( px->fn, O_WRONLY | O_CREAT, 0600 );
     271        g_free( dir );
     272       
     273        if( px->fd < 0 )
     274        {
     275                imcb_error( ic, "Could not create temporary file for file transfer" );
     276                g_free( px );
     277                g_free( px->fn );
     278                return;
     279        }
    259280       
    260281        px->ic = ic;
    261282        px->handle = g_strdup( handle );
    262         px->orig_fn = g_strdup( ft->file_name );
    263283       
    264284        imcb_log( ic, "Due to libpurple limitations, the file has to be cached locally before proceeding with the actual file transfer. Please wait..." );
     
    324344        prplcb_xfer_new,
    325345        prplcb_xfer_destroy,
    326         prplcb_xfer_add,
     346        NULL, /* prplcb_xfer_add, */
    327347        prplcb_xfer_progress,
    328348        prplcb_xfer_dbg,
  • protocols/purple/purple.c

    re7dc02a r75c3ff7  
    841841        purple_notify_set_ui_ops( &bee_notify_uiops );
    842842        purple_xfers_set_ui_ops( &bee_xfer_uiops );
    843         //purple_debug_set_ui_ops( &bee_debug_uiops );
     843        purple_debug_set_ui_ops( &bee_debug_uiops );
    844844}
    845845
Note: See TracChangeset for help on using the changeset viewer.