Some syntax errors removed

dynamic-accesslists
erdgeist 18 years ago
parent 83e339bbe0
commit 898206ac7a

@ -2,7 +2,7 @@ CC?=gcc
CFLAGS+=-I../libowfat -Wall -O2 -pipe CFLAGS+=-I../libowfat -Wall -O2 -pipe
LDFLAGS+=-L../libowfat/ -lowfat -s LDFLAGS+=-L../libowfat/ -lowfat -s
SOURCES=opentracker.c trackerlogic.c SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c
opentracker: $(SOURCES) opentracker: $(SOURCES)
$(CC) $(SOURCES) -o opentracker $(CFLAGS) $(LDFLAGS) $(CC) $(SOURCES) -o opentracker $(CFLAGS) $(LDFLAGS)

@ -14,6 +14,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include "trackerlogic.h"
#include "scan_urlencoded_query.h"
static void carp(const char* routine) { static void carp(const char* routine) {
buffer_puts(buffer_2,routine); buffer_puts(buffer_2,routine);
buffer_puts(buffer_2,": "); buffer_puts(buffer_2,": ");
@ -112,9 +115,7 @@ e400:
} }
else else
{ {
char *d; char *d, *data;
int64 fd;
struct stat s;
// expect 'GET /uri?nnbjhg HTTP/1.*' // expect 'GET /uri?nnbjhg HTTP/1.*'
c+=4; c+=4;
@ -130,19 +131,18 @@ e400:
switch( scan_urlencoded_query( &c, data, SCAN_PATH ) ) { switch( scan_urlencoded_query( &c, data, SCAN_PATH ) ) {
case 6: /* scrape ? */ case 6: /* scrape ? */
if (!byte_diff(c,6,"scrape")) if (!byte_diff(c,6,"scrape"))
goto 404; goto e404;
break; break;
case 9: case 9:
if( !byte_diff(c,8,"announce")) if( !byte_diff(c,8,"announce"))
goto 404; goto e404;
else { else {
// info_hash, left, port, numwant, compact // info_hash, left, port, numwant, compact
struct ot_peer peer; struct ot_peer peer;
ot_hash hash; byte_copy( peer.ip, 4, h->ip );
byte_copy( peer.ip, h->ip, 4);
peer.port = 6881; peer.port = 6881;
while( NOCHAMSCANNEN ) { while( 1 ) {
data = c; data = c;
switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) { switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) {
case -1: /* error */ case -1: /* error */
@ -150,20 +150,21 @@ e400:
goto e404; goto e404;
case 4: case 4:
if(!byte_diff(c,4,"port")) if(!byte_diff(c,4,"port"))
/* scan int */ /* scan int */ c;
else if(!byte_diff(c,4,"left")) else if(!byte_diff(c,4,"left"))
/* scan int */ /* scan int */ c;
break; break;
case 7: case 7:
if(!byte_diff(c,7,"numwant")) if(!byte_diff(c,7,"numwant"))
/* scan int */ /* scan int */ c;
else if(!byte_diff(c,7,"compact")) else if(!byte_diff(c,7,"compact"))
/* scan flag */ /* scan flag */ c;
break; break;
case 9: /* info_hash */ case 9: /* info_hash */
if(!byte_diff(c,9,"info_hash")) if(!byte_diff(c,9,"info_hash")) c;
/* scan 20 bytes */ /* scan 20 bytes */
break; break;
}
} }
} }
break; break;
@ -176,13 +177,13 @@ e400:
c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain"); c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain");
c+=fmt_str(c,"\r\nContent-Length: "); c+=fmt_str(c,"\r\nContent-Length: ");
/* ANSWER SIZE*/ /* ANSWER SIZE*/
c+=fmt_ulonglong(c,s.st_size); c+=fmt_ulonglong(c, 100 );
c+=fmt_str(c,"\r\nLast-Modified: "); c+=fmt_str(c,"\r\nLast-Modified: ");
/* MODIFY DATE */ /* MODIFY DATE
c+=fmt_httpdate(c,s.st_mtime); c+=fmt_httpdate(c,s.st_mtime); */
c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); c+=fmt_str(c,"\r\nConnection: close\r\n\r\n");
iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf);
iob_addbuf(&h->iob,tracker_answer, tzracker_answer_size); iob_addbuf(&h->iob,tracker_answer, tracker_answer_size);
} }
e404: e404:
io_dontwantread(s); io_dontwantread(s);
@ -227,7 +228,7 @@ int main()
if (h) if (h)
{ {
byte_zero(h,sizeof(struct http_data)); byte_zero(h,sizeof(struct http_data));
byte_copy(h->ip,ip,sizeof(ip)); byte_copy(h->ip,sizeof(ip),ip);
io_setcookie(n,h); io_setcookie(n,h);
} else } else
io_close(n); io_close(n);

@ -1,13 +1,5 @@
#include "scan.h" #include "scan.h"
#include "scan_urlencoded_query.h"
#define BREAK_AT_QUESTIONMARK (1<<0)
#define BREAK_AT_WHITESPACE (1<<1)
#define BREAK_AT_AMPERSAND (1<<2)
#define BREAK_AT_EQUALSIGN (1<<3)
#define SCAN_PATH ( BREAK_AT_QUESTIONMARK | BREAK_AT_WHITESPACE )
#define SCAN_SEARCHPATH_PARAM ( BREAK_AT_EQUALSIGN )
#define SCAN_SEARCHPATH_VALUE ( BREAK_AT_AMPERSAND | BREAK_AT_WHITESPACE )
// Idea is to do a in place replacement or guarantee at least // Idea is to do a in place replacement or guarantee at least
// strlen( string ) bytes in deststring // strlen( string ) bytes in deststring
@ -17,19 +9,19 @@
// we add '%' to the matrix to not stop at encoded chars. // we add '%' to the matrix to not stop at encoded chars.
static const unsigned char reserved_matrix[] = { 0xA2, 0x63, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x47}; static const unsigned char reserved_matrix[] = { 0xA2, 0x63, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x47};
inline int is_unreserved( unsigned char c ) const { inline 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) { size_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;
const unsigned char *d = deststring; unsigned char *d = (unsigned char*)deststring;
register unsigned char b, c; register unsigned char b, c;
while ( is_unreserved( c = *s++) ) { while ( is_unreserved( c = *s++) ) {
if (c=='%') { if (c=='%') {
if( ( c = scan_fromhex(*s++) ) < 0 ) return -1; if( ( c = scan_fromhex(*s++) ) == 0xff ) return -1;
if( ( b = scan_fromhex(*s++) ) < 0 ) return -1; if( ( b = scan_fromhex(*s++) ) == 0xff ) return -1;
c=(c<<4)|b; c=(c<<4)|b;
} }
*d++ = c; *d++ = c;
@ -37,21 +29,21 @@ size_t scan_urlencoded_query(char **string, char *deststring, int flags) {
switch( c ) { switch( c ) {
case 0: case '\r': case '\n': case ' ': case 0: case '\r': case '\n': case ' ':
if ( flags & BREAK_AT_WHITESPACE == 0 ) return -1; if ( ( flags & BREAK_AT_WHITESPACE ) == 0 ) return -1;
break; break;
case '?': case '?':
if ( flags & BREAK_AT_QUESTIONMARK == 0 ) return -1; if ( ( flags & BREAK_AT_QUESTIONMARK ) == 0 ) return -1;
break; break;
case '=': case '=':
if ( flags & BREAK_AT_EQUALSIGN == 0 ) return -1; if ( ( flags & BREAK_AT_EQUALSIGN ) == 0 ) return -1;
break; break;
case '&': case '&':
if ( flags & BREAK_AT_AMPERSAND == 0 ) return -1; if ( ( flags & BREAK_AT_AMPERSAND ) == 0 ) return -1;
break; break;
default: default:
return -1; return -1;
} }
*string = s; *string = (char *)s;
return d - deststring; return d - (unsigned char*)deststring;
} }

@ -1,4 +1,4 @@
#ifdef __SCAN_URLENCODED_QUERY_H__ #ifndef __SCAN_URLENCODED_QUERY_H__
#define __SCAN_URLENCODED_QUERY_H__ #define __SCAN_URLENCODED_QUERY_H__
#define BREAK_AT_QUESTIONMARK (1<<0) #define BREAK_AT_QUESTIONMARK (1<<0)

Loading…
Cancel
Save