summaryrefslogtreecommitdiff
path: root/noncore
authorspiralman <spiralman>2003-03-15 16:19:51 (UTC)
committer spiralman <spiralman>2003-03-15 16:19:51 (UTC)
commitd421f8708983df4bab1f9069e87cda94e1d4aeea (patch) (unidiff)
tree3aa7587f72705f73e65a5dc1aa3e824311fba2d1 /noncore
parent69823b154b29cd62c9d53f7ebdaae4cb7dd61939 (diff)
downloadopie-d421f8708983df4bab1f9069e87cda94e1d4aeea.zip
opie-d421f8708983df4bab1f9069e87cda94e1d4aeea.tar.gz
opie-d421f8708983df4bab1f9069e87cda94e1d4aeea.tar.bz2
HttpFactory::data() now returns 0 if there is a 404 error (previously, if there was a 404 error on an image, the browser would get stuck in an infinite loop).
also, fixed html detection
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/ubrowser/httpfactory.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/noncore/net/ubrowser/httpfactory.cpp b/noncore/net/ubrowser/httpfactory.cpp
index 4ace4cb..b37e9f9 100644
--- a/noncore/net/ubrowser/httpfactory.cpp
+++ b/noncore/net/ubrowser/httpfactory.cpp
@@ -178,116 +178,122 @@ const QMimeSource * HttpFactory::data(const QString &abs_or_rel_name, const QStr
178 } 178 }
179 179
180 return 0; 180 return 0;
181} 181}
182 182
183const QByteArray HttpFactory::processResponse( int sockfd, bool &isText ) const 183const QByteArray HttpFactory::processResponse( int sockfd, bool &isText ) const
184{ 184{
185 QByteArray inputBin( 1 ); 185 QByteArray inputBin( 1 );
186 QByteArray conClosedErr( 27 ); 186 QByteArray conClosedErr( 27 );
187 char conClosedErrMsg[] = "Connection to server closed"; 187 char conClosedErrMsg[] = "Connection to server closed";
188 QString currentLine; 188 QString currentLine;
189 bool done=false, chunked=false; 189 bool done=false, chunked=false;
190 int dataLength = 0; 190 int dataLength = 0;
191 191
192 for( int i = 0; i < 27; i++) 192 for( int i = 0; i < 27; i++)
193 { 193 {
194 conClosedErr[i] = conClosedErrMsg[i]; 194 conClosedErr[i] = conClosedErrMsg[i];
195 } 195 }
196 196
197 while( !done ) 197 while( !done )
198 { 198 {
199 recv( sockfd, inputBin.data(), inputBin.size(), 0 ); 199 recv( sockfd, inputBin.data(), inputBin.size(), 0 );
200 currentLine += *(inputBin.data()); 200 currentLine += *(inputBin.data());
201 201
202 if( *(inputBin.data()) == '\n' ) 202 if( *(inputBin.data()) == '\n' )
203 { 203 {
204 if( currentLine.isEmpty() || currentLine.startsWith( "\r") ) 204 if( currentLine.isEmpty() || currentLine.startsWith( "\r") )
205 { 205 {
206 printf( "HttpFactory::processResponse: end of header\n" ); 206 printf( "HttpFactory::processResponse: end of header\n" );
207 if( chunked ) 207 if( chunked )
208 { 208 {
209 return recieveChunked( sockfd ); 209 return recieveChunked( sockfd );
210 } else { 210 } else {
211 return recieveNormal( sockfd, dataLength ); 211 return recieveNormal( sockfd, dataLength );
212 } 212 }
213 done = true; 213 done = true;
214 } 214 }
215 215
216 if( currentLine.contains( "Transfer-Encoding: chunked", false) >= 1 ) 216 if( currentLine.contains( "Transfer-Encoding: chunked", false) >= 1 )
217 { 217 {
218 chunked = true; 218 chunked = true;
219 printf( "HttpFactory::processResponse: chunked encoding\n" ); 219 printf( "HttpFactory::processResponse: chunked encoding\n" );
220 } 220 }
221 221
222 if( currentLine.contains( "Content-Type: text", false ) >= 1 ) 222 if( currentLine.contains( "Content-Type: text", false ) >= 1 )
223 { 223 {
224 isText = true; 224 isText = true;
225 printf( "HttpFactory::processResponse: content type text\n" ); 225 printf( "HttpFactory::processResponse: content type text\n" );
226 if( currentLine.contains( "html", false ) ) 226 if( currentLine.contains( "html", false ) >= 1)
227 { 227 {
228 browser->setTextFormat(Qt::RichText); 228 browser->setTextFormat(Qt::RichText);
229 printf( "HttpFactory::processResponse: content type html\n" ); 229 printf( "HttpFactory::processResponse: content type html\n" );
230 } 230 }
231 } 231 }
232 232
233 if( currentLine.contains( "Content-Type: image", false ) >= 1 ) 233 if( currentLine.contains( "Content-Type: image", false ) >= 1 )
234 { 234 {
235 isText = false; 235 isText = false;
236 printf( "HttpFactory::processResponse: content type image\n" ); 236 printf( "HttpFactory::processResponse: content type image\n" );
237 } 237 }
238 238
239 if( currentLine.contains( "Content-Length", false ) >= 1 ) 239 if( currentLine.contains( "Content-Length", false ) >= 1 )
240 { 240 {
241 currentLine.remove( 0, 16 ); 241 currentLine.remove( 0, 16 );
242 dataLength = currentLine.toInt(); 242 dataLength = currentLine.toInt();
243 printf( "HttpFactory::processResponse: content length: %d\n", dataLength ); 243 printf( "HttpFactory::processResponse: content length: %d\n", dataLength );
244 } 244 }
245 245
246 if( currentLine.contains( "404", false ) >= 1 )
247 {
248 printf( "HttpFactory::processResponse: 404 error\n" );
249 return 0;
250 }
251
246 currentLine = ""; 252 currentLine = "";
247 printf("HttpFactory::processResponse: reseting currentLine: %s\n", currentLine.latin1() ); 253 printf("HttpFactory::processResponse: reseting currentLine: %s\n", currentLine.latin1() );
248 } 254 }
249 } 255 }
250} 256}
251 257
252const QByteArray HttpFactory::recieveNormal( int sockfd, int dataLen ) const 258const QByteArray HttpFactory::recieveNormal( int sockfd, int dataLen ) const
253{ 259{
254 printf( "HttpFactory::recieveNormal: recieving w/out chunked encoding\n" ); 260 printf( "HttpFactory::recieveNormal: recieving w/out chunked encoding\n" );
255 261
256 QByteArray data( dataLen ); 262 QByteArray data( dataLen );
257 QByteArray temp( dataLen ); 263 QByteArray temp( dataLen );
258 int recieved, i; 264 int recieved, i;
259 265
260 recieved = recv( sockfd, temp.data(), temp.size(), 0 ); 266 recieved = recv( sockfd, temp.data(), temp.size(), 0 );
261 printf( "HttpFactory::recieveNormal: found some data: %s\n", (char *)temp.data() ); 267 printf( "HttpFactory::recieveNormal: found some data: %s\n", (char *)temp.data() );
262 for( i = 0; i < recieved; i++ ) 268 for( i = 0; i < recieved; i++ )
263 { 269 {
264 data[i] = temp[i]; 270 data[i] = temp[i];
265 } 271 }
266 dataLen -= recieved; 272 dataLen -= recieved;
267 while( dataLen > 0 ) 273 while( dataLen > 0 )
268 { 274 {
269 recieved = recv( sockfd, temp.data(), temp.size(), 0 ); 275 recieved = recv( sockfd, temp.data(), temp.size(), 0 );
270 dataLen -= recieved; 276 dataLen -= recieved;
271 // printf( "HttpFactory::recieveNormal: found some more data: %s\n", (char *)temp.data() ); 277 // printf( "HttpFactory::recieveNormal: found some more data: %s\n", (char *)temp.data() );
272 for( int j = 0; j < recieved; j++ ) 278 for( int j = 0; j < recieved; j++ )
273 { 279 {
274 data[i] = temp[j]; 280 data[i] = temp[j];
275 i++; 281 i++;
276 } 282 }
277 temp.fill('\0'); 283 temp.fill('\0');
278 } 284 }
279 285
280 printf( "HttpFactory::recieveNormal: end of data\n" ); 286 printf( "HttpFactory::recieveNormal: end of data\n" );
281 return data; 287 return data;
282} 288}
283 289
284const QByteArray HttpFactory::recieveChunked( int sockfd ) const 290const QByteArray HttpFactory::recieveChunked( int sockfd ) const
285{ 291{
286 printf( "HttpFactory::recieveChunked: recieving data with chunked encoding\n" ); 292 printf( "HttpFactory::recieveChunked: recieving data with chunked encoding\n" );
287 293
288 QByteArray data; 294 QByteArray data;
289 QByteArray temp( 1 ); 295 QByteArray temp( 1 );
290 int recieved, i = 0, cSize = 0; 296 int recieved, i = 0, cSize = 0;
291 QString cSizeS; 297 QString cSizeS;
292 298
293 printf( "HttpFactory::recieveChunked: temp.size(): %d\n", temp.size() ); 299 printf( "HttpFactory::recieveChunked: temp.size(): %d\n", temp.size() );