Changeset a02f34f for dcc.c


Ignore:
Timestamp:
2008-08-11T23:07:12Z (11 years ago)
Author:
ulim <a.sporto+bee@…>
Branches:
master
Children:
5d550c5
Parents:
66be784
Message:

Added conf entries and lib/ftutil.[ch].

ft_listen = <IP-A>:<Port-A>;<IP-B>:<Port-B> to specify listening addresses for
the bitlbee<->client connection and the bitlbee<->IM peer connection,
respectively.

ft_max_size should be obvious. ft_max_kbps should limit the kilobits per second
per transfer (not implemented yet).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dcc.c

    r66be784 ra02f34f  
    2929#include <netinet/tcp.h>
    3030#include <regex.h>
    31 
    32 /* Some ifdefs for ulibc (Thanks to Whoopie) */
    33 #ifndef HOST_NAME_MAX
    34 #include <sys/param.h>
    35 #ifdef MAXHOSTNAMELEN
    36 #define HOST_NAME_MAX MAXHOSTNAMELEN
    37 #else
    38 #define HOST_NAME_MAX 255
    39 #endif
    40 #endif
    41 
    42 #ifndef AI_NUMERICSERV
    43 #define AI_NUMERICSERV 0x0400   /* Don't use name resolution.  */
    44 #endif
     31#include "lib/ftutil.h"
    4532
    4633/*
     
    8067static void dcc_close( file_transfer_t *file );
    8168gboolean dccs_send_proto( gpointer data, gint fd, b_input_condition cond );
    82 gboolean dcc_listen( dcc_file_transfer_t *df, struct sockaddr_storage **saddr_ptr );
    8369int dccs_send_request( struct dcc_file_transfer *df, char *user_nick, struct sockaddr_storage *saddr );
    8470gboolean dccs_recv_start( file_transfer_t *ft );
     
    8672gboolean dccs_recv_write_request( file_transfer_t *ft );
    8773gboolean dcc_progress( gpointer data, gint fd, b_input_condition cond );
     74gboolean dcc_abort( dcc_file_transfer_t *df, char *reason, ... );
    8875
    8976/* As defined in ft.h */
     
    143130        file_transfer_t *file;
    144131        dcc_file_transfer_t *df;
    145         struct sockaddr_storage *saddr;
    146 
    147         if( file_size > global.conf->max_filetransfer_size )
     132        struct sockaddr_storage saddr;
     133        char *errmsg;
     134        char host[INET6_ADDRSTRLEN];
     135        char port[6];
     136
     137        if( file_size > global.conf->ft_max_size )
    148138                return NULL;
    149139       
     
    153143
    154144        /* listen and request */
    155         if( !dcc_listen( df, &saddr ) ||
    156             !dccs_send_request( df, user_nick, saddr ) )
     145
     146        if( ( df->fd = ft_listen( &saddr, host, port, TRUE, &errmsg ) ) == -1 ) {
     147                dcc_abort( df, "Failed to listen locally, check your ft_listen setting in bitlbee.conf: %s", errmsg );
    157148                return NULL;
    158 
    159         g_free( saddr );
     149        }
     150
     151        file->status = FT_STATUS_LISTENING;
     152
     153        if( !dccs_send_request( df, user_nick, &saddr ) )
     154                return NULL;
    160155
    161156        /* watch */
     
    258253
    259254        g_free( cmd );
    260 
    261         return TRUE;
    262 }
    263 
    264 /*
    265  * Creates a listening socket and returns it in saddr_ptr.
    266  */
    267 gboolean dcc_listen( dcc_file_transfer_t *df, struct sockaddr_storage **saddr_ptr )
    268 {
    269         file_transfer_t *file = df->ft;
    270         struct sockaddr_storage *saddr;
    271         int fd,gret;
    272         char hostname[ HOST_NAME_MAX + 1 ];
    273         struct addrinfo hints, *rp;
    274         socklen_t ssize = sizeof( struct sockaddr_storage );
    275 
    276         /* won't be long till someone asks for this to be configurable :) */
    277 
    278         ASSERTSOCKOP( gethostname( hostname, sizeof( hostname ) ), "gethostname()" );
    279 
    280         memset( &hints, 0, sizeof( struct addrinfo ) );
    281         hints.ai_socktype = SOCK_STREAM;
    282         hints.ai_flags = AI_NUMERICSERV;
    283 
    284         if ( ( gret = getaddrinfo( hostname, "0", &hints, &rp ) != 0 ) )
    285                 return dcc_abort( df, "getaddrinfo(): %s", gai_strerror( gret ) );
    286 
    287         saddr = g_new( struct sockaddr_storage, 1 );
    288 
    289         *saddr_ptr = saddr;
    290 
    291         memcpy( saddr, rp->ai_addr, rp->ai_addrlen );
    292 
    293         ASSERTSOCKOP( fd = df->fd = socket( saddr->ss_family, SOCK_STREAM, 0 ), "Opening socket" );
    294 
    295         ASSERTSOCKOP( bind( fd, ( struct sockaddr *)saddr, rp->ai_addrlen ), "Binding socket" );
    296        
    297         freeaddrinfo( rp );
    298 
    299         ASSERTSOCKOP( getsockname( fd, ( struct sockaddr *)saddr, &ssize ), "Getting socket name" );
    300 
    301         ASSERTSOCKOP( listen( fd, 1 ), "Making socket listen" );
    302 
    303         file->status = FT_STATUS_LISTENING;
    304255
    305256        return TRUE;
Note: See TracChangeset for help on using the changeset viewer.