Changeset edfc6db


Ignore:
Timestamp:
2010-03-23T01:06:25Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a897467
Parents:
c735200
Message:

Frankenstein, it lives!

This stuff can send files but it has troubles with certain protocol modules,
don't rely on this yet.

It's also getting too messy and should be split off into a separate file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    rc735200 redfc6db  
    365365}
    366366
     367void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle );
     368
    367369static void purple_ui_init();
    368370
     
    665667};
    666668
     669
    667670struct prpl_xfer_data
    668671{
     
    670673        file_transfer_t *ft;
    671674        gint ready_timer;
    672 };
     675        char *buf;
     676        int buf_len;
     677};
     678
     679static file_transfer_t *next_ft;
    673680
    674681/* Glorious hack: We seem to have to remind at least some libpurple plugins
     
    677684static gboolean prplcb_xfer_write_request_cb( gpointer data, gint fd, b_input_condition cond )
    678685{
    679         purple_xfer_ui_ready( data );
    680         return TRUE;
     686        struct prpl_xfer_data *px = data;
     687       
     688        purple_xfer_ui_ready( px->xfer );
     689       
     690        return purple_xfer_get_type( px->xfer ) == PURPLE_XFER_RECEIVE;
    681691}
    682692
     
    684694{
    685695        struct prpl_xfer_data *px = ft->data;
    686         px->ready_timer = b_timeout_add( 100, prplcb_xfer_write_request_cb, px->xfer );
     696        px->ready_timer = b_timeout_add( 100, prplcb_xfer_write_request_cb, px );
    687697        return TRUE;
    688698}
     
    702712       
    703713        return st ? size : 0;
     714}
     715
     716static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len )
     717{
     718        struct prpl_xfer_data *px = ft->data;
     719       
     720        px->buf = g_memdup( buffer, len );
     721        px->buf_len = len;
     722       
     723        //purple_xfer_ui_ready( px->xfer );
     724        px->ready_timer = b_timeout_add( 0, prplcb_xfer_write_request_cb, px );
     725       
     726        return TRUE;
    704727}
    705728
     
    717740}
    718741
    719 static gboolean prplcb_xfer_new_cb( gpointer data, gint fd, b_input_condition cond )
     742static gboolean prplcb_xfer_new_send_cb( gpointer data, gint fd, b_input_condition cond )
    720743{
    721744        PurpleXfer *xfer = data;
     
    744767static void prplcb_xfer_new( PurpleXfer *xfer )
    745768{
    746         /* This should suppress the stupid file dialog. */
    747         purple_xfer_set_local_filename( xfer, "/tmp/wtf123" );
    748        
    749         /* Sadly the xfer struct is still empty ATM so come back after
    750            the caller is done. */
    751         b_timeout_add( 0, prplcb_xfer_new_cb, xfer );
     769        if( purple_xfer_get_type( xfer ) == PURPLE_XFER_RECEIVE )
     770        {
     771                /* This should suppress the stupid file dialog. */
     772                purple_xfer_set_local_filename( xfer, "/tmp/wtf123" );
     773               
     774                /* Sadly the xfer struct is still empty ATM so come back after
     775                   the caller is done. */
     776                b_timeout_add( 0, prplcb_xfer_new_send_cb, xfer );
     777        }
     778        else
     779        {
     780                struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
     781               
     782                px->ft = next_ft;
     783                px->ft->data = px;
     784                px->xfer = xfer;
     785                px->xfer->ui_data = px;
     786               
     787                purple_xfer_set_filename( xfer, px->ft->file_name );
     788                purple_xfer_set_size( xfer, px->ft->file_size );
     789               
     790                next_ft = NULL;
     791        }
     792}
     793
     794static void prplcb_xfer_dbg( PurpleXfer *xfer )
     795{
     796        fprintf( stderr, "prplcb_xfer_dbg 0x%p\n", xfer );
     797}
     798
     799gssize prplcb_xfer_read( PurpleXfer *xfer, guchar **buffer, gssize size )
     800{
     801        struct prpl_xfer_data *px = xfer->ui_data;
     802       
     803        fprintf( stderr, "xfer_read %d %d\n", size, px->buf_len );
     804
     805        if( px->buf )
     806        {
     807                *buffer = px->buf;
     808                px->buf = NULL;
     809               
     810                px->ft->write_request( px->ft );
     811               
     812                return px->buf_len;
     813        }
     814       
     815        return 0;
    752816}
    753817
     
    755819{
    756820        prplcb_xfer_new,
    757         NULL,
    758         NULL,
    759         NULL,
    760         NULL,
    761         NULL,
     821        prplcb_xfer_dbg,
     822        prplcb_xfer_dbg,
     823        prplcb_xfer_dbg,
     824        prplcb_xfer_dbg,
     825        prplcb_xfer_dbg,
    762826        prplcb_xfer_write,
    763 };
     827        prplcb_xfer_read,
     828        prplcb_xfer_dbg,
     829};
     830
     831static gboolean prplcb_xfer_send_cb( gpointer data, gint fd, b_input_condition cond );
     832
     833void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle )
     834{
     835        PurpleAccount *pa = ic->proto_data;
     836        struct prpl_xfer_data *px;
     837       
     838        /* xfer_new() will pick up this variable. It's a hack but we're not
     839           multi-threaded anyway. */
     840        next_ft = ft;
     841        serv_send_file( purple_account_get_connection( pa ), handle, ft->file_name );
     842       
     843        ft->write = prpl_xfer_write;
     844       
     845        px = ft->data;
     846        imcb_file_recv_start( ft );
     847       
     848        px->ready_timer = b_timeout_add( 100, prplcb_xfer_send_cb, px );
     849}
     850
     851static gboolean prplcb_xfer_send_cb( gpointer data, gint fd, b_input_condition cond )
     852{
     853        struct prpl_xfer_data *px = data;
     854       
     855        if( px->ft->status & FT_STATUS_TRANSFERRING )
     856        {
     857                fprintf( stderr, "The ft, it is ready...\n" );
     858                px->ft->write_request( px->ft );
     859               
     860                return FALSE;
     861        }
     862       
     863        return TRUE;
     864}
    764865
    765866static void purple_ui_init()
     
    771872        purple_notify_set_ui_ops( &bee_notify_uiops );
    772873        purple_xfers_set_ui_ops( &bee_xfer_uiops );
    773         //purple_debug_set_ui_ops( &bee_debug_uiops );
     874        purple_debug_set_ui_ops( &bee_debug_uiops );
    774875}
    775876
     
    817918        funcs.send_typing = purple_send_typing;
    818919        funcs.handle_cmp = g_strcasecmp;
     920        /* TODO(wilmer): Set this one only for protocols that support it? */
     921        funcs.transfer_request = purple_transfer_request;
    819922       
    820923        help = g_string_new("BitlBee libpurple module supports the following IM protocols:\n");
Note: See TracChangeset for help on using the changeset viewer.