summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opentracker.c77
1 files changed, 36 insertions, 41 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 {
141 // info_hash, left, port, numwant, compact
142 struct ot_peer peer;
143 ot_hash *hash = NULL;
144 byte_copy( peer.ip, 4, h->ip );
145 peer.port = 6881;
146 142
147 while( 1 ) { 143 byte_copy( peer.ip, 4, h->ip );
148 data = c; 144 peer.port = 6881;
149 switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_PARAM ) ) { 145
150 case -1: /* error */ 146 while( 1 ) {
151 goto e404; 147 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
152 case 4: 148 case -1: /* error */
153 if(!byte_diff(c,4,"port")) 149 goto e404;
154 /* scan int */ c; 150 case 4:
155 else if(!byte_diff(c,4,"left")) 151 if(!byte_diff(c,4,"port"))
156 /* scan int */ c; 152 /* scan int */ c;
157 break; 153 else if(!byte_diff(c,4,"left"))
158 case 7: 154 /* scan int */ c;
159 if(!byte_diff(c,7,"numwant")) 155 break;
160 /* scan int */ c; 156 case 7:
161 else if(!byte_diff(c,7,"compact")) 157 if(!byte_diff(c,7,"numwant"))
162 /* scan flag */ c; 158 /* scan int */ c;
163 break; 159 else if(!byte_diff(c,7,"compact"))
164 case 9: /* info_hash= */ 160 /* scan flag */ c;
165 if(!byte_diff(c,9,"info_hash")) { 161 break;
166 data = c; 162 case 9: /* info_hash= */
167 /* ignore this, when we have less than 20 bytes */ 163 if(!byte_diff(c,9,"info_hash")) {
168 switch( scan_urlencoded_query( &c, data, SCAN_SEARCHPATH_VALUE ) ) 164 /* ignore this, when we have less than 20 bytes */
169 case -1: 165 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) )
170 httperror(h,"404 Not Found","No such file or directory."); 166 case -1:
171 goto bailout; 167 httperror(h,"404 Not Found","No such file or directory.");
172 case 20: 168 goto bailout;
173 hash = (ot_hash*)data; 169 case 20:
174 break; 170 hash = (ot_hash*)data; /* Fall through intended */
175 default: 171 default:
176 continue; 172 continue;
177 }
178 break;
179 } 173 }
174 break;
180 } 175 }
181 } 176 }
182 break; 177 break;