Changeset a02f34f
- Timestamp:
- 2008-08-11T23:07:12Z (16 years ago)
- Branches:
- master
- Children:
- 5d550c5
- Parents:
- 66be784
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r66be784 ra02f34f 11 11 # Program variables 12 12 objects = account.o bitlbee.o crypting.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) user.o dcc.o 13 headers = account.h bitlbee.h commands.h conf.h config.h crypting.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/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/nogaim.h protocols/ft.h 13 headers = account.h bitlbee.h commands.h conf.h config.h crypting.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/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/nogaim.h protocols/ft.h lib/ftutil.h 14 14 subdirs = lib protocols 15 15 -
conf.c
r66be784 ra02f34f 63 63 conf->ping_timeout = 300; 64 64 conf->user = NULL; 65 conf->max_filetransfer_size = G_MAXUINT; 65 conf->ft_max_size = SIZE_MAX; 66 conf->ft_max_kbps = G_MAXUINT; 67 conf->ft_listen = NULL; 66 68 proxytype = 0; 67 69 … … 307 309 conf->user = g_strdup( ini->value ); 308 310 } 311 else if( g_strcasecmp( ini->key, "ft_max_size" ) == 0 ) 312 { 313 size_t ft_max_size; 314 if( sscanf( ini->value, "%zu", &ft_max_size ) != 1 ) 315 { 316 fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value ); 317 return 0; 318 } 319 conf->ft_max_size = ft_max_size; 320 } 321 else if( g_strcasecmp( ini->key, "ft_max_kbps" ) == 0 ) 322 { 323 if( sscanf( ini->value, "%d", &i ) != 1 ) 324 { 325 fprintf( stderr, "Invalid %s value: %s\n", ini->key, ini->value ); 326 return 0; 327 } 328 conf->ft_max_kbps = i; 329 } 330 else if( g_strcasecmp( ini->key, "ft_listen" ) == 0 ) 331 { 332 g_free( conf->ft_listen ); 333 conf->ft_listen = g_strdup( ini->value ); 334 } 309 335 else 310 336 { -
conf.h
r66be784 ra02f34f 50 50 int ping_timeout; 51 51 char *user; 52 size_t max_filetransfer_size; 52 size_t ft_max_size; 53 int ft_max_kbps; 54 char *ft_listen; 53 55 } conf_t; 54 56 -
dcc.c
r66be784 ra02f34f 29 29 #include <netinet/tcp.h> 30 30 #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" 45 32 46 33 /* … … 80 67 static void dcc_close( file_transfer_t *file ); 81 68 gboolean 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 );83 69 int dccs_send_request( struct dcc_file_transfer *df, char *user_nick, struct sockaddr_storage *saddr ); 84 70 gboolean dccs_recv_start( file_transfer_t *ft ); … … 86 72 gboolean dccs_recv_write_request( file_transfer_t *ft ); 87 73 gboolean dcc_progress( gpointer data, gint fd, b_input_condition cond ); 74 gboolean dcc_abort( dcc_file_transfer_t *df, char *reason, ... ); 88 75 89 76 /* As defined in ft.h */ … … 143 130 file_transfer_t *file; 144 131 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 ) 148 138 return NULL; 149 139 … … 153 143 154 144 /* 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 ); 157 148 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; 160 155 161 156 /* watch */ … … 258 253 259 254 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;304 255 305 256 return TRUE; -
lib/Makefile
r66be784 ra02f34f 10 10 11 11 # [SH] Program variables 12 objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o 12 objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o ftutil.o 13 13 14 14 CFLAGS += -Wall -
protocols/jabber/s5bytestream.c
r66be784 ra02f34f 24 24 #include "jabber.h" 25 25 #include "sha1.h" 26 #include "lib/ftutil.h" 26 27 #include <poll.h> 27 28 /* Some ifdefs for ulibc (Thanks to Whoopie) */29 #ifndef HOST_NAME_MAX30 #include <sys/param.h>31 #ifdef MAXHOSTNAMELEN32 #define HOST_NAME_MAX MAXHOSTNAMELEN33 #else34 #define HOST_NAME_MAX 25535 #endif36 #endif37 38 #ifndef AI_NUMERICSERV39 #define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */40 #endif41 28 42 29 struct bs_transfer { … … 115 102 gboolean jabber_bs_send_request( struct jabber_transfer *tf, GSList *streamhosts ); 116 103 gboolean 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 );118 104 static xt_status jabber_bs_send_handle_activate( struct im_connection *ic, struct xt_node *node, struct xt_node *orig ); 119 105 void jabber_bs_send_activate( struct bs_transfer *bt ); … … 902 888 struct jabber_data *jd = tf->ic->proto_data; 903 889 char *proxysetting = g_strdup ( set_getstr( &tf->ic->acc->set, "proxy" ) ); 904 char *proxy, *next;890 char *proxy, *next, *errmsg = NULL; 905 891 char port[6]; 906 892 char host[INET6_ADDRSTRLEN]; … … 913 899 *next++ = '\0'; 914 900 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 } 924 916 } else if( strcmp( proxy, "<auto>" ) == 0 ) { 925 917 while ( streamhosts ) { … … 1020 1012 1021 1013 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_addr1058 , 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 else1066 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in6 *) saddr )->sin6_port ) );1067 1068 return TRUE;1069 1014 } 1070 1015 -
protocols/msn/invitation.c
r66be784 ra02f34f 28 28 #include "invitation.h" 29 29 #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" 44 31 45 32 #ifdef debug … … 78 65 if( (op) == -1 ) \ 79 66 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_addr116 , 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 else124 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in6 *) saddr )->sin6_port ) );125 126 return TRUE;127 }128 67 129 68 void msn_ftp_invitation_cmd( struct im_connection *ic, char *who, int cookie, char *icmd, … … 282 221 char host[INET6_ADDRSTRLEN]; 283 222 char port[6]; 223 char *errmsg; 284 224 285 225 msn_file->auth_cookie = acookie; 286 226 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 } 289 231 290 232 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.