Changeset 17a6ee9


Ignore:
Timestamp:
2010-04-11T14:37:06Z (9 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.

Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    r1f92a58 r17a6ee9  
    1111# Program variables
    1212#objects = bitlbee.o chat.o dcc.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS)
    13 objects = bitlbee.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o root_commands.o set.o storage.o $(STORAGE_OBJS)
     13objects = bitlbee.o dcc.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o root_commands.o set.o storage.o $(STORAGE_OBJS)
    1414headers = account.h bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/ft.h protocols/nogaim.h
    1515subdirs = lib protocols
  • 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;
  • dcc.h

    r1f92a58 r17a6ee9  
    9595} dcc_file_transfer_t;
    9696
    97 file_transfer_t *dccs_send_start( struct im_connection *ic, char *user_nick, char *file_name, size_t file_size );
     97file_transfer_t *dccs_send_start( struct im_connection *ic, irc_user_t *iu, const char *file_name, size_t file_size );
     98void dcc_canceled( file_transfer_t *file, char *reason );
     99gboolean dccs_send_write( file_transfer_t *file, char *data, unsigned int data_size );
     100file_transfer_t *dcc_request( struct im_connection *ic, char *line );
     101void dcc_finish( file_transfer_t *file );
     102void dcc_close( file_transfer_t *file );
     103gboolean dccs_recv_start( file_transfer_t *ft );
    98104
    99 void dcc_canceled( file_transfer_t *file, char *reason );
    100 
    101 gboolean dccs_send_write( file_transfer_t *file, char *data, unsigned int data_size );
    102 
    103 file_transfer_t *dcc_request( struct im_connection *ic, char *line );
    104105#endif
  • irc_im.c

    r1f92a58 r17a6ee9  
    2525
    2626#include "bitlbee.h"
    27 
     27#include "dcc.h"
    2828
    2929/* IM->IRC callbacks */
     
    161161}
    162162
     163/* File transfers */
     164static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size )
     165{
     166        return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size );
     167}
     168
     169gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft )
     170{
     171        return dccs_recv_start( ft );
     172}
     173
     174void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft )
     175{
     176        return dcc_close( ft );
     177}
     178
     179void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file )
     180{
     181        dcc_file_transfer_t *df = file->priv;
     182
     183        if( file->bytes_transferred >= file->file_size )
     184                dcc_finish( file );
     185        else
     186                df->proto_finished = TRUE;
     187}
     188
    163189const struct bee_ui_funcs irc_ui_funcs = {
    164190        bee_irc_user_new,
     
    167193        bee_irc_user_status,
    168194        bee_irc_user_msg,
     195       
     196        bee_irc_ft_in_start,
     197        bee_irc_ft_out_start,
     198        bee_irc_ft_close,
     199        bee_irc_ft_finished,
    169200};
    170201
  • protocols/Makefile

    r1f92a58 r17a6ee9  
    1010
    1111# [SH] Program variables
    12 objects = account.o bee.o bee_user.o nogaim.o
     12objects = account.o bee.o bee_ft.o bee_user.o nogaim.o
    1313
    1414
  • protocols/bee.h

    r1f92a58 r17a6ee9  
    7171        gboolean (*user_status)( bee_t *bee, struct bee_user *bu, struct bee_user *old );
    7272        gboolean (*user_msg)( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at );
     73       
     74        struct file_transfer* (*ft_in_start)( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size );
     75        gboolean (*ft_out_start)( struct im_connection *ic, struct file_transfer *ft );
     76        void (*ft_close)( struct im_connection *ic, struct file_transfer *ft );
     77        void (*ft_finished)( struct im_connection *ic, struct file_transfer *ft );
    7378} bee_ui_funcs_t;
    7479
  • protocols/ft.h

    r1f92a58 r17a6ee9  
    168168 * the canceled() and free() callbacks given in file will be called by this function.
    169169 */
    170 void imcb_file_canceled( file_transfer_t *file, char *reason );
     170void imcb_file_canceled( struct im_connection *ic, file_transfer_t *file, char *reason );
    171171
    172 gboolean imcb_file_recv_start( file_transfer_t *ft );
     172gboolean imcb_file_recv_start( struct im_connection *ic, file_transfer_t *ft );
    173173
    174 void imcb_file_finished( file_transfer_t *file );
     174void imcb_file_finished( struct im_connection *ic, file_transfer_t *file );
    175175#endif
  • protocols/jabber/iq.c

    r1f92a58 r17a6ee9  
    392392                        if( ( strcmp( sub, "both" ) == 0 || strcmp( sub, "to" ) == 0 ) )
    393393                        {
    394                                 if( initial || imcb_find_buddy( ic, jid ) == NULL )
     394                                if( initial || bee_user_by_handle( ic->bee, ic, jid ) == NULL )
    395395                                        imcb_add_buddy( ic, jid, ( group && group->text_len ) ?
    396396                                                                   group->text : NULL );
     
    590590            strcmp( s, "result" ) == 0 )
    591591        {
    592                 if( imcb_find_buddy( ic, jid ) == NULL )
     592                if( bee_user_by_handle( ic->bee, ic, jid ) == NULL )
    593593                        imcb_add_buddy( ic, jid, NULL );
    594594        }
  • protocols/jabber/jabber.c

    r1f92a58 r17a6ee9  
    267267       
    268268        while( jd->filetransfers )
    269                 imcb_file_canceled( ( ( struct jabber_transfer *) jd->filetransfers->data )->ft, "Logging out" );
     269                imcb_file_canceled( ic, ( ( struct jabber_transfer *) jd->filetransfers->data )->ft, "Logging out" );
    270270
    271271        while( jd->streamhosts )
  • protocols/jabber/jabber_util.c

    r1f92a58 r17a6ee9  
    279279        presence_send_request( bla->ic, bla->handle, "subscribed" );
    280280       
    281         if( imcb_find_buddy( bla->ic, bla->handle ) == NULL )
    282                 imcb_ask_add( bla->ic, bla->handle, NULL );
     281        imcb_ask_add( bla->ic, bla->handle, NULL );
    283282       
    284283        g_free( bla->handle );
     
    462461               
    463462                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
    464                     ( bare_exists || imcb_find_buddy( ic, jid ) ) )
     463                    ( bare_exists || bee_user_by_handle( ic->bee, ic, jid ) ) )
    465464                {
    466465                        *s = '/';
     
    483482                if( bud == NULL )
    484483                        /* No match. Create it now? */
    485                         return ( ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid_ ) ) ?
     484                        return ( ( flags & GET_BUDDY_CREAT ) &&
     485                                 bee_user_by_handle( ic->bee, ic, jid_ ) ) ?
    486486                                   jabber_buddy_add( ic, jid_ ) : NULL;
    487487                else if( bud->resource && ( flags & GET_BUDDY_EXACT ) )
  • protocols/jabber/s5bytestream.c

    r1f92a58 r17a6ee9  
    566566        xt_free_node( reply );
    567567
    568         imcb_file_canceled( tf->ft, "couldn't connect to any streamhosts" );
     568        imcb_file_canceled( tf->ic, tf->ft, "couldn't connect to any streamhosts" );
    569569
    570570        bt->tf->watch_in = 0;
     
    603603               
    604604        if( !jabber_write_packet( tf->ic, reply ) )
    605                 imcb_file_canceled( tf->ft, "Error transmitting bytestream response" );
     605                imcb_file_canceled( tf->ic, tf->ft, "Error transmitting bytestream response" );
    606606        xt_free_node( reply );
    607607}
     
    643643
    644644        if( tf->bytesread >= tf->ft->file_size )
    645                 imcb_file_finished( tf->ft );
     645                imcb_file_finished( tf->ic, tf->ft );
    646646
    647647        tf->ft->write( tf->ft, tf->ft->buffer, ret );   
     
    659659        if( tf->watch_in )
    660660        {
    661                 imcb_file_canceled( ft, "BUG in jabber file transfer: write_request called when already watching for input" );
     661                imcb_file_canceled( tf->ic, ft, "BUG in jabber file transfer: write_request called when already watching for input" );
    662662                return FALSE;
    663663        }
     
    705705
    706706        if( tf->byteswritten >= ft->file_size )
    707                 imcb_file_finished( ft );
     707                imcb_file_finished( tf->ic, ft );
    708708        else
    709709                bt->tf->watch_out = b_input_add( tf->fd, GAIM_INPUT_WRITE, jabber_bs_send_can_write, bt );
     
    10051005
    10061006        if( !jabber_write_packet( tf->ic, iq ) )
    1007                 imcb_file_canceled( tf->ft, "Error transmitting bytestream request" );
     1007                imcb_file_canceled( tf->ic, tf->ft, "Error transmitting bytestream request" );
    10081008        return TRUE;
    10091009}
     
    10201020
    10211021        if( jd->streamhosts==NULL ) /* we're done here unless we have a proxy to try */
    1022                 imcb_file_canceled( tf->ft, error );
     1022                imcb_file_canceled( tf->ic, tf->ft, error );
    10231023
    10241024        /* MUST always return FALSE! */
  • protocols/jabber/si.c

    r1f92a58 r17a6ee9  
    9191
    9292        if( !foundft )
    93                 imcb_file_canceled( tf->ft, "Buddy's client doesn't feature file transfers" );
     93                imcb_file_canceled( tf->ic, tf->ft, "Buddy's client doesn't feature file transfers" );
    9494        else if( !foundbt )
    95                 imcb_file_canceled( tf->ft, "Buddy's client doesn't feature byte streams (required)" );
     95                imcb_file_canceled( tf->ic, tf->ft, "Buddy's client doesn't feature byte streams (required)" );
    9696        else if( !foundsi )
    97                 imcb_file_canceled( tf->ft, "Buddy's client doesn't feature stream initiation (required)" );
     97                imcb_file_canceled( tf->ic, tf->ft, "Buddy's client doesn't feature stream initiation (required)" );
    9898               
    9999        return foundft && foundbt && foundsi;
     
    109109
    110110        /* and start the receive logic */
    111         imcb_file_recv_start( tf->ft );
     111        imcb_file_recv_start( tf->ic, tf->ft );
    112112
    113113}
     
    156156        if( bud == NULL )
    157157        {
    158                 imcb_file_canceled( ft, "Couldn't find buddy (BUG?)" );
     158                imcb_file_canceled( ic, ft, "Couldn't find buddy (BUG?)" );
    159159                return;
    160160        }
  • protocols/msn/Makefile

    r1f92a58 r17a6ee9  
    1010
    1111# [SH] Program variables
    12 objects = invitation.o msn.o msn_util.o ns.o passport.o sb.o tables.o
     12objects = msn.o msn_util.o ns.o passport.o sb.o tables.o
    1313
    1414CFLAGS += -Wall
  • protocols/msn/msn.c

    r1f92a58 r17a6ee9  
    8181        if( md )
    8282        {
     83                /** Disabling MSN ft support for now.
    8384                while( md->filetransfers ) {
    8485                        imcb_file_canceled( md->filetransfers->data, "Closing connection" );
    8586                }
     87                */
    8688               
    8789                if( md->fd >= 0 )
     
    344346        ret->send_typing = msn_send_typing;
    345347        ret->handle_cmp = g_strcasecmp;
    346         ret->transfer_request = msn_ftp_transfer_request;
     348        //ret->transfer_request = msn_ftp_transfer_request;
    347349
    348350        register_protocol(ret);
  • protocols/msn/msn_util.c

    r1f92a58 r17a6ee9  
    9696        msn_buddy_list_add( bla->ic, "AL", bla->handle, bla->realname );
    9797       
    98         if( imcb_find_buddy( bla->ic, bla->handle ) == NULL )
    99                 imcb_ask_add( bla->ic, bla->handle, NULL );
     98        imcb_ask_add( bla->ic, bla->handle, NULL );
    10099       
    101100        g_free( bla->handle );
  • protocols/msn/sb.c

    r1f92a58 r17a6ee9  
    691691                        }
    692692                }
     693#if 0
     694                // Disable MSN ft support for now.
    693695                else if( g_strncasecmp( ct, "text/x-msmsgsinvite", 19 ) == 0 )
    694696                {
     
    723725                        g_free( command );
    724726                }
     727#endif
    725728                else if( g_strncasecmp( ct, "application/x-msnmsgrp2p", 24 ) == 0 )
    726729                {
  • protocols/nogaim.c

    r1f92a58 r17a6ee9  
    391391        if( !bu || !fullname ) return;
    392392       
    393         if( strcmp( bu->fullname, fullname ) != 0 )
     393        if( !bu->fullname || strcmp( bu->fullname, fullname ) != 0 )
    394394        {
    395395                g_free( bu->fullname );
Note: See TracChangeset for help on using the changeset viewer.