Introduce configuration dependent number of parameters in a nicer way

dynamic-accesslists
erdgeist 17 years ago
parent 5aa41e9d82
commit 8acc0ff48f

@ -76,6 +76,9 @@ static size_t ot_sockets_count = 0;
#ifdef _DEBUG_HTTPERROR #ifdef _DEBUG_HTTPERROR
static char debug_request[8192]; static char debug_request[8192];
#define _DEBUG_HTTPERROR_PARAM( param ) , param
#else
#define _DEBUG_HTTPERROR_PARAM( param )
#endif #endif
typedef enum { typedef enum {
@ -99,12 +102,7 @@ static int ot_ip_compare( const void *a, const void *b ) { return memcmp( a,b,4
int main( int argc, char **argv ); int main( int argc, char **argv );
static void httperror( const int64 s, const char *title, const char *message ); static void httperror( const int64 s, const char *title, const char *message );
static void httpresponse( const int64 s, char *data _DEBUG_HTTPERROR_PARAM(size_t l ) );
#ifdef _DEBUG_HTTPERROR
static void httpresponse( const int64 s, char *data, size_t l );
#else
static void httpresponse( const int64 s, char *data );
#endif
static void sendmmapdata( const int64 s, char *buffer, const size_t size ); static void sendmmapdata( const int64 s, char *buffer, const size_t size );
static void senddata( const int64 s, char *buffer, const size_t size ); static void senddata( const int64 s, char *buffer, const size_t size );
@ -226,11 +224,7 @@ static void senddata( const int64 s, char *buffer, size_t size ) {
} }
} }
#ifdef _DEBUG_HTTPERROR static void httpresponse( const int64 s, char *data _DEBUG_HTTPERROR_PARAM( size_t l ) ) {
static void httpresponse( const int64 s, char *data, size_t l ) {
#else
static void httpresponse( const int64 s, char *data ) {
#endif
struct http_data* h = io_getcookie( s ); struct http_data* h = io_getcookie( s );
char *c, *reply; char *c, *reply;
ot_peer peer; ot_peer peer;
@ -675,13 +669,8 @@ static void handle_read( const int64 clientsocket ) {
/* If we get the whole request in one packet, handle it without copying */ /* If we get the whole request in one packet, handle it without copying */
if( !array_start( &h->request ) ) { if( !array_start( &h->request ) ) {
if( memchr( static_inbuf, '\n', l ) ) { if( memchr( static_inbuf, '\n', l ) )
return httpresponse( clientsocket, static_inbuf return httpresponse( clientsocket, static_inbuf _DEBUG_HTTPERROR_PARAM( l ) );
#ifdef _DEBUG_HTTPERROR
, l
#endif
);
}
h->flag |= STRUCT_HTTP_FLAG_ARRAY_USED; h->flag |= STRUCT_HTTP_FLAG_ARRAY_USED;
return array_catb( &h->request, static_inbuf, l ); return array_catb( &h->request, static_inbuf, l );
} }
@ -695,13 +684,8 @@ static void handle_read( const int64 clientsocket ) {
if( ( array_bytes( &h->request ) > 8192 ) && NOTBLESSED( h ) ) if( ( array_bytes( &h->request ) > 8192 ) && NOTBLESSED( h ) )
return httperror( clientsocket, "500 request too long", "You sent too much headers"); return httperror( clientsocket, "500 request too long", "You sent too much headers");
if( memchr( array_start( &h->request ), '\n', array_bytes( &h->request ) ) ) { if( memchr( array_start( &h->request ), '\n', array_bytes( &h->request ) ) )
return httpresponse( clientsocket, array_start( &h->request ) return httpresponse( clientsocket, array_start( &h->request ) _DEBUG_HTTPERROR_PARAM( array_bytes( &h->request ) ) );
#ifdef _DEBUG_HTTPERROR
, array_bytes( &h->request )
#endif
);
}
} }
static void handle_write( const int64 clientsocket ) { static void handle_write( const int64 clientsocket ) {

@ -145,11 +145,7 @@ static void vector_remove_torrent( ot_vector *vector, ot_torrent *match ) {
} }
} }
#ifdef WANT_TRACKER_SYNC ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) ) {
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset ) {
#else
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
#endif
int exactmatch; int exactmatch;
ot_torrent *torrent; ot_torrent *torrent;
ot_peer *peer_dest; ot_peer *peer_dest;

@ -98,16 +98,18 @@ typedef struct {
Exported functions Exported functions
*/ */
#ifdef WANT_TRACKER_SYNC
#define WANT_TRACKER_SYNC_PARAM( param ) , param
#else
#define WANT_TRACKER_SYNC_PARAM( param )
#endif
int init_logic( const char * const serverdir ); int init_logic( const char * const serverdir );
void deinit_logic( void ); void deinit_logic( void );
enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, STATS_SLASH24S_OLD, SYNC_IN, SYNC_OUT, STATS_FULLSCRAPE }; enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, STATS_SLASH24S_OLD, SYNC_IN, SYNC_OUT, STATS_FULLSCRAPE };
#ifdef WANT_TRACKER_SYNC ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) );
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset );
#else
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer );
#endif
size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp );
size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp ); size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp );
size_t return_fullscrape_for_tracker( char **reply ); size_t return_fullscrape_for_tracker( char **reply );

Loading…
Cancel
Save