Changeset c96c72f


Ignore:
Timestamp:
2010-05-18T00:08:17Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
31fc06fb
Parents:
5d1b3a95
Message:

Little cleanup. Less compiler warnings, and removing tempfile at the
beginning of the download already to make sure it doesn't stick around.

Location:
protocols/purple
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/ft.c

    r5d1b3a95 rc96c72f  
    4646
    4747struct im_connection *purple_ic_by_pa( PurpleAccount *pa );
     48static gboolean prplcb_xfer_new_send_cb( gpointer data, gint fd, b_input_condition cond );
     49static gboolean prpl_xfer_write_request( struct file_transfer *ft );
     50
     51
     52/* Receiving files (IM->UI): */
     53static void prpl_xfer_accept( struct file_transfer *ft )
     54{
     55        struct prpl_xfer_data *px = ft->data;
     56        purple_xfer_request_accepted( px->xfer, NULL );
     57        prpl_xfer_write_request( ft );
     58}
     59
     60static void prpl_xfer_canceled( struct file_transfer *ft, char *reason )
     61{
     62        struct prpl_xfer_data *px = ft->data;
     63        purple_xfer_request_denied( px->xfer );
     64}
     65
     66static void prplcb_xfer_new( PurpleXfer *xfer )
     67{
     68        if( purple_xfer_get_type( xfer ) == PURPLE_XFER_RECEIVE )
     69        {
     70                struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
     71               
     72                xfer->ui_data = px;
     73                px->xfer = xfer;
     74                px->fn = mktemp( g_strdup( "/tmp/bitlbee-purple-ft.XXXXXX" ) );
     75                px->fd = -1;
     76               
     77                purple_xfer_set_local_filename( xfer, px->fn );
     78               
     79                /* Sadly the xfer struct is still empty ATM so come back after
     80                   the caller is done. */
     81                b_timeout_add( 0, prplcb_xfer_new_send_cb, xfer );
     82        }
     83        else
     84        {
     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;
     91                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 );
     96               
     97                next_ft = NULL;
     98                */
     99        }
     100}
     101
     102static gboolean prplcb_xfer_new_send_cb( gpointer data, gint fd, b_input_condition cond )
     103{
     104        PurpleXfer *xfer = data;
     105        struct im_connection *ic = purple_ic_by_pa( xfer->account );
     106        struct prpl_xfer_data *px = xfer->ui_data;
     107        PurpleBuddy *buddy;
     108        const char *who;
     109       
     110        buddy = purple_find_buddy( xfer->account, xfer->who );
     111        who = buddy ? purple_buddy_get_name( buddy ) : xfer->who;
     112       
     113        /* TODO(wilmer): After spreading some more const goodness in BitlBee,
     114           remove the evil cast below. */
     115        px->ft = imcb_file_send_start( ic, (char*) who, xfer->filename, xfer->size );
     116        px->ft->data = px;
     117       
     118        px->ft->accept = prpl_xfer_accept;
     119        px->ft->canceled = prpl_xfer_canceled;
     120        px->ft->write_request = prpl_xfer_write_request;
     121       
     122        return FALSE;
     123}
    48124
    49125gboolean try_write_to_ui( gpointer data, gint fd, b_input_condition cond )
     
    53129        struct stat fs;
    54130        off_t tx_bytes;
    55        
    56         fprintf( stderr, "write_to_ui\n" );
    57131       
    58132        /* If we don't have the file opened yet, there's no data so wait. */
     
    63137        fstat( px->fd, &fs );
    64138       
    65         fprintf( stderr, "write_to_ui %zd %zd %zd\n", fs.st_size, tx_bytes, px->xfer->size );
    66        
    67139        if( fs.st_size > tx_bytes )
    68140        {
     
    72144                if( read( px->fd, buf, n ) == n && ft->write( ft, buf, n ) )
    73145                {
    74                         fprintf( stderr, "Wrote %zd bytes\n", n );
    75146                        px->ui_wants_data = FALSE;
    76147                }
     
    96167        struct prpl_xfer_data *px = ft->data;
    97168       
    98         fprintf( stderr, "wrq\n" );
    99        
    100169        px->ui_wants_data = TRUE;
    101170        try_write_to_ui( ft, 0, 0 );
     
    104173}
    105174
    106 static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len )
    107 {
    108         return FALSE;
    109 }
    110 
    111 static void prpl_xfer_accept( struct file_transfer *ft )
    112 {
    113         struct prpl_xfer_data *px = ft->data;
    114         purple_xfer_request_accepted( px->xfer, NULL );
    115         prpl_xfer_write_request( ft );
    116 }
    117 
    118 static void prpl_xfer_canceled( struct file_transfer *ft, char *reason )
    119 {
    120         struct prpl_xfer_data *px = ft->data;
    121         purple_xfer_request_denied( px->xfer );
    122 }
    123 
    124 static gboolean prplcb_xfer_new_send_cb( gpointer data, gint fd, b_input_condition cond );
    125 
    126 static void prplcb_xfer_new( PurpleXfer *xfer )
    127 {
    128         if( purple_xfer_get_type( xfer ) == PURPLE_XFER_RECEIVE )
    129         {
    130                 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
    131                
    132                 xfer->ui_data = px;
    133                 px->xfer = xfer;
    134                 px->fn = mktemp( g_strdup( "/tmp/bitlbee-purple-ft.XXXXXX" ) );
    135                 px->fd = -1;
    136                
    137                 purple_xfer_set_local_filename( xfer, px->fn );
    138                
    139                 /* Sadly the xfer struct is still empty ATM so come back after
    140                    the caller is done. */
    141                 b_timeout_add( 0, prplcb_xfer_new_send_cb, xfer );
    142         }
    143         else
    144         {
    145                 /*
    146                 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 );
    147                
    148                 px->fd = -1;
    149                 px->ft = next_ft;
    150                 px->ft->data = px;
    151                 px->xfer = xfer;
    152                 px->xfer->ui_data = px;
    153                
    154                 purple_xfer_set_filename( xfer, px->ft->file_name );
    155                 purple_xfer_set_size( xfer, px->ft->file_size );
    156                
    157                 next_ft = NULL;
    158                 */
    159         }
    160 }
    161 
    162 static gboolean prplcb_xfer_new_send_cb( gpointer data, gint fd, b_input_condition cond )
    163 {
    164         PurpleXfer *xfer = data;
    165         struct im_connection *ic = purple_ic_by_pa( xfer->account );
    166         struct prpl_xfer_data *px = xfer->ui_data;
    167         PurpleBuddy *buddy;
    168         const char *who;
    169        
    170         buddy = purple_find_buddy( xfer->account, xfer->who );
    171         who = buddy ? purple_buddy_get_name( buddy ) : xfer->who;
    172        
    173         /* TODO(wilmer): After spreading some more const goodness in BitlBee,
    174            remove the evil cast below. */
    175         px->ft = imcb_file_send_start( ic, (char*) who, xfer->filename, xfer->size );
    176         px->ft->data = px;
    177        
    178         px->ft->accept = prpl_xfer_accept;
    179         px->ft->canceled = prpl_xfer_canceled;
    180         px->ft->write_request = prpl_xfer_write_request;
    181        
    182         return FALSE;
    183 }
    184 
     175
     176/* Generic (IM<>UI): */
    185177static void prplcb_xfer_destroy( PurpleXfer *xfer )
    186178{
     
    197189        struct prpl_xfer_data *px = xfer->ui_data;
    198190       
    199         fprintf( stderr, "prplcb_xfer_progress 0x%p %f\n", xfer, percent );
    200        
    201191        if( px->fd == -1 && percent > 0 )
    202192        {
     
    206196               
    207197                /* Unlink it now, because we don't need it after this. */
    208                 //unlink( px->fn );
     198                unlink( px->fn );
    209199        }
    210200       
     
    212202                try_write_to_ui( px->ft, 0, 0 );
    213203        else
     204                /* Another nice problem: If we have the whole file, it only
     205                   gets closed when we return. Problem: There may still be
     206                   stuff buffered and not written, we'll only see it after
     207                   the caller close()s the file. So poll the file after that. */
    214208                b_timeout_add( 0, try_write_to_ui, px->ft );
    215209}
     
    226220        fprintf( stderr, "prplcb_xfer_dbg 0x%p\n", xfer );
    227221}
     222
     223
     224/* Sending files (UI->IM): */
     225static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len )
     226{
     227        return FALSE;
     228}
     229
     230void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle )
     231{
     232        PurpleAccount *pa = ic->proto_data;
     233        struct prpl_xfer_data *px;
     234       
     235        /* xfer_new() will pick up this variable. It's a hack but we're not
     236           multi-threaded anyway. */
     237        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
     246
     247
    228248
    229249PurpleXferUiOps bee_xfer_uiops =
     
    239259        prplcb_xfer_dbg,
    240260};
    241 
    242 void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle )
    243 {
    244         PurpleAccount *pa = ic->proto_data;
    245         struct prpl_xfer_data *px;
    246        
    247         /* xfer_new() will pick up this variable. It's a hack but we're not
    248            multi-threaded anyway. */
    249         next_ft = ft;
    250         serv_send_file( purple_account_get_connection( pa ), handle, ft->file_name );
    251        
    252         ft->write = prpl_xfer_write;
    253        
    254         px = ft->data;
    255         imcb_file_recv_start( ft );
    256 }
  • protocols/purple/purple.c

    r5d1b3a95 rc96c72f  
    142142                                PurpleKeyValuePair *kv = io->data;
    143143                                opts = g_slist_append( opts, kv->value );
     144                                /* TODO: kv->value is not a char*, WTF? */
    144145                                if( strcmp( kv->value, kv->key ) != 0 )
    145                                         g_string_append_printf( help, "%s (%s), ", kv->value, kv->key );
     146                                        g_string_append_printf( help, "%s (%s), ", (char*) kv->value, kv->key );
    146147                                else
    147                                         g_string_append_printf( help, "%s, ", kv->value );
     148                                        g_string_append_printf( help, "%s, ", (char*) kv->value );
    148149                        }
    149150                        g_string_truncate( help, help->len - 2 );
     
    455456}
    456457
    457 void purple_chat_leave( struct groupchat *gc, char *who )
     458void purple_chat_leave( struct groupchat *gc )
    458459{
    459460        PurpleConversation *pc = gc->data;
Note: See TracChangeset for help on using the changeset viewer.