diff options
author | erdgeist <> | 2006-12-15 23:28:23 +0000 |
---|---|---|
committer | erdgeist <> | 2006-12-15 23:28:23 +0000 |
commit | 82b4df67514f258976152031fce44b9dfe249435 (patch) | |
tree | 24c08fc00c17a53bbb775fc3aed916b0aff1b727 /opentracker.c | |
parent | 9e93e6b6e18971811d706e16bdaa0c2a33829a65 (diff) |
Make code endianess save
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/opentracker.c b/opentracker.c index 1139b9e..b20a4dc 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -114,6 +114,7 @@ void httpresponse(struct http_data* h,int64 s) | |||
114 | ot_torrent *torrent; | 114 | ot_torrent *torrent; |
115 | ot_hash *hash = NULL; | 115 | ot_hash *hash = NULL; |
116 | int numwant, tmp, scanon; | 116 | int numwant, tmp, scanon; |
117 | unsigned short port = htons(6881); | ||
117 | size_t reply_size = 0; | 118 | size_t reply_size = 0; |
118 | 119 | ||
119 | array_cat0(&h->r); | 120 | array_cat0(&h->r); |
@@ -187,8 +188,9 @@ e400: | |||
187 | if( byte_diff(data,8,"announce")) | 188 | if( byte_diff(data,8,"announce")) |
188 | goto e404; | 189 | goto e404; |
189 | 190 | ||
190 | peer.ip = h->ip; | 191 | OT_SETIP( &peer, &h->ip); |
191 | peer.port_flags = 6881 << 16; | 192 | OT_SETPORT( &peer, &port ); |
193 | OT_FLAG( &peer ) = 0; | ||
192 | numwant = 50; | 194 | numwant = 50; |
193 | scanon = 1; | 195 | scanon = 1; |
194 | 196 | ||
@@ -202,12 +204,12 @@ e400: | |||
202 | case 4: | 204 | case 4: |
203 | if(!byte_diff(data,4,"port")) { | 205 | if(!byte_diff(data,4,"port")) { |
204 | size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); | 206 | size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); |
205 | if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) || (tmp > 65536) ) goto e404; | 207 | if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) || ( tmp > 0xffff ) ) goto e404; |
206 | peer.port_flags = ( tmp << 16 ) | ( peer.port_flags & 0xffff ); | 208 | port = htons( tmp ); OT_SETPORT ( &peer, &port ); |
207 | } else if(!byte_diff(data,4,"left")) { | 209 | } else if(!byte_diff(data,4,"left")) { |
208 | size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); | 210 | size_t len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ); |
209 | if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) ) goto e404; | 211 | if( ( len <= 0 ) || scan_fixed_int( data, len, &tmp ) ) goto e404; |
210 | if( !tmp ) peer.port_flags |= PEER_FLAG_SEEDING; | 212 | if( !tmp ) OT_FLAG( &peer ) |= PEER_FLAG_SEEDING; |
211 | } else | 213 | } else |
212 | scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE ); | 214 | scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE ); |
213 | break; | 215 | break; |
@@ -218,10 +220,10 @@ e400: | |||
218 | case -1: | 220 | case -1: |
219 | goto e404; | 221 | goto e404; |
220 | case 7: | 222 | case 7: |
221 | if(!byte_diff(data,7,"stopped")) peer.port_flags |= PEER_FLAG_STOPPED; | 223 | if(!byte_diff(data,7,"stopped")) OT_FLAG( &peer ) |= PEER_FLAG_STOPPED; |
222 | break; | 224 | break; |
223 | case 9: | 225 | case 9: |
224 | if(!byte_diff(data,9,"complete")) peer.port_flags |= PEER_FLAG_COMPLETED; | 226 | if(!byte_diff(data,9,"complete")) OT_FLAG( &peer ) |= PEER_FLAG_COMPLETED; |
225 | default: // Fall through intended | 227 | default: // Fall through intended |
226 | break; | 228 | break; |
227 | } | 229 | } |
@@ -263,7 +265,7 @@ e400: | |||
263 | /* Scanned whole query string */ | 265 | /* Scanned whole query string */ |
264 | if( !hash ) goto e404; | 266 | if( !hash ) goto e404; |
265 | 267 | ||
266 | if( peer.port_flags & PEER_FLAG_STOPPED ) { | 268 | if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { |
267 | remove_peer_from_torrent( hash, &peer ); | 269 | remove_peer_from_torrent( hash, &peer ); |
268 | reply = strdup( "d15:warning message4:Okaye" ); reply_size = 26; | 270 | reply = strdup( "d15:warning message4:Okaye" ); reply_size = 26; |
269 | } else { | 271 | } else { |