Changeset c735200 for protocols/purple


Ignore:
Timestamp:
2010-03-22T01:20:40Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
edfc6db
Parents:
437bd9b
Message:

Incoming file transfers can now be accepted (and should work) and/or
rejected. Tested with Jabber and msn/msn-pecan so far.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    r437bd9b rc735200  
    665665};
    666666
    667 static void prplcb_xfer( PurpleXfer *xfer )
    668 {
    669         fprintf( stderr, "ft bla: 0x%p\n", xfer );
     667struct prpl_xfer_data
     668{
     669        PurpleXfer *xfer;
     670        file_transfer_t *ft;
     671        gint ready_timer;
     672};
     673
     674/* Glorious hack: We seem to have to remind at least some libpurple plugins
     675   that we're ready because this info may get lost if we give it too early.
     676   So just do it ten times a second. :-/ */
     677static gboolean prplcb_xfer_write_request_cb( gpointer data, gint fd, b_input_condition cond )
     678{
     679        purple_xfer_ui_ready( data );
     680        return TRUE;
     681}
     682
     683static gboolean prpl_xfer_write_request( struct file_transfer *ft )
     684{
     685        struct prpl_xfer_data *px = ft->data;
     686        px->ready_timer = b_timeout_add( 100, prplcb_xfer_write_request_cb, px->xfer );
     687        return TRUE;
     688}
     689
     690static gssize prplcb_xfer_write( PurpleXfer *xfer, const guchar *buffer, gssize size )
     691{
     692        struct prpl_xfer_data *px = xfer->ui_data;
     693        gboolean st;
     694       
     695        b_event_remove( px->ready_timer );
     696        px->ready_timer = 0;
     697       
     698        st = px->ft->write( px->ft, (char*) buffer, size );
     699       
     700        if( st && xfer->bytes_remaining == size )
     701                imcb_file_finished( px->ft );
     702       
     703        return st ? size : 0;
    670704}
    671705
    672706static void prpl_xfer_accept( struct file_transfer *ft )
    673707{
    674         purple_xfer_request_accepted( ft->data, NULL );
    675         purple_xfer_ui_ready( ft->data );
    676 }
    677 
    678 static void prpl_xfer_reject( struct file_transfer *ft )
    679 {
    680         purple_xfer_request_denied( ft->data );
     708        struct prpl_xfer_data *px = ft->data;
     709        purple_xfer_request_accepted( px->xfer, NULL );
     710        prpl_xfer_write_request( ft );
     711}
     712
     713static void prpl_xfer_canceled( struct file_transfer *ft, char *reason )
     714{
     715        struct prpl_xfer_data *px = ft->data;
     716        purple_xfer_request_denied( px->xfer );
    681717}
    682718
     
    685721        PurpleXfer *xfer = data;
    686722        struct im_connection *ic = purple_ic_by_pa( xfer->account );
    687         file_transfer_t *ft;
    688        
    689         ft = imcb_file_send_start( ic, xfer->who, xfer->filename, xfer->size );
    690         ft->data = xfer;
    691         xfer->ui_data = ft;
    692        
    693         ft->accept = prpl_xfer_accept;
     723        struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
     724        PurpleBuddy *buddy;
     725        const char *who;
     726       
     727        buddy = purple_find_buddy( xfer->account, xfer->who );
     728        who = buddy ? purple_buddy_get_name( buddy ) : xfer->who;
     729       
     730        /* TODO(wilmer): After spreading some more const goodness in BitlBee,
     731           remove the evil cast below. */
     732        px->ft = imcb_file_send_start( ic, (char*) who, xfer->filename, xfer->size );
     733        px->ft->data = px;
     734        px->xfer = data;
     735        px->xfer->ui_data = px;
     736       
     737        px->ft->accept = prpl_xfer_accept;
     738        px->ft->canceled = prpl_xfer_canceled;
     739        px->ft->write_request = prpl_xfer_write_request;
    694740       
    695741        return FALSE;
     
    698744static void prplcb_xfer_new( PurpleXfer *xfer )
    699745{
     746        /* This should suppress the stupid file dialog. */
    700747        purple_xfer_set_local_filename( xfer, "/tmp/wtf123" );
    701748       
    702         fprintf( stderr, "ft_new bla: 0x%p\n", xfer );
    703        
     749        /* Sadly the xfer struct is still empty ATM so come back after
     750           the caller is done. */
    704751        b_timeout_add( 0, prplcb_xfer_new_cb, xfer );
    705752}
     
    708755{
    709756        prplcb_xfer_new,
    710         prplcb_xfer,
    711         prplcb_xfer,
    712         prplcb_xfer,
    713         prplcb_xfer,
    714         prplcb_xfer,
    715         prplcb_xfer,
    716         prplcb_xfer,
    717         prplcb_xfer,
    718         prplcb_xfer,
     757        NULL,
     758        NULL,
     759        NULL,
     760        NULL,
     761        NULL,
     762        prplcb_xfer_write,
    719763};
    720764
     
    727771        purple_notify_set_ui_ops( &bee_notify_uiops );
    728772        purple_xfers_set_ui_ops( &bee_xfer_uiops );
    729         purple_debug_set_ui_ops( &bee_debug_uiops );
     773        //purple_debug_set_ui_ops( &bee_debug_uiops );
    730774}
    731775
Note: See TracChangeset for help on using the changeset viewer.