Changeset 17a6ee9 for dcc.c


Ignore:
Timestamp:
2010-04-11T14:37:06Z (11 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a87e6ba
Parents:
1f92a58
Message:

Including DCC stuff again, with a wonderful extra layer of abstraction.
Some hooks are missing so sending files doesn't work yet. Receiving also
still seems to have some issues. On the plus side, at least the MSN/Jabber
modules work again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dcc.c

    r1f92a58 r17a6ee9  
    6161unsigned int receivedchunks=0, receiveddata=0;
    6262
    63 static void dcc_finish( file_transfer_t *file );
    64 static void dcc_close( file_transfer_t *file );
     63void dcc_finish( file_transfer_t *file );
     64void dcc_close( file_transfer_t *file );
    6565gboolean dccs_send_proto( gpointer data, gint fd, b_input_condition cond );
    66 int dccs_send_request( struct dcc_file_transfer *df, char *user_nick, struct sockaddr_storage *saddr );
    67 gboolean dccs_recv_start( file_transfer_t *ft );
     66int dccs_send_request( struct dcc_file_transfer *df, irc_user_t *iu, struct sockaddr_storage *saddr );
    6867gboolean dccs_recv_proto( gpointer data, gint fd, b_input_condition cond);
    6968gboolean dccs_recv_write_request( file_transfer_t *ft );
     
    7170gboolean dcc_abort( dcc_file_transfer_t *df, char *reason, ... );
    7271
    73 /* As defined in ft.h */
    74 file_transfer_t *imcb_file_send_start( struct im_connection *ic, char *handle, char *file_name, size_t file_size )
    75 {
    76         user_t *u = user_findhandle( ic, handle );
    77         /* one could handle this more intelligent like imcb_buddy_msg.
    78          * can't call it directly though cause it does some wrapping.
    79          * Maybe give imcb_buddy_msg a parameter NO_WRAPPING? */
    80         if (!u) return NULL;
    81 
    82         return dccs_send_start( ic, u->nick, file_name, file_size );
    83 };
    84 
    85 /* As defined in ft.h */
    86 void imcb_file_canceled( file_transfer_t *file, char *reason )
    87 {
    88         if( file->canceled )
    89                 file->canceled( file, reason );
    90 
    91         dcc_close( file );
    92 }
    93 
    94 /* As defined in ft.h */
    95 gboolean imcb_file_recv_start( file_transfer_t *ft )
    96 {
    97         return dccs_recv_start( ft );
    98 }
    99 
    100 /* As defined in ft.h */
    101 void imcb_file_finished( file_transfer_t *file )
    102 {
    103         dcc_file_transfer_t *df = file->priv;
    104 
    105         if( file->bytes_transferred >= file->file_size )
    106                 dcc_finish( file );
    107         else
    108                 df->proto_finished = TRUE;
    109 }
    110 
    111 dcc_file_transfer_t *dcc_alloc_transfer( char *file_name, size_t file_size, struct im_connection *ic )
     72dcc_file_transfer_t *dcc_alloc_transfer( const char *file_name, size_t file_size, struct im_connection *ic )
    11273{
    11374        file_transfer_t *file = g_new0( file_transfer_t, 1 );
     
    12485
    12586/* This is where the sending magic starts... */
    126 file_transfer_t *dccs_send_start( struct im_connection *ic, char *user_nick, char *file_name, size_t file_size )
     87file_transfer_t *dccs_send_start( struct im_connection *ic, irc_user_t *iu, const char *file_name, size_t file_size )
    12788{
    12889        file_transfer_t *file;
    12990        dcc_file_transfer_t *df;
     91        irc_t *irc = (irc_t *) ic->bee->ui_data;
    13092        struct sockaddr_storage saddr;
    13193        char *errmsg;
     
    150112        file->status = FT_STATUS_LISTENING;
    151113
    152         if( !dccs_send_request( df, user_nick, &saddr ) )
     114        if( !dccs_send_request( df, iu, &saddr ) )
    153115                return NULL;
    154116
     
    156118        df->watch_in = b_input_add( df->fd, GAIM_INPUT_READ, dccs_send_proto, df );
    157119
    158         df->ic->irc->file_transfers = g_slist_prepend( df->ic->irc->file_transfers, file );
     120        irc->file_transfers = g_slist_prepend( irc->file_transfers, file );
    159121
    160122        df->progress_timeout = b_timeout_add( DCC_MAX_STALL * 1000, dcc_progress, df );
     
    163125                      "Accept the file transfer if you'd like the file. If you don't, "
    164126                      "issue the 'transfers reject' command.",
    165                       user_nick, file_name, file_size / 1024 );
     127                      iu->nick, file_name, file_size / 1024 );
    166128
    167129        return file;
     
    216178
    217179/* Creates the "DCC SEND" line and sends it to the server */
    218 int dccs_send_request( struct dcc_file_transfer *df, char *user_nick, struct sockaddr_storage *saddr )
     180int dccs_send_request( struct dcc_file_transfer *df, irc_user_t *iu, struct sockaddr_storage *saddr )
    219181{
    220182        char ipaddr[INET6_ADDRSTRLEN];
     
    250212                                df->ft->file_name, ipaddr, port, df->ft->file_size );
    251213       
    252         if ( !irc_msgfrom( df->ic->irc, user_nick, cmd ) )
    253                 return dcc_abort( df, "Couldn't send `DCC SEND' message to %s.", user_nick );
     214        irc_send_msg_raw( iu, "PRIVMSG", iu->irc->user->nick, cmd );
    254215
    255216        g_free( cmd );
     
    496457 * Cleans up after a transfer.
    497458 */
    498 static void dcc_close( file_transfer_t *file )
     459void dcc_close( file_transfer_t *file )
    499460{
    500461        dcc_file_transfer_t *df = file->priv;
     462        irc_t *irc = (irc_t *) df->ic->bee->ui_data;
    501463
    502464        if( file->free )
     
    514476                b_event_remove( df->progress_timeout );
    515477       
    516         df->ic->irc->file_transfers = g_slist_remove( df->ic->irc->file_transfers, file );
     478        irc->file_transfers = g_slist_remove( irc->file_transfers, file );
    517479       
    518480        g_free( df );
     
    544506file_transfer_t *dcc_request( struct im_connection *ic, char *line )
    545507{
     508        irc_t *irc = (irc_t *) ic->bee->ui_data;
    546509        char *pattern = "SEND"
    547510                " (([^\"][^ ]*)|\"(([^\"]|\\\")*)\")"
     
    627590                g_free( input );
    628591
    629                 df->ic->irc->file_transfers = g_slist_prepend( df->ic->irc->file_transfers, ft );
     592                irc->file_transfers = g_slist_prepend( irc->file_transfers, ft );
    630593
    631594                return ft;
Note: See TracChangeset for help on using the changeset viewer.