diff options
author | erdgeist <> | 2006-12-08 20:28:17 +0000 |
---|---|---|
committer | erdgeist <> | 2006-12-08 20:28:17 +0000 |
commit | 898206ac7a254325a53f1a4c418ce702755de040 (patch) | |
tree | b831d48bbbbca43d265d3e01c883ed91e786aed4 | |
parent | 83e339bbe05e150c819f8e5a90ebe5d6861b4b34 (diff) |
Some syntax errors removed
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | opentracker.c | 37 | ||||
-rw-r--r-- | scan_urlencoded_query.c | 32 | ||||
-rw-r--r-- | scan_urlencoded_query.h | 2 |
4 files changed, 33 insertions, 40 deletions
@@ -2,7 +2,7 @@ CC?=gcc | |||
2 | CFLAGS+=-I../libowfat -Wall -O2 -pipe | 2 | CFLAGS+=-I../libowfat -Wall -O2 -pipe |
3 | LDFLAGS+=-L../libowfat/ -lowfat -s | 3 | LDFLAGS+=-L../libowfat/ -lowfat -s |
4 | 4 | ||
5 | SOURCES=opentracker.c trackerlogic.c | 5 | SOURCES=opentracker.c trackerlogic.c scan_urlencoded_query.c |
6 | 6 | ||
7 | opentracker: $(SOURCES) | 7 | opentracker: $(SOURCES) |
8 | $(CC) $(SOURCES) -o opentracker $(CFLAGS) $(LDFLAGS) | 8 | $(CC) $(SOURCES) -o opentracker $(CFLAGS) $(LDFLAGS) |
diff --git a/opentracker.c b/opentracker.c index 4a421cc..c420d6f 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -14,6 +14,9 @@ | |||
14 | #include <stdlib.h> | 14 | #include <stdlib.h> |
15 | #include <errno.h> | 15 | #include <errno.h> |
16 | 16 | ||
17 | #include "trackerlogic.h" | ||
18 | #include "scan_urlencoded_query.h" | ||
19 | |||
17 | static void carp(const char* routine) { | 20 | static void carp(const char* routine) { |
18 | buffer_puts(buffer_2,routine); | 21 | buffer_puts(buffer_2,routine); |
19 | buffer_puts(buffer_2,": "); | 22 | buffer_puts(buffer_2,": "); |
@@ -112,9 +115,7 @@ e400: | |||
112 | } | 115 | } |
113 | else | 116 | else |
114 | { | 117 | { |
115 | char *d; | 118 | char *d, *data; |
116 | int64 fd; | ||
117 | struct stat s; | ||
118 | 119 | ||
119 | // expect 'GET /uri?nnbjhg HTTP/1.*' | 120 | // expect 'GET /uri?nnbjhg HTTP/1.*' |
120 | c+=4; | 121 | c+=4; |
@@ -130,19 +131,18 @@ e400: | |||
130 | switch( scan_urlencoded_query( &c, data, SCAN_PATH ) ) { | 131 | switch( scan_urlencoded_query( &c, data, SCAN_PATH ) ) { |
131 | case 6: /* scrape ? */ | 132 | case 6: /* scrape ? */ |
132 | if (!byte_diff(c,6,"scrape")) | 133 | if (!byte_diff(c,6,"scrape")) |
133 | goto 404; | 134 | goto e404; |
134 | break; | 135 | break; |
135 | case 9: | 136 | case 9: |
136 | if( !byte_diff(c,8,"announce")) | 137 | if( !byte_diff(c,8,"announce")) |
137 | goto 404; | 138 | goto e404; |
138 | else { | 139 | else { |
139 | // info_hash, left, port, numwant, compact | 140 | // info_hash, left, port, numwant, compact |
140 | struct ot_peer peer; | 141 | struct ot_peer peer; |
141 | ot_hash hash; | 142 | byte_copy( peer.ip, 4, h->ip ); |
142 | byte_copy( peer.ip, h->ip, 4); | ||
143 | peer.port = 6881; | 143 | peer.port = 6881; |
144 | 144 | ||
145 | while( NOCHAMSCANNEN ) { | 145 | while( 1 ) { |
146 | data = c; | 146 | data = c; |
147 | switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) { | 147 | switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) { |
148 | case -1: /* error */ | 148 | case -1: /* error */ |
@@ -150,20 +150,21 @@ e400: | |||
150 | goto e404; | 150 | goto e404; |
151 | case 4: | 151 | case 4: |
152 | if(!byte_diff(c,4,"port")) | 152 | if(!byte_diff(c,4,"port")) |
153 | /* scan int */ | 153 | /* scan int */ c; |
154 | else if(!byte_diff(c,4,"left")) | 154 | else if(!byte_diff(c,4,"left")) |
155 | /* scan int */ | 155 | /* scan int */ c; |
156 | break; | 156 | break; |
157 | case 7: | 157 | case 7: |
158 | if(!byte_diff(c,7,"numwant")) | 158 | if(!byte_diff(c,7,"numwant")) |
159 | /* scan int */ | 159 | /* scan int */ c; |
160 | else if(!byte_diff(c,7,"compact")) | 160 | else if(!byte_diff(c,7,"compact")) |
161 | /* scan flag */ | 161 | /* scan flag */ c; |
162 | break; | 162 | break; |
163 | case 9: /* info_hash */ | 163 | case 9: /* info_hash */ |
164 | if(!byte_diff(c,9,"info_hash")) | 164 | if(!byte_diff(c,9,"info_hash")) c; |
165 | /* scan 20 bytes */ | 165 | /* scan 20 bytes */ |
166 | break; | 166 | break; |
167 | } | ||
167 | } | 168 | } |
168 | } | 169 | } |
169 | break; | 170 | break; |
@@ -176,13 +177,13 @@ e400: | |||
176 | c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain"); | 177 | c+=fmt_str(c,"HTTP/1.1 Coming Up\r\nContent-Type: text/plain"); |
177 | c+=fmt_str(c,"\r\nContent-Length: "); | 178 | c+=fmt_str(c,"\r\nContent-Length: "); |
178 | /* ANSWER SIZE*/ | 179 | /* ANSWER SIZE*/ |
179 | c+=fmt_ulonglong(c,s.st_size); | 180 | c+=fmt_ulonglong(c, 100 ); |
180 | c+=fmt_str(c,"\r\nLast-Modified: "); | 181 | c+=fmt_str(c,"\r\nLast-Modified: "); |
181 | /* MODIFY DATE */ | 182 | /* MODIFY DATE |
182 | c+=fmt_httpdate(c,s.st_mtime); | 183 | c+=fmt_httpdate(c,s.st_mtime); */ |
183 | c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); | 184 | c+=fmt_str(c,"\r\nConnection: close\r\n\r\n"); |
184 | iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); | 185 | iob_addbuf(&h->iob,h->hdrbuf,c - h->hdrbuf); |
185 | iob_addbuf(&h->iob,tracker_answer, tzracker_answer_size); | 186 | iob_addbuf(&h->iob,tracker_answer, tracker_answer_size); |
186 | } | 187 | } |
187 | e404: | 188 | e404: |
188 | io_dontwantread(s); | 189 | io_dontwantread(s); |
@@ -227,7 +228,7 @@ int main() | |||
227 | if (h) | 228 | if (h) |
228 | { | 229 | { |
229 | byte_zero(h,sizeof(struct http_data)); | 230 | byte_zero(h,sizeof(struct http_data)); |
230 | byte_copy(h->ip,ip,sizeof(ip)); | 231 | byte_copy(h->ip,sizeof(ip),ip); |
231 | io_setcookie(n,h); | 232 | io_setcookie(n,h); |
232 | } else | 233 | } else |
233 | io_close(n); | 234 | io_close(n); |
diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c index 7aeabab..6ba7808 100644 --- a/scan_urlencoded_query.c +++ b/scan_urlencoded_query.c | |||
@@ -1,13 +1,5 @@ | |||
1 | #include "scan.h" | 1 | #include "scan.h" |
2 | 2 | #include "scan_urlencoded_query.h" | |
3 | #define BREAK_AT_QUESTIONMARK (1<<0) | ||
4 | #define BREAK_AT_WHITESPACE (1<<1) | ||
5 | #define BREAK_AT_AMPERSAND (1<<2) | ||
6 | #define BREAK_AT_EQUALSIGN (1<<3) | ||
7 | |||
8 | #define SCAN_PATH ( BREAK_AT_QUESTIONMARK | BREAK_AT_WHITESPACE ) | ||
9 | #define SCAN_SEARCHPATH_PARAM ( BREAK_AT_EQUALSIGN ) | ||
10 | #define SCAN_SEARCHPATH_VALUE ( BREAK_AT_AMPERSAND | BREAK_AT_WHITESPACE ) | ||
11 | 3 | ||
12 | // Idea is to do a in place replacement or guarantee at least | 4 | // Idea is to do a in place replacement or guarantee at least |
13 | // strlen( string ) bytes in deststring | 5 | // strlen( string ) bytes in deststring |
@@ -17,19 +9,19 @@ | |||
17 | // we add '%' to the matrix to not stop at encoded chars. | 9 | // we add '%' to the matrix to not stop at encoded chars. |
18 | 10 | ||
19 | static const unsigned char reserved_matrix[] = { 0xA2, 0x63, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x47}; | 11 | static const unsigned char reserved_matrix[] = { 0xA2, 0x63, 0xFF, 0x03, 0xFE, 0xFF, 0xFF, 0x87, 0xFE, 0xFF, 0xFF, 0x47}; |
20 | inline int is_unreserved( unsigned char c ) const { | 12 | inline int is_unreserved( unsigned char c ) { |
21 | if( ( c <= 32 ) || ( c >= 127 ) ) return 0; return 1&(reserved_matrix[(c-32)>>3]>>(c&7)); | 13 | if( ( c <= 32 ) || ( c >= 127 ) ) return 0; return 1&(reserved_matrix[(c-32)>>3]>>(c&7)); |
22 | } | 14 | } |
23 | 15 | ||
24 | size_t scan_urlencoded_query(char **string, char *deststring, int flags) { | 16 | size_t scan_urlencoded_query(char **string, char *deststring, int flags) { |
25 | register const unsigned char* s=*(const unsigned char*) string; | 17 | register const unsigned char* s=*(const unsigned char**) string; |
26 | const unsigned char *d = deststring; | 18 | unsigned char *d = (unsigned char*)deststring; |
27 | register unsigned char b, c; | 19 | register unsigned char b, c; |
28 | 20 | ||
29 | while ( is_unreserved( c = *s++) ) { | 21 | while ( is_unreserved( c = *s++) ) { |
30 | if (c=='%') { | 22 | if (c=='%') { |
31 | if( ( c = scan_fromhex(*s++) ) < 0 ) return -1; | 23 | if( ( c = scan_fromhex(*s++) ) == 0xff ) return -1; |
32 | if( ( b = scan_fromhex(*s++) ) < 0 ) return -1; | 24 | if( ( b = scan_fromhex(*s++) ) == 0xff ) return -1; |
33 | c=(c<<4)|b; | 25 | c=(c<<4)|b; |
34 | } | 26 | } |
35 | *d++ = c; | 27 | *d++ = c; |
@@ -37,21 +29,21 @@ size_t scan_urlencoded_query(char **string, char *deststring, int flags) { | |||
37 | 29 | ||
38 | switch( c ) { | 30 | switch( c ) { |
39 | case 0: case '\r': case '\n': case ' ': | 31 | case 0: case '\r': case '\n': case ' ': |
40 | if ( flags & BREAK_AT_WHITESPACE == 0 ) return -1; | 32 | if ( ( flags & BREAK_AT_WHITESPACE ) == 0 ) return -1; |
41 | break; | 33 | break; |
42 | case '?': | 34 | case '?': |
43 | if ( flags & BREAK_AT_QUESTIONMARK == 0 ) return -1; | 35 | if ( ( flags & BREAK_AT_QUESTIONMARK ) == 0 ) return -1; |
44 | break; | 36 | break; |
45 | case '=': | 37 | case '=': |
46 | if ( flags & BREAK_AT_EQUALSIGN == 0 ) return -1; | 38 | if ( ( flags & BREAK_AT_EQUALSIGN ) == 0 ) return -1; |
47 | break; | 39 | break; |
48 | case '&': | 40 | case '&': |
49 | if ( flags & BREAK_AT_AMPERSAND == 0 ) return -1; | 41 | if ( ( flags & BREAK_AT_AMPERSAND ) == 0 ) return -1; |
50 | break; | 42 | break; |
51 | default: | 43 | default: |
52 | return -1; | 44 | return -1; |
53 | } | 45 | } |
54 | 46 | ||
55 | *string = s; | 47 | *string = (char *)s; |
56 | return d - deststring; | 48 | return d - (unsigned char*)deststring; |
57 | } | 49 | } |
diff --git a/scan_urlencoded_query.h b/scan_urlencoded_query.h index 379bc32..03ed730 100644 --- a/scan_urlencoded_query.h +++ b/scan_urlencoded_query.h | |||
@@ -1,4 +1,4 @@ | |||
1 | #ifdef __SCAN_URLENCODED_QUERY_H__ | 1 | #ifndef __SCAN_URLENCODED_QUERY_H__ |
2 | #define __SCAN_URLENCODED_QUERY_H__ | 2 | #define __SCAN_URLENCODED_QUERY_H__ |
3 | 3 | ||
4 | #define BREAK_AT_QUESTIONMARK (1<<0) | 4 | #define BREAK_AT_QUESTIONMARK (1<<0) |