summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2006-12-08 21:00:56 +0000
committererdgeist <>2006-12-08 21:00:56 +0000
commit419e65cc2a7a4740670a54cc02549f112f081285 (patch)
treea292ad46fb98a4a5b3b8b6a4da1dbc0c0fb4b9c3
parentb9743bf516a8d52b3f4e440c2e7c3510c0e3f3cc (diff)
Further compact code
-rw-r--r--opentracker.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/opentracker.c b/opentracker.c
index 65ea024..8313d90 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -104,6 +104,9 @@ const char* http_header(struct http_data* r,const char* h)
104void httpresponse(struct http_data* h,int64 s) 104void httpresponse(struct http_data* h,int64 s)
105{ 105{
106 char *c, *d, *data; 106 char *c, *d, *data;
107 struct ot_peer peer;
108 ot_hash *hash = NULL;
109
107 array_cat0(&h->r); 110 array_cat0(&h->r);
108 111
109 c = array_start(&h->r); 112 c = array_start(&h->r);
@@ -124,8 +127,7 @@ e400:
124 if (c[0]!='/') goto e404; 127 if (c[0]!='/') goto e404;
125 while (c[1]=='/') ++c; 128 while (c[1]=='/') ++c;
126 129
127 data = c; 130 switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) {
128 switch( scan_urlencoded_query( &c, data, SCAN_PATH ) ) {
129 case 0: 131 case 0:
130e404: 132e404:
131 httperror(h,"404 Not Found","No such file or directory."); 133 httperror(h,"404 Not Found","No such file or directory.");
@@ -134,49 +136,42 @@ e404:
134 if (!byte_diff(c,6,"scrape")) 136 if (!byte_diff(c,6,"scrape"))
135 goto e404; 137 goto e404;
136 break; 138 break;
137 case 9: 139 case 8:
138 if( !byte_diff(c,8,"announce")) 140 if( !byte_diff(c,8,"announce"))
139 goto e404; 141 goto e404;
140 else { 142
141 // info_hash, left, port, numwant, compact 143 byte_copy( peer.ip, 4, h->ip );
142 struct ot_peer peer; 144 peer.port = 6881;
143 ot_hash *hash = NULL; 145
144 byte_copy( peer.ip, 4, h->ip ); 146 while( 1 ) {
145 peer.port = 6881; 147 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
146 148 case -1: /* error */
147 while( 1 ) { 149 goto e404;
148 data = c; 150 case 4:
149 switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) { 151 if(!byte_diff(c,4,"port"))
150 case -1: /* error */ 152 /* scan int */ c;
151 goto e404; 153 else if(!byte_diff(c,4,"left"))
152 case 4: 154 /* scan int */ c;
153 if(!byte_diff(c,4,"port")) 155 break;
154 /* scan int */ c; 156 case 7:
155 else if(!byte_diff(c,4,"left")) 157 if(!byte_diff(c,7,"numwant"))
156 /* scan int */ c; 158 /* scan int */ c;
157 break; 159 else if(!byte_diff(c,7,"compact"))
158 case 7: 160 /* scan flag */ c;
159 if(!byte_diff(c,7,"numwant")) 161 break;
160 /* scan int */ c; 162 case 9: /* info_hash= */
161 else if(!byte_diff(c,7,"compact")) 163 if(!byte_diff(c,9,"info_hash")) {
162 /* scan flag */ c; 164 /* ignore this, when we have less than 20 bytes */
163 break; 165 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) )
164 case 9: /* info_hash= */ 166 case -1:
165 if(!byte_diff(c,9,"info_hash")) { 167 httperror(h,"404 Not Found","No such file or directory.");
166 data = c; 168 goto bailout;
167 /* ignore this, when we have less than 20 bytes */ 169 case 20:
168 switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_VALUE ) ) 170 hash = (ot_hash*)data; /* Fall through intended */
169 case -1: 171 default:
170 httperror(h,"404 Not Found","No such file or directory."); 172 continue;
171 goto bailout;
172 case 20:
173 hash = (ot_hash*)data;
174 break;
175 default:
176 continue;
177 }
178 break;
179 } 173 }
174 break;
180 } 175 }
181 } 176 }
182 break; 177 break;