Changeset a02f34f for protocols


Ignore:
Timestamp:
2008-08-11T23:07:12Z (16 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).

Location:
protocols
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/s5bytestream.c

    r66be784 ra02f34f  
    2424#include "jabber.h"
    2525#include "sha1.h"
     26#include "lib/ftutil.h"
    2627#include <poll.h>
    27 
    28 /* Some ifdefs for ulibc (Thanks to Whoopie) */
    29 #ifndef HOST_NAME_MAX
    30 #include <sys/param.h>
    31 #ifdef MAXHOSTNAMELEN
    32 #define HOST_NAME_MAX MAXHOSTNAMELEN
    33 #else
    34 #define HOST_NAME_MAX 255
    35 #endif
    36 #endif
    37 
    38 #ifndef AI_NUMERICSERV
    39 #define AI_NUMERICSERV 0x0400   /* Don't use name resolution.  */
    40 #endif
    4128
    4229struct bs_transfer {
     
    115102gboolean jabber_bs_send_request( struct jabber_transfer *tf, GSList *streamhosts );
    116103gboolean jabber_bs_send_handshake( gpointer data, gint fd, b_input_condition cond );
    117 gboolean jabber_bs_send_listen( struct bs_transfer *bt, struct sockaddr_storage *saddr, char *host, char *port );
    118104static xt_status jabber_bs_send_handle_activate( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
    119105void jabber_bs_send_activate( struct bs_transfer *bt );
     
    902888        struct jabber_data *jd = tf->ic->proto_data;
    903889        char *proxysetting = g_strdup ( set_getstr( &tf->ic->acc->set, "proxy" ) );
    904         char *proxy,*next;
     890        char *proxy, *next, *errmsg = NULL;
    905891        char port[6];
    906892        char host[INET6_ADDRSTRLEN];
     
    913899                        *next++ = '\0';
    914900               
    915                 if( ( strcmp( proxy, "<local>" ) == 0 ) && jabber_bs_send_listen( bt, &tf->saddr, host, port ) ) {
    916                         sh = g_new0( jabber_streamhost_t, 1 );
    917                         sh->jid = g_strdup( tf->ini_jid );
    918                         sh->host = g_strdup( host );
    919                         strcpy( sh->port, port );
    920                         bt->streamhosts = g_slist_append( bt->streamhosts, sh );
    921 
    922                         bt->tf->watch_in = b_input_add( tf->fd, GAIM_INPUT_READ, jabber_bs_send_handshake, bt );
    923                         bt->connect_timeout = b_timeout_add( JABBER_BS_LISTEN_TIMEOUT * 1000, jabber_bs_connect_timeout, bt );
     901                if( strcmp( proxy, "<local>" ) == 0 ) {
     902                        if( ( tf->fd = ft_listen( &tf->saddr, host, port, FALSE, &errmsg ) ) != -1 ) {
     903                                sh = g_new0( jabber_streamhost_t, 1 );
     904                                sh->jid = g_strdup( tf->ini_jid );
     905                                sh->host = g_strdup( host );
     906                                strcpy( sh->port, port );
     907                                bt->streamhosts = g_slist_append( bt->streamhosts, sh );
     908
     909                                bt->tf->watch_in = b_input_add( tf->fd, GAIM_INPUT_READ, jabber_bs_send_handshake, bt );
     910                                bt->connect_timeout = b_timeout_add( JABBER_BS_LISTEN_TIMEOUT * 1000, jabber_bs_connect_timeout, bt );
     911                        } else {
     912                                imcb_log( tf->ic, "Transferring file %s: couldn't listen locally(non fatal, check your ft_listen setting in bitlbee.conf): %s",
     913                                          tf->ft->file_name,
     914                                          errmsg );
     915                        }
    924916                } else if( strcmp( proxy, "<auto>" ) == 0 ) {
    925917                        while ( streamhosts ) {
     
    10201012
    10211013        return FALSE;
    1022 }
    1023 
    1024 /*
    1025  * Creates a listening socket and returns it in saddr_ptr.
    1026  */
    1027 gboolean jabber_bs_send_listen( struct bs_transfer *bt, struct sockaddr_storage *saddr, char *host, char *port )
    1028 {
    1029         struct jabber_transfer *tf = bt->tf;
    1030         int fd,gret;
    1031         char hostname[ HOST_NAME_MAX + 1 ];
    1032         struct addrinfo hints, *rp;
    1033         socklen_t ssize = sizeof( struct sockaddr_storage );
    1034 
    1035         /* won't be long till someone asks for this to be configurable :) */
    1036 
    1037         ASSERTSOCKOP( gethostname( hostname, sizeof( hostname ) ), "gethostname()" );
    1038 
    1039         memset( &hints, 0, sizeof( struct addrinfo ) );
    1040         hints.ai_socktype = SOCK_STREAM;
    1041         hints.ai_flags = AI_NUMERICSERV;
    1042 
    1043         if ( ( gret = getaddrinfo( hostname, "0", &hints, &rp ) ) != 0 )
    1044                 return jabber_bs_abort( bt, "getaddrinfo() failed: %s", gai_strerror( gret ) );
    1045 
    1046         memcpy( saddr, rp->ai_addr, rp->ai_addrlen );
    1047 
    1048         ASSERTSOCKOP( fd = tf->fd = socket( saddr->ss_family, SOCK_STREAM, 0 ), "Opening socket" );
    1049 
    1050         ASSERTSOCKOP( bind( fd, ( struct sockaddr *)saddr, rp->ai_addrlen ), "Binding socket" );
    1051        
    1052         freeaddrinfo( rp );
    1053 
    1054         ASSERTSOCKOP( listen( fd, 1 ), "Making socket listen" );
    1055 
    1056         if ( !inet_ntop( saddr->ss_family, saddr->ss_family == AF_INET ?
    1057                         ( void * )&( ( struct sockaddr_in * ) saddr )->sin_addr.s_addr : ( void * )&( ( struct sockaddr_in6 * ) saddr )->sin6_addr.s6_addr
    1058                         , host, INET6_ADDRSTRLEN ) )
    1059                 return jabber_bs_abort( bt, "inet_ntop failed on listening socket" );
    1060 
    1061         ASSERTSOCKOP( getsockname( fd, ( struct sockaddr *)saddr, &ssize ), "Getting socket name" );
    1062 
    1063         if( saddr->ss_family == AF_INET )
    1064                 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in *) saddr )->sin_port ) );
    1065         else
    1066                 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in6 *) saddr )->sin6_port ) );
    1067 
    1068         return TRUE;
    10691014}
    10701015
  • protocols/msn/invitation.c

    r66be784 ra02f34f  
    2828#include "invitation.h"
    2929#include "msn.h"
    30 
    31 /* Some ifdefs for ulibc and apparently also BSD (Thanks to Whoopie) */
    32 #ifndef HOST_NAME_MAX
    33 #include <sys/param.h>
    34 #ifdef MAXHOSTNAMELEN
    35 #define HOST_NAME_MAX MAXHOSTNAMELEN
    36 #else
    37 #define HOST_NAME_MAX 255
    38 #endif
    39 #endif
    40 
    41 #ifndef AI_NUMERICSERV
    42 #define AI_NUMERICSERV 0x0400   /* Don't use name resolution.  */
    43 #endif
     30#include "lib/ftutil.h"
    4431
    4532#ifdef debug
     
    7865        if( (op) == -1 ) \
    7966                return msn_ftp_abort( file , msg ": %s", strerror( errno ) );
    80 
    81 /*
    82  * Creates a listening socket and returns its address in host, port.
    83  */
    84 gboolean msn_ftp_listen( msn_filetransfer_t *msn_file, char *host, char *port )
    85 {
    86         file_transfer_t *file = msn_file->dcc;
    87         int fd,gret;
    88         char hostname[ HOST_NAME_MAX + 1 ];
    89         struct addrinfo hints, *rp;
    90         struct sockaddr_storage saddrst, *saddr = &saddrst;
    91         socklen_t ssize = sizeof( struct sockaddr_storage );
    92 
    93         /* won't be long till someone asks for this to be configurable :) */
    94 
    95         ASSERTSOCKOP( gethostname( hostname, sizeof( hostname ) ), "gethostname()" );
    96 
    97         memset( &hints, 0, sizeof( struct addrinfo ) );
    98         hints.ai_socktype = SOCK_STREAM;
    99         hints.ai_flags = AI_NUMERICSERV;
    100 
    101         if ( ( gret = getaddrinfo( hostname, "0", &hints, &rp ) ) != 0 )
    102                 return msn_ftp_abort( file, "getaddrinfo() failed: %s", gai_strerror( gret ) );
    103 
    104         memcpy( saddr, rp->ai_addr, rp->ai_addrlen );
    105 
    106         ASSERTSOCKOP( fd = msn_file->fd = socket( saddr->ss_family, SOCK_STREAM, 0 ), "Opening socket" );
    107 
    108         ASSERTSOCKOP( bind( fd, ( struct sockaddr *)saddr, rp->ai_addrlen ), "Binding socket" );
    109 
    110         freeaddrinfo( rp );
    111 
    112         ASSERTSOCKOP( listen( fd, 1 ), "Making socket listen" );
    113 
    114         if ( !inet_ntop( saddr->ss_family, saddr->ss_family == AF_INET ?
    115                         ( void * )&( ( struct sockaddr_in * ) saddr )->sin_addr.s_addr : ( void * )&( ( struct sockaddr_in6 * ) saddr )->sin6_addr.s6_addr
    116                         , host, INET6_ADDRSTRLEN ) )
    117                 return msn_ftp_abort( file, "inet_ntop failed on listening socket" );
    118 
    119         ASSERTSOCKOP( getsockname( fd, ( struct sockaddr *)saddr, &ssize ), "Getting socket name" );
    120 
    121         if( saddr->ss_family == AF_INET )
    122                 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in *) saddr )->sin_port ) );
    123         else
    124                 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in6 *) saddr )->sin6_port ) );
    125 
    126         return TRUE;
    127 }
    12867
    12968void msn_ftp_invitation_cmd( struct im_connection *ic, char *who, int cookie, char *icmd,
     
    282221        char host[INET6_ADDRSTRLEN];
    283222        char port[6];
     223        char *errmsg;
    284224
    285225        msn_file->auth_cookie = acookie;
    286226
    287         if( !msn_ftp_listen( msn_file, host, port ) )
    288             return;
     227        if( ( msn_file->fd = ft_listen( NULL, host, port, FALSE, &errmsg ) ) == -1 ) {
     228                msn_ftp_abort( file, "Failed to listen locally, check your ft_listen setting in bitlbee.conf: %s", errmsg );
     229                return;
     230        }
    289231
    290232        msn_file->r_event_id = b_input_add( msn_file->fd, GAIM_INPUT_READ, msn_ftps_connected, file );
Note: See TracChangeset for help on using the changeset viewer.