Use signed size_t wherever appropriate

dynamic-accesslists
erdgeist 18 years ago
parent 11abb03e85
commit 6e1ee92de6

@ -130,7 +130,7 @@ static void sendmallocdata( const int64 s, char *buffer, size_t size ) {
static void senddata( const int64 s, char *buffer, size_t size ) { static void senddata( const int64 s, char *buffer, size_t size ) {
struct http_data *h = io_getcookie( s ); struct http_data *h = io_getcookie( s );
size_t written_size; ssize_t written_size;
/* whoever sends data is not interested in its input-array */ /* whoever sends data is not interested in its input-array */
if( h ) if( h )
@ -167,6 +167,7 @@ static void httpresponse( const int64 s, char *data ) {
int numwant, tmp, scanon, mode; int numwant, tmp, scanon, mode;
unsigned short port = htons(6881); unsigned short port = htons(6881);
time_t t; time_t t;
ssize_t len;
size_t reply_size = 0, reply_off; size_t reply_size = 0, reply_off;
#ifdef _DEBUG_HTTPERROR #ifdef _DEBUG_HTTPERROR
@ -208,7 +209,7 @@ static void httpresponse( const int64 s, char *data ) {
} }
if( !hash ) HTTPERROR_400_PARAM; if( !hash ) HTTPERROR_400_PARAM;
if( ( reply_size = return_sync_for_torrent( hash, &reply ) ) <= 0 ) HTTPERROR_500; if( !( reply_size = return_sync_for_torrent( hash, &reply ) ) ) HTTPERROR_500;
return sendmallocdata( s, reply, reply_size ); return sendmallocdata( s, reply, reply_size );
case 5: /* stats ? */ case 5: /* stats ? */
@ -226,8 +227,7 @@ static void httpresponse( const int64 s, char *data ) {
scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE ); scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
continue; continue;
} }
size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); if( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) != 4 ) HTTPERROR_400_PARAM;
if( len <= 0 ) HTTPERROR_400_PARAM;
if( !byte_diff(data,4,"mrtg")) if( !byte_diff(data,4,"mrtg"))
mode = STATS_MRTG; mode = STATS_MRTG;
else if( !byte_diff(data,4,"top5")) else if( !byte_diff(data,4,"top5"))
@ -238,7 +238,7 @@ static void httpresponse( const int64 s, char *data ) {
} }
/* Enough for http header + whole scrape string */ /* Enough for http header + whole scrape string */
if( ( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) <= 0 ) HTTPERROR_500; if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500;
break; break;
case 6: /* scrape ? */ case 6: /* scrape ? */
@ -266,12 +266,12 @@ SCRAPE_WORKAROUND:
/* Scanned whole query string, no hash means full scrape... you might want to limit that */ /* Scanned whole query string, no hash means full scrape... you might want to limit that */
if( !hash ) { if( !hash ) {
if( ( reply_size = return_fullscrape_for_tracker( &reply ) ) <= 0 ) HTTPERROR_500; if( !( reply_size = return_fullscrape_for_tracker( &reply ) ) ) HTTPERROR_500;
return sendmallocdata( s, reply, reply_size ); return sendmallocdata( s, reply, reply_size );
} }
/* Enough for http header + whole scrape string */ /* Enough for http header + whole scrape string */
if( ( reply_size = return_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) <= 0 ) HTTPERROR_500; if( !( reply_size = return_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500;
break; break;
case 8: case 8:
if( byte_diff( data, 8, "announce" ) ) HTTPERROR_404; if( byte_diff( data, 8, "announce" ) ) HTTPERROR_404;
@ -292,8 +292,8 @@ ANNOUNCE_WORKAROUND:
#ifdef WANT_IP_FROM_QUERY_STRING #ifdef WANT_IP_FROM_QUERY_STRING
case 2: case 2:
if(!byte_diff(data,2,"ip")) { if(!byte_diff(data,2,"ip")) {
size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE );
unsigned char ip[4]; unsigned char ip[4];
len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE );
if( ( len <= 0 ) || scan_fixed_ip( data, len, ip ) ) HTTPERROR_400_PARAM; if( ( len <= 0 ) || scan_fixed_ip( data, len, ip ) ) HTTPERROR_400_PARAM;
OT_SETIP( &peer, ip ); OT_SETIP( &peer, ip );
} else } else
@ -302,12 +302,11 @@ ANNOUNCE_WORKAROUND:
#endif #endif
case 4: case 4:
if( !byte_diff( data, 4, "port" ) ) { if( !byte_diff( data, 4, "port" ) ) {
size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE );
if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) || ( tmp > 0xffff ) ) HTTPERROR_400_PARAM; if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) || ( tmp > 0xffff ) ) HTTPERROR_400_PARAM;
port = htons( tmp ); OT_SETPORT( &peer, &port ); port = htons( tmp ); OT_SETPORT( &peer, &port );
} else if( !byte_diff( data, 4, "left" ) ) { } else if( !byte_diff( data, 4, "left" ) ) {
size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); if( ( len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) <= 0 ) HTTPERROR_400_PARAM;
if( len <= 0 ) HTTPERROR_400_PARAM;
if( scan_fixed_int( data, len, &tmp ) ) tmp = 0; if( scan_fixed_int( data, len, &tmp ) ) tmp = 0;
if( !tmp ) OT_FLAG( &peer ) |= PEER_FLAG_SEEDING; if( !tmp ) OT_FLAG( &peer ) |= PEER_FLAG_SEEDING;
} else } else
@ -330,11 +329,11 @@ ANNOUNCE_WORKAROUND:
break; break;
case 7: case 7:
if(!byte_diff(data,7,"numwant")) { if(!byte_diff(data,7,"numwant")) {
size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE );
if( ( len <= 0 ) || scan_fixed_int( data, len, &numwant ) ) HTTPERROR_400_PARAM; if( ( len <= 0 ) || scan_fixed_int( data, len, &numwant ) ) HTTPERROR_400_PARAM;
if( numwant > 200 ) numwant = 200; if( numwant > 200 ) numwant = 200;
} else if(!byte_diff(data,7,"compact")) { } else if(!byte_diff(data,7,"compact")) {
size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE );
if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) ) HTTPERROR_400_PARAM; if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) ) HTTPERROR_400_PARAM;
if( !tmp ) HTTPERROR_400_COMPACT; if( !tmp ) HTTPERROR_400_COMPACT;
} else } else
@ -352,7 +351,7 @@ ANNOUNCE_WORKAROUND:
} }
} }
/* Scanned whole query string */ /* Scanned whole query string XXX better send Error */
if( !hash ) HTTPERROR_400_PARAM; if( !hash ) HTTPERROR_400_PARAM;
if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) {
@ -360,7 +359,7 @@ ANNOUNCE_WORKAROUND:
reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d8:completei0e10:incompletei0e8:intervali%ie5:peers0:e", OT_CLIENT_REQUEST_INTERVAL_RANDOM ); reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d8:completei0e10:incompletei0e8:intervali%ie5:peers0:e", OT_CLIENT_REQUEST_INTERVAL_RANDOM );
} else { } else {
torrent = add_peer_to_torrent( hash, &peer ); torrent = add_peer_to_torrent( hash, &peer );
if( !torrent || ( reply_size = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) <= 0 ) HTTPERROR_500; if( !torrent || !( reply_size = return_peers_for_torrent( torrent, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500;
} }
ot_overall_successfulannounces++; ot_overall_successfulannounces++;
break; break;
@ -382,7 +381,7 @@ ANNOUNCE_WORKAROUND:
HTTPERROR_404; HTTPERROR_404;
} }
if( reply_size <= 0 ) HTTPERROR_500; if( !reply_size ) HTTPERROR_500;
/* This one is rather ugly, so I take you step by step through it. /* This one is rather ugly, so I take you step by step through it.
@ -449,7 +448,7 @@ static void help( char *name ) {
static void handle_read( const int64 clientsocket ) { static void handle_read( const int64 clientsocket ) {
struct http_data* h = io_getcookie( clientsocket ); struct http_data* h = io_getcookie( clientsocket );
int64 l; ssize_t l;
if( ( l = io_tryread( clientsocket, static_inbuf, sizeof static_inbuf ) ) <= 0 ) { if( ( l = io_tryread( clientsocket, static_inbuf, sizeof static_inbuf ) ) <= 0 ) {
if( h ) { if( h ) {

@ -21,7 +21,7 @@ static int is_unreserved( unsigned char c ) {
if( ( c <= 32 ) || ( c >= 127 ) ) return 0; return 1&(reserved_matrix[(c-32)>>3]>>(c&7)); if( ( c <= 32 ) || ( c >= 127 ) ) return 0; return 1&(reserved_matrix[(c-32)>>3]>>(c&7));
} }
size_t scan_urlencoded_query(char **string, char *deststring, int flags) { ssize_t scan_urlencoded_query(char **string, char *deststring, int flags) {
register const unsigned char* s=*(const unsigned char**) string; register const unsigned char* s=*(const unsigned char**) string;
unsigned char *d = (unsigned char*)deststring; unsigned char *d = (unsigned char*)deststring;
register unsigned char b, c; register unsigned char b, c;
@ -62,18 +62,17 @@ found_terminator:
return d - (unsigned char*)deststring; return d - (unsigned char*)deststring;
} }
size_t scan_fixed_int( char *data, size_t len, int *tmp ) { ssize_t scan_fixed_int( char *data, size_t len, int *tmp ) {
*tmp = 0; *tmp = 0;
while( (len > 0) && (*data >= '0') && (*data <= '9') ) { --len; *tmp = 10**tmp + *data++-'0'; } while( (len > 0) && (*data >= '0') && (*data <= '9') ) { --len; *tmp = 10**tmp + *data++-'0'; }
return len; return len;
} }
size_t scan_fixed_ip( char *data, size_t len, unsigned char ip[4] ) { ssize_t scan_fixed_ip( char *data, size_t len, unsigned char ip[4] ) {
int u, i; int u, i;
for( i=0; i<4; ++i ) { for( i=0; i<4; ++i ) {
register unsigned int j; ssize_t j = scan_fixed_int( data, len, &u );
j = scan_fixed_int( data, len, &u );
if( j == len ) return len; if( j == len ) return len;
ip[i] = u; ip[i] = u;
data += len - j; data += len - j;

@ -14,20 +14,20 @@
returns number of valid converted characters in deststring returns number of valid converted characters in deststring
or -1 for parse error or -1 for parse error
*/ */
size_t scan_urlencoded_query(char **string, char *deststring, int flags); ssize_t scan_urlencoded_query(char **string, char *deststring, int flags);
/* data pointer to len chars of string /* data pointer to len chars of string
len length of chars in data to parse len length of chars in data to parse
number number to receive result number number to receive result
returns number of bytes not parsed, mostly !=0 means fail returns number of bytes not parsed, mostly !=0 means fail
*/ */
size_t scan_fixed_int( char *data, size_t len, int *number ); ssize_t scan_fixed_int( char *data, size_t len, int *number );
/* data pointer to len chars of string /* data pointer to len chars of string
len length of chars in data to parse len length of chars in data to parse
ip buffer to receive result ip buffer to receive result
returns number of bytes not parsed, mostly !=0 means fail returns number of bytes not parsed, mostly !=0 means fail
*/ */
size_t scan_fixed_ip( char *data, size_t len, unsigned char ip[4] ); ssize_t scan_fixed_ip( char *data, size_t len, unsigned char ip[4] );
#endif #endif

Loading…
Cancel
Save