summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-04-03 11:08:17 +0000
committererdgeist <>2007-04-03 11:08:17 +0000
commit5c18293c9c7b2c5f419135b1705f07460e7773b0 (patch)
tree6f86e247b14fdd03d23d0bbefc7277ca939db9d7
parentbd4617a911fb961c5251425fff3e531e3968867c (diff)
New Makefile, incorporated some patches sent to me by Robin H. Johnson
-rw-r--r--Makefile40
-rw-r--r--opentracker.c23
-rw-r--r--scan_urlencoded_query.c2
-rw-r--r--trackerlogic.c19
4 files changed, 54 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index dd5c728..178a8c8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,37 @@
1CC?=gcc 1CC?=gcc
2FEATURES=#-DWANT_IP_FROM_QUERY_STRING -DWANT_BLACKLIST -DWANT_CLOSED_TRACKER -D_DEBUG_HTTPERROR 2FEATURES=#-DWANT_IP_FROM_QUERY_STRING -D_DEBUG_HTTPERROR
3#DEBUG_OPTS=-g -ggdb -pg # -fprofile-arcs -ftest-coverage 3OPTS_debug=-g -ggdb #-pg # -fprofile-arcs -ftest-coverage
4DEBUG_OPTS=-s -Os 4OPTS_production=-s -Os
5CFLAGS+=-I../libowfat -Wall -pipe# -pedantic -ansi 5CFLAGS+=-I../libowfat -Wall -pipe -Wextra #-pedantic #-ansi
6LDFLAGS+=-L../libowfat/ -lowfat 6LDFLAGS+=-L../libowfat/ -lowfat
7 7
8BINARY = opentracker
8HEADERS=trackerlogic.h scan_urlencoded_query.h 9HEADERS=trackerlogic.h scan_urlencoded_query.h
9SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c 10SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c
11
12all: $(BINARY) $(BINARY).debug
13
14CFLAGS_production = $(CFLAGS) $(OPTS_production) $(FEATURES)
15CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES)
16
17OBJECTS_debug = $(SOURCES:%.c=%.debug.o)
18OBJECTS_production = $(SOURCES:%.c=%.production.o)
19
20$(OBJECTS_debug) $(OBJECTS_production): $(HEADERS)
21
22%.production.o : CFLAGS := $(CFLAGS_production)
23%.debug.o : CFLAGS := $(CFLAGS_debug)
10 24
11opentracker: $(SOURCES) $(HEADERS) 25%.production.o : %.c
12 $(CC) $(SOURCES) -o opentracker $(CFLAGS) $(FEATURES) $(DEBUG_OPTS) $(LDFLAGS) 26 $(COMPILE.c) $(OUTPUT_OPTION) $<
27%.debug.o : %.c
28 $(COMPILE.c) $(OUTPUT_OPTION) $<
13 29
14clean: 30$(BINARY): $(OBJECTS_production)
15 rm -rf opentracker 31 $(CC) $^ -o $@ $(CFLAGS_production) $(LDFLAGS)
32$(BINARY).debug: $(OBJECTS_debug)
33 $(CC) $^ -o $@ $(CFLAGS_debug) $(LDFLAGS)
34
35 clean:
36 rm -rf opentracker *.o *~
37
diff --git a/opentracker.c b/opentracker.c
index f9dc48b..0d4f2b5 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -154,7 +154,7 @@ static void senddata( const int64 s, char *buffer, size_t size ) {
154 array_reset( &h->request ); 154 array_reset( &h->request );
155 155
156 written_size = write( s, buffer, size ); 156 written_size = write( s, buffer, size );
157 if( ( written_size < 0 ) || ( written_size == size ) ) { 157 if( ( written_size < 0 ) || ( (size_t)written_size == size ) ) {
158 free( h ); io_close( s ); 158 free( h ); io_close( s );
159 } else { 159 } else {
160 char * outbuf = malloc( size - written_size ); 160 char * outbuf = malloc( size - written_size );
@@ -594,15 +594,15 @@ static void handle_timeouted( void ) {
594} 594}
595 595
596static void handle_udp4( int64 serversocket ) { 596static void handle_udp4( int64 serversocket ) {
597 ot_peer peer; 597 ot_peer peer;
598 ot_torrent *torrent; 598 ot_torrent *torrent;
599 ot_hash *hash = NULL; 599 ot_hash *hash = NULL;
600 char remoteip[4]; 600 char remoteip[4];
601 unsigned long *inpacket = (unsigned long*)static_inbuf; 601 ot_dword *inpacket = (ot_dword*)static_inbuf;
602 unsigned long *outpacket = (unsigned long*)static_outbuf; 602 ot_dword *outpacket = (ot_dword*)static_outbuf;
603 unsigned long numwant, left, event; 603 ot_dword numwant, left, event;
604 uint16 port, remoteport; 604 ot_word port, remoteport;
605 size_t r, r_out; 605 size_t r, r_out;
606 606
607 r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport); 607 r = socket_recv4( serversocket, static_inbuf, 8192, remoteip, &remoteport);
608 608
@@ -627,8 +627,9 @@ static void handle_udp4( int64 serversocket ) {
627 numwant = 200; 627 numwant = 200;
628 /* We do only want to know, if it is zero */ 628 /* We do only want to know, if it is zero */
629 left = inpacket[64/4] | inpacket[68/4]; 629 left = inpacket[64/4] | inpacket[68/4];
630
630 event = ntohl( inpacket[80/4] ); 631 event = ntohl( inpacket[80/4] );
631 port = *(unsigned short*)( static_inbuf + 96 ); 632 port = *(ot_word*)( static_inbuf + 96 );
632 hash = (ot_hash*)( static_inbuf + 16 ); 633 hash = (ot_hash*)( static_inbuf + 16 );
633 634
634 OT_SETIP( &peer, remoteip ); 635 OT_SETIP( &peer, remoteip );
diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c
index f9c38ed..296e829 100644
--- a/scan_urlencoded_query.c
+++ b/scan_urlencoded_query.c
@@ -73,7 +73,7 @@ ssize_t scan_fixed_ip( char *data, size_t len, unsigned char ip[4] ) {
73 73
74 for( i=0; i<4; ++i ) { 74 for( i=0; i<4; ++i ) {
75 ssize_t j = scan_fixed_int( data, len, &u ); 75 ssize_t j = scan_fixed_int( data, len, &u );
76 if( j == len ) return len; 76 if( j == (ssize_t)len ) return len;
77 ip[i] = u; 77 ip[i] = u;
78 data += len - j; 78 data += len - j;
79 len = j; 79 len = j;
diff --git a/trackerlogic.c b/trackerlogic.c
index 5bda0df..bdf120f 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -243,9 +243,9 @@ size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply
243 if( is_tcp ) 243 if( is_tcp )
244 r += sprintf( r, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers%zd:", seed_count, peer_count-seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM, 6*amount ); 244 r += sprintf( r, "d8:completei%zde10:incompletei%zde8:intervali%ie5:peers%zd:", seed_count, peer_count-seed_count, OT_CLIENT_REQUEST_INTERVAL_RANDOM, 6*amount );
245 else { 245 else {
246 *(unsigned long*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM ); 246 *(ot_dword*)(r+0) = htonl( OT_CLIENT_REQUEST_INTERVAL_RANDOM );
247 *(unsigned long*)(r+4) = htonl( peer_count ); 247 *(ot_dword*)(r+4) = htonl( peer_count );
248 *(unsigned long*)(r+8) = htonl( seed_count ); 248 *(ot_dword*)(r+8) = htonl( seed_count );
249 r += 12; 249 r += 12;
250 } 250 }
251 251
@@ -357,7 +357,7 @@ size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) {
357 if( !exactmatch ) { 357 if( !exactmatch ) {
358 memset( reply, 0, 12); 358 memset( reply, 0, 12);
359 } else { 359 } else {
360 unsigned long *r = (unsigned long*) reply; 360 ot_dword *r = (ot_dword*) reply;
361 361
362 for( i=0; i<OT_POOLS_COUNT; ++i ) { 362 for( i=0; i<OT_POOLS_COUNT; ++i ) {
363 peers += torrent->peer_list->peers[i].size; 363 peers += torrent->peer_list->peers[i].size;
@@ -394,7 +394,7 @@ size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ) {
394/* Throw away old changeset */ 394/* Throw away old changeset */
395static void release_changeset( void ) { 395static void release_changeset( void ) {
396 ot_byte **changeset_ptrs = (ot_byte**)(changeset.data); 396 ot_byte **changeset_ptrs = (ot_byte**)(changeset.data);
397 int i; 397 size_t i;
398 398
399 for( i = 0; i < changeset.size; ++i ) 399 for( i = 0; i < changeset.size; ++i )
400 free( changeset_ptrs[i] ); 400 free( changeset_ptrs[i] );
@@ -507,7 +507,8 @@ size_t return_changeset_for_tracker( char **reply ) {
507/* Clean up all torrents, remove timedout pools and 507/* Clean up all torrents, remove timedout pools and
508 torrents, also prepare new changeset */ 508 torrents, also prepare new changeset */
509void clean_all_torrents( void ) { 509void clean_all_torrents( void ) {
510 int i, j, k; 510 int i, k;
511 size_t j;
511 time_t time_now = NOW; 512 time_t time_now = NOW;
512 size_t peers_count; 513 size_t peers_count;
513 514
@@ -566,7 +567,7 @@ void clean_all_torrents( void ) {
566 } 567 }
567} 568}
568 569
569typedef struct { int val; ot_torrent * torrent; } ot_record; 570typedef struct { size_t val; ot_torrent * torrent; } ot_record;
570 571
571/* Fetches stats from tracker */ 572/* Fetches stats from tracker */
572size_t return_stats_for_tracker( char *reply, int mode ) { 573size_t return_stats_for_tracker( char *reply, int mode ) {
@@ -611,11 +612,11 @@ size_t return_stats_for_tracker( char *reply, int mode ) {
611 r += sprintf( r, "Top5 torrents by peers:\n" ); 612 r += sprintf( r, "Top5 torrents by peers:\n" );
612 for( idx=0; idx<5; ++idx ) 613 for( idx=0; idx<5; ++idx )
613 if( top5c[idx].torrent ) 614 if( top5c[idx].torrent )
614 r += sprintf( r, "\t%i\t%s\n", top5c[idx].val, to_hex(top5c[idx].torrent->hash) ); 615 r += sprintf( r, "\t%zd\t%s\n", top5c[idx].val, to_hex(top5c[idx].torrent->hash) );
615 r += sprintf( r, "Top5 torrents by seeds:\n" ); 616 r += sprintf( r, "Top5 torrents by seeds:\n" );
616 for( idx=0; idx<5; ++idx ) 617 for( idx=0; idx<5; ++idx )
617 if( top5s[idx].torrent ) 618 if( top5s[idx].torrent )
618 r += sprintf( r, "\t%i\t%s\n", top5s[idx].val, to_hex(top5s[idx].torrent->hash) ); 619 r += sprintf( r, "\t%zd\t%s\n", top5s[idx].val, to_hex(top5s[idx].torrent->hash) );
619 } else { 620 } else {
620 r += sprintf( r, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", peer_count, seed_count, torrent_count ); 621 r += sprintf( r, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", peer_count, seed_count, torrent_count );
621 } 622 }