summaryrefslogtreecommitdiff
path: root/noncore
authorspiralman <spiralman>2002-08-03 03:25:31 (UTC)
committer spiralman <spiralman>2002-08-03 03:25:31 (UTC)
commit7d4b246bc728b73e9d38e110619222dd89c1fd1c (patch) (unidiff)
tree7e6fbb8bbb106967993fa786a917fccde43970f3 /noncore
parent4005263f7c64a631f4df9aeece83321ba818160d (diff)
downloadopie-7d4b246bc728b73e9d38e110619222dd89c1fd1c.zip
opie-7d4b246bc728b73e9d38e110619222dd89c1fd1c.tar.gz
opie-7d4b246bc728b73e9d38e110619222dd89c1fd1c.tar.bz2
fixed relative links (except from forward and back buttons), added initial image code (not working), changes to chunked encoding (still not working, might be a qsocket issue)
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/ubrowser/httpcomm.cpp43
-rw-r--r--noncore/net/ubrowser/httpcomm.h6
-rw-r--r--noncore/net/ubrowser/httpfactory.cpp25
-rw-r--r--noncore/net/ubrowser/httpfactory.h1
4 files changed, 59 insertions, 16 deletions
diff --git a/noncore/net/ubrowser/httpcomm.cpp b/noncore/net/ubrowser/httpcomm.cpp
index 3c14053..4f189ce 100644
--- a/noncore/net/ubrowser/httpcomm.cpp
+++ b/noncore/net/ubrowser/httpcomm.cpp
@@ -18,85 +18,90 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19HttpComm::HttpComm(QSocket *newSocket, QTextBrowser *newBrowser):QObject() 19HttpComm::HttpComm(QSocket *newSocket, QTextBrowser *newBrowser):QObject()
20{ 20{
21 socket = newSocket; 21 socket = newSocket;
22 22
23 connect(socket, SIGNAL(hostFound()), this, SLOT(hostFound()) ); 23 connect(socket, SIGNAL(hostFound()), this, SLOT(hostFound()) );
24 connect(socket, SIGNAL(connected()), this, SLOT(connected()) ); 24 connect(socket, SIGNAL(connected()), this, SLOT(connected()) );
25 connect(socket, SIGNAL(readyRead()), this, SLOT(incoming()) ); 25 connect(socket, SIGNAL(readyRead()), this, SLOT(incoming()) );
26 connect(socket, SIGNAL(connectionClosed()), this, SLOT(connectionClosed()) ); 26 connect(socket, SIGNAL(connectionClosed()), this, SLOT(connectionClosed()) );
27 27
28 headerRead=false; 28 headerRead=false;
29 length = 0; 29 length = 0;
30 bRead = 0; 30 bRead = 0;
31 chunked=false; 31 chunked=false;
32 lengthset=false; 32 lengthset=false;
33 33
34 browser=newBrowser; 34 browser=newBrowser;
35} 35}
36 36
37void HttpComm::setUp(QString *newName) 37void HttpComm::setUp(QString *newName)
38{ 38{
39 name = newName; 39 name = newName;
40} 40}
41 41
42void HttpComm::setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText) 42void HttpComm::setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText, QImageDrag *newImage, bool newIsImage)
43{ 43{
44 host = newHost; 44 host = newHost;
45 portS = newPortS; 45 portS = newPortS;
46 file = newFile; 46 file = newFile;
47 text = newText; 47 text = newText;
48 isImage = newIsImage;
49 image = newImage;
48} 50}
49 51
50void HttpComm::hostFound() 52void HttpComm::hostFound()
51{ 53{
52 printf("HttpComm::hostFound: host found\n"); 54 printf("HttpComm::hostFound: host found\n");
53} 55}
54 56
55void HttpComm::connected() 57void HttpComm::connected()
56{ 58{
57 QString request("GET " + file + " HTTP/1.1\r\nHost: " + host + ':' + portS + "\r\nConnection: close\r\n\r\n"); 59 QString request("GET " + file + " HTTP/1.1\r\nHost: " + host + ':' + portS + "\r\nConnection: close\r\n\r\n");
58 //QString request("GET " + file + " HTTP/1.0\r\n\r\n"); 60 //QString request("GET " + file + " HTTP/1.0\r\n\r\n");
59 printf("HttpComm::data: bytes written: %d\n", socket->writeBlock(request.latin1(), request.length()) ); 61 printf("HttpComm::data: bytes written: %d\n", socket->writeBlock(request.latin1(), request.length()) );
60 printf("HttpComm::data: request sent:\n%s", request.latin1()); 62 printf("HttpComm::data: request sent:\n%s", request.latin1());
61 63
62 headerRead=false; 64 headerRead=false;
63 bRead=0; 65 bRead=0;
64 length = 0; 66 length = 0;
65 header=""; 67 header="";
66 body=""; 68 body="";
67 chunked=false; 69 chunked=false;
68 lengthset=false; 70 lengthset=false;
69} 71}
70 72
71void HttpComm::incoming() 73void HttpComm::incoming()
72{ 74{
73 int ba=socket->bytesAvailable(), i=0, j=0, semi=0; 75 int ba=socket->size(), i=0, j=0, semi=0;
74 char *tempString = new char [ba]; 76 char *tempString = new char [ba];
77 int br = socket->readBlock(tempString, ba);
78 socket->flush();
75 bool nextChunk=false; 79 bool nextChunk=false;
76 bool done=false; 80 bool done=false;
77 socket->readBlock(tempString, ba);
78 printf("HttpComm::incoming: ba: %d\n", ba); 81 printf("HttpComm::incoming: ba: %d\n", ba);
82 printf("HttpComm::incoming: bytes read from socket: %d\n", br);
83 //printf("HttpComm::incoming: tempString length: %d\n");
79 QString sclength; 84 QString sclength;
80 85
81 if(headerRead == false) 86 if(headerRead == false)
82 { 87 {
83 for(i=0; i<ba; i++) 88 for(i=0; i<ba; i++)
84 { 89 {
85 if(tempString[i] != '\r') 90 if(tempString[i] != '\r')
86 { 91 {
87 if(tempString[i] == '\n' && header[header.length()-1] == '\n') 92 if(tempString[i] == '\n' && header[header.length()-1] == '\n')
88 { 93 {
89 j=i; 94 j=i;
90 headerRead = true; 95 headerRead = true;
91 parseHeader(); 96 parseHeader();
92 goto body; 97 goto body;
93 } 98 }
94 else 99 else
95 { 100 {
96 header+=tempString[i]; 101 header+=tempString[i];
97 } 102 }
98 } 103 }
99 // printf("%d %d\n", ba, i); 104 // printf("%d %d\n", ba, i);
100 } 105 }
101 } 106 }
102 else 107 else
@@ -111,48 +116,49 @@ void HttpComm::incoming()
111 { 116 {
112 for( ; j<ba ; j++) 117 for( ; j<ba ; j++)
113 { 118 {
114 body+=tempString[j]; 119 body+=tempString[j];
115 bRead++; 120 bRead++;
116 // printf("bRead1: %d\n", bRead); 121 // printf("bRead1: %d\n", bRead);
117 } 122 }
118 } 123 }
119 else 124 else
120 { 125 {
121 body += tempString; 126 body += tempString;
122 bRead+=ba; 127 bRead+=ba;
123 // printf("bRead2: %d\n", bRead); 128 // printf("bRead2: %d\n", bRead);
124 } 129 }
125 130
126 if(bRead >= length) 131 if(bRead >= length)
127 { 132 {
128 printf("HttpComm::incoming: finished reading body\n"); 133 printf("HttpComm::incoming: finished reading body\n");
129 processBody(); 134 processBody();
130 socket->close(); 135 socket->close();
131 } 136 }
132 } 137 }
133 else 138 else
134 { 139 {
140 int startclength=0;
135 QString tempQString = tempString; 141 QString tempQString = tempString;
136 //remove the http header, if one exists 142 //remove the http header, if one exists
137 if(j != 0) 143 if(j != 0)
138 { 144 {
139 tempQString.remove(0, j+1); 145 tempQString.remove(0, j+1);
140 printf("HttpComm::incoming: removing http header. Result: \n%s", tempQString.latin1()); 146 printf("HttpComm::incoming: removing http header. Result: \n%s", tempQString.latin1());
141 } 147 }
142 while(!done) 148 while(!done)
143 { 149 {
144 switch(status) 150 switch(status)
145 { 151 {
146 //case 0=need to read chunk length 152 //case 0=need to read chunk length
147 case 0: 153 case 0:
148 j = tempQString.find('\n'); 154 j = tempQString.find('\n');
149 sclength = tempQString; 155 sclength = tempQString;
150 sclength.truncate(j); 156 sclength.truncate(j);
151 clength = sclength.toUInt(0, 16); 157 clength = sclength.toUInt(0, 16);
152 printf("HttpComm::Incoming: chunk length: %d\n", clength); 158 printf("HttpComm::Incoming: chunk length: %d\n", clength);
153 printf("HttpComm::Incoming: chunk length string: %s\n", sclength.latin1()); 159 printf("HttpComm::Incoming: chunk length string: %s\n", sclength.latin1());
154 //end of data 160 //end of data
155 if(clength==0) 161 if(clength==0)
156 { 162 {
157 processBody(); 163 processBody();
158 done=true; 164 done=true;
@@ -167,101 +173,111 @@ void HttpComm::incoming()
167 } 173 }
168 //still more data waiting 174 //still more data waiting
169 else 175 else
170 { 176 {
171 done=false; 177 done=false;
172 //remove the chunk length header 178 //remove the chunk length header
173 tempQString.remove(0,j+1); 179 tempQString.remove(0,j+1);
174 } 180 }
175 bRead=0; 181 bRead=0;
176 // break; 182 // break;
177 //if there is more fall through to: 183 //if there is more fall through to:
178 //chunk length just read, still more in tempQstring 184 //chunk length just read, still more in tempQstring
179 case 1: 185 case 1:
180 //the current data extends beyond the end of the chunk 186 //the current data extends beyond the end of the chunk
181 if(bRead + tempQString.length() > clength) 187 if(bRead + tempQString.length() > clength)
182 { 188 {
183 QString newTQstring = tempQString; 189 QString newTQstring = tempQString;
184 newTQstring.truncate(clength-bRead); 190 newTQstring.truncate(clength-bRead);
185 bRead+=newTQstring.length(); 191 bRead+=newTQstring.length();
186 body+=newTQstring; 192 body+=newTQstring;
187 printf("HttpComm::incoming: start new body piece 1: \n"); 193 printf("HttpComm::incoming: start new body piece 1: \n");
188 printf("%s", newTQstring.latin1() ); 194 printf("%s", newTQstring.latin1() );
189 printf("HttpComm::incoming: end new body piece 1.\n"); 195 printf("HttpComm::incoming: end new body piece 1.\n");
190 status=0; 196 status=0;
191 tempQString = tempQString.remove(0, clength); 197 tempQString = tempQString.remove(0, newTQstring.length());
198 startclength = tempQString.find('\n');
199 printf("HttpComm::incoming: startclength: %d\n", startclength);
200 tempQString = tempQString.remove(0, startclength+1);
192 done=false; 201 done=false;
193 // break; 202 // break;
194 } 203 }
195 //the chunk extends beyond the current data; 204 //the chunk extends beyond the current data;
196 else 205 else
197 { 206 {
198 if(tempQString.length() <= ba) 207 if(tempQString.length() <= ba)
199 { 208 {
209 printf("HttpComm::incoming: not truncating tempQString\n");
200 body+=tempQString; 210 body+=tempQString;
201 bRead+=tempQString.length(); 211 bRead+=tempQString.length();
202 } 212 }
203 else 213 else
204 { 214 {
215 printf("HttpComm::incoming: truncating tempQString\n");
205 tempQString.truncate(ba); 216 tempQString.truncate(ba);
206 body+=tempQString; 217 body+=tempQString;
207 bRead+=tempQString.length(); 218 bRead+=tempQString.length();
208 } 219 }
209 printf("HttpComm::incoming: start new body piece 2: \n"); 220 printf("HttpComm::incoming: start new body piece 2: \n");
210 printf("%s", tempQString.latin1() ); 221 printf("%s", tempQString.latin1() );
211 printf("HttpComm::incoming: end new body piece 2.\n"); 222 printf("HttpComm::incoming: end new body piece 2.\n");
212 done=true; 223 done=true;
213 status=2; 224 status=2;
214 // break; 225 // break;
215 } 226 }
216 break; 227 break;
217 //just got data in, continue reading chunk 228 //just got data in, continue reading chunk
218 case 2: 229 case 2:
219 //the current data extends beyond the end of the chunk 230 //the current data extends beyond the end of the chunk
220 if(bRead + tempQString.length() > clength) 231 if(bRead + tempQString.length() > clength)
221 { 232 {
222 QString newTQstring = tempQString; 233 QString newTQstring = tempQString;
223 newTQstring.truncate(clength-bRead); 234 newTQstring.truncate(clength-bRead);
224 bRead+=newTQstring.length(); 235 bRead+=newTQstring.length();
225 body+=newTQstring; 236 body+=newTQstring;
226 printf("HttpComm::incoming: start new body piece 3: \n"); 237 printf("HttpComm::incoming: start new body piece 3: \n");
227 printf("%s", newTQstring.latin1() ); 238 printf("%s", newTQstring.latin1() );
228 printf("HttpComm::incoming: end new body piece 3.\n"); 239 printf("HttpComm::incoming: end new body piece 3.\n");
229 status=0; 240 status=0;
230 tempQString = tempQString.remove(0, clength); 241 tempQString = tempQString.remove(0, newTQstring.length());
242 startclength = tempQString.find('\n');
243 printf("HttpComm::incoming: startclength, tempQString length: %d %d\n", startclength, tempQString.length());
244 tempQString = tempQString.remove(0, startclength+1);
231 done=false; 245 done=false;
232 // break; 246 // break;
233 } 247 }
234 //the chunk extends beyond the current data; 248 //the chunk extends beyond the current data;
235 else 249 else
236 { 250 {
237 if(tempQString.length() <= ba) 251 if(tempQString.length() <= ba)
238 { 252 {
253 printf("HttpComm::incoming: not truncating tempQString\n");
239 body+=tempQString; 254 body+=tempQString;
240 bRead+=tempQString.length(); 255 bRead+=tempQString.length();
241 } 256 }
242 else 257 else
243 { 258 {
259 printf("HttpComm::incoming: truncating tempQString\n");
244 tempQString.truncate(ba); 260 tempQString.truncate(ba);
245 body+=tempQString; 261 body+=tempQString;
246 bRead+=tempQString.length(); 262 bRead+=tempQString.length();
247 } 263 }
248 printf("HttpComm::incoming: start new body piece 4: \n"); 264 printf("HttpComm::incoming: start new body piece 4: \n");
249 printf("%s", tempQString.latin1() ); 265 printf("%s", tempQString.latin1() );
250 printf("HttpComm::incoming: end new body piece 4.\n"); 266 printf("HttpComm::incoming: end new body piece 4.\n");
251 done=true; 267 done=true;
252 status=2; 268 status=2;
253 // break; 269 // break;
254 } 270 }
255 break; 271 break;
256 } 272 }
257 printf("HttpComm::incoming: chunked encoding: bRead: %d\n", bRead); 273 printf("HttpComm::incoming: chunked encoding: bRead: %d\n", bRead);
258 } 274 }
259 } 275 }
260 } 276 }
261 delete tempString; 277 delete tempString;
262} 278}
263 279
264void HttpComm::connectionClosed() 280void HttpComm::connectionClosed()
265{ 281{
266 printf("HttpComm::connectionClosed: connection closed\n"); 282 printf("HttpComm::connectionClosed: connection closed\n");
267 processBody(); 283 processBody();
@@ -287,31 +303,40 @@ void HttpComm::parseHeader()
287 length = tempList[1].toUInt(); 303 length = tempList[1].toUInt();
288 } 304 }
289 else if(headerLines[i].startsWith("Transfer-Encoding: chunked") ) 305 else if(headerLines[i].startsWith("Transfer-Encoding: chunked") )
290 { 306 {
291 printf("HttpComm::parseHeader: using chunked encoding\n"); 307 printf("HttpComm::parseHeader: using chunked encoding\n");
292 chunked = true; 308 chunked = true;
293 status=0; 309 status=0;
294 } 310 }
295 } 311 }
296 312
297 printf("HttpConn::parseHeader: content-length: %d\n", length); 313 printf("HttpConn::parseHeader: content-length: %d\n", length);
298} 314}
299 315
300void HttpComm::processBody() 316void HttpComm::processBody()
301{ 317{
302 printf("HttpComm::processBody: processing body\n"); 318 printf("HttpComm::processBody: processing body\n");
303 //printf("HttpComm::processBody: start body\n\n"); 319 //printf("HttpComm::processBody: start body\n\n");
304 //printf("%s", body.latin1()); 320 //printf("%s", body.latin1());
305 //printf("HttpComm::processBody: end body\n"); 321 //printf("HttpComm::processBody: end body\n");
306 322
307 int lastSlash = file.findRev('/'); 323 int lastSlash = file.findRev('/');
308 324
309 QString end = file; 325 QString end = file;
310 end.truncate(lastSlash+1); 326 end.truncate(lastSlash+1);
311 QString context("http://"+host+':'+portS+end); 327 QString context = "http://"+host+':'+portS+end;
312 printf("HttpComm::processBody: context: %s\n", context.latin1() ); 328 printf("HttpComm::processBody: context: %s\n", context.latin1() );
313 329
314 browser->setTextFormat(RichText); 330 if(!isImage)
315 browser->mimeSourceFactory()->setFilePath(context); 331 {
316 browser->setText(body, context); 332 browser->setTextFormat(RichText);
333 browser->mimeSourceFactory()->setFilePath(context);
334 browser->setText(body, context);
335 }
336 else
337 {
338 QImage tempImage(body.latin1());
339 image->setImage(tempImage);
340 browser->update();
341 }
317} 342}
diff --git a/noncore/net/ubrowser/httpcomm.h b/noncore/net/ubrowser/httpcomm.h
index c20fe72..d6f63fc 100644
--- a/noncore/net/ubrowser/httpcomm.h
+++ b/noncore/net/ubrowser/httpcomm.h
@@ -1,57 +1,61 @@
1/* 1/*
2Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing 2Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include <qobject.h> 17#include <qobject.h>
18#include <qstring.h> 18#include <qstring.h>
19#include <qsocket.h> 19#include <qsocket.h>
20#include <qstringlist.h> 20#include <qstringlist.h>
21#include <qdragobject.h> 21#include <qdragobject.h>
22#include <qtextbrowser.h> 22#include <qtextbrowser.h>
23#include <qcstring.h>
24#include <qimage.h>
23 25
24#include <stdio.h> 26#include <stdio.h>
25 27
26class HttpComm : public QObject 28class HttpComm : public QObject
27{ 29{
28Q_OBJECT 30Q_OBJECT
29public: 31public:
30 HttpComm(QSocket *newSocket, QTextBrowser *newBrowser); 32 HttpComm(QSocket *newSocket, QTextBrowser *newBrowser);
31 void setUp(QString *newName); 33 void setUp(QString *newName);
32 void setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText); 34 void setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText, QImageDrag *newImage, bool newIsImage);
33 void parseHeader(); 35 void parseHeader();
34 void processBody(); 36 void processBody();
35public slots: 37public slots:
36 void hostFound(); 38 void hostFound();
37 void connected(); 39 void connected();
38 void connectionClosed(); 40 void connectionClosed();
39 void incoming(); 41 void incoming();
40private: 42private:
41 QString *name; 43 QString *name;
42 QSocket *socket; 44 QSocket *socket;
43 QString host; 45 QString host;
44 QString portS; 46 QString portS;
45 QString file; 47 QString file;
46 bool headerRead; 48 bool headerRead;
47 QString header; 49 QString header;
48 QString body; 50 QString body;
49 unsigned int length; 51 unsigned int length;
50 unsigned int bRead; 52 unsigned int bRead;
51 QTextDrag *text; 53 QTextDrag *text;
54 QImageDrag *image;
52 QTextBrowser *browser; 55 QTextBrowser *browser;
53 bool chunked; 56 bool chunked;
54 bool lengthset; 57 bool lengthset;
55 unsigned int clength; 58 unsigned int clength;
56 int status; 59 int status;
60 bool isImage;
57}; 61};
diff --git a/noncore/net/ubrowser/httpfactory.cpp b/noncore/net/ubrowser/httpfactory.cpp
index 92718fb..50a3c9a 100644
--- a/noncore/net/ubrowser/httpfactory.cpp
+++ b/noncore/net/ubrowser/httpfactory.cpp
@@ -1,104 +1,117 @@
1/* 1/*
2Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing 2Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include "httpfactory.h" 17#include "httpfactory.h"
18 18
19HttpFactory::HttpFactory(QTextBrowser *newBrowser):QMimeSourceFactory() 19HttpFactory::HttpFactory(QTextBrowser *newBrowser):QMimeSourceFactory()
20{ 20{
21 socket = new QSocket; 21 socket = new QSocket;
22 text = new QTextDrag; 22 text = new QTextDrag;
23 browser=newBrowser; 23 browser=newBrowser;
24 comm = new HttpComm(socket, browser); 24 comm = new HttpComm(socket, browser);
25 image = new QImageDrag;
25} 26}
26 27
27const QMimeSource * HttpFactory::data(const QString &abs_name) const 28const QMimeSource * HttpFactory::data(const QString &abs_name) const
28{ 29{
29 printf("HttpFactory::data: using absolute data func\n"); 30 printf("HttpFactory::data: using absolute data func\n");
30 31
31 int port=80, addrEnd, portSep; 32 int port=80, addrEnd, portSep;
32 QString host, file, portS, name, tempString; 33 QString host, file, portS, name, tempString;
33 bool done=false; 34 bool done=false, isImage=false;
34 35
35 comm->setUp((QString *)&abs_name); 36 comm->setUp((QString *)&abs_name);
36 37
37 name = abs_name; 38 name = abs_name;
38 //name = name.lower(); 39 //name = name.lower();
39 name = name.stripWhiteSpace(); 40 name = name.stripWhiteSpace();
40 41
41 printf("%s\n", name.latin1()); 42 printf("%s\n", name.latin1());
42 43
43 if(name.startsWith("http://")) 44 if(name.startsWith("http://"))
44 { 45 {
45 name = name.remove(0, 7); 46 name = name.remove(0, 7);
46 } 47 }
47 else 48 else
48 { 49 {
49 return 0; 50 name.prepend(browser->context());
51 name = name.remove(0, 7);
50 } 52 }
51 53
52 addrEnd = name.find('/'); 54 addrEnd = name.find('/');
53 if(addrEnd == -1) 55 if(addrEnd == -1)
54 { 56 {
55 name += '/'; 57 name += '/';
56 addrEnd = name.length()-1; 58 addrEnd = name.length()-1;
57 } 59 }
58 60
59 host = name; 61 host = name;
60 file = name; 62 file = name;
61 63
62 host.truncate(addrEnd); 64 host.truncate(addrEnd);
63 file.remove(0, addrEnd); 65 file.remove(0, addrEnd);
64 66
65 portSep = host.find(':'); 67 portSep = host.find(':');
66 if(portSep != -1) 68 if(portSep != -1)
67 { 69 {
68 portS=host; 70 portS=host;
69 host.truncate(portSep); 71 host.truncate(portSep);
70 portS.remove(0, portSep+1); 72 portS.remove(0, portSep+1);
71 port = portS.toInt(); 73 port = portS.toInt();
72 } 74 }
73 75
74 printf("%s %s %d\n", host.latin1(), file.latin1(), port); 76 printf("%s %s %d\n", host.latin1(), file.latin1(), port);
75 77
76 if(port == 80) 78 if(port == 80)
77 { 79 {
78 portS="80"; 80 portS="80";
79 } 81 }
82
83 if(file.find(".png", file.length()-4) != -1 || file.find(".gif", file.length()-4) != -1 || file.find(".jpg", file.length()-4) != -1)
84 {
85 isImage=true;
86 }
80 87
81 comm->setStuff(host, portS, file, text); 88 comm->setStuff(host, portS, file, text, image, isImage);
82 89
83 socket->connectToHost(host, port); 90 socket->connectToHost(host, port);
84 91
85 text->setText(""); 92 if(!image)
86 93 {
87 return text; 94 text->setText("");
95 return text;
96 }
97 else
98 {
99 return image;
100 }
88} 101}
89 102
90const QMimeSource * HttpFactory::data(const QString &abs_or_rel_name, const QString & context) const 103const QMimeSource * HttpFactory::data(const QString &abs_or_rel_name, const QString & context) const
91{ 104{
92 printf("HttpFactory::data: using relative data func\n"); 105 printf("HttpFactory::data: using relative data func\n");
93 106
94 if(abs_or_rel_name.startsWith(context)) 107 if(abs_or_rel_name.startsWith(context))
95 { 108 {
96 return data(abs_or_rel_name); 109 return data(abs_or_rel_name);
97 } 110 }
98 else 111 else
99 { 112 {
100 return data(context + abs_or_rel_name); 113 return data(context + abs_or_rel_name);
101 } 114 }
102 115
103 return 0; 116 return 0;
104} 117}
diff --git a/noncore/net/ubrowser/httpfactory.h b/noncore/net/ubrowser/httpfactory.h
index bb7615b..1802f56 100644
--- a/noncore/net/ubrowser/httpfactory.h
+++ b/noncore/net/ubrowser/httpfactory.h
@@ -13,26 +13,27 @@ Public License for more details.
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17#include <qmime.h> 17#include <qmime.h>
18#include <qsocket.h> 18#include <qsocket.h>
19#include <qstring.h> 19#include <qstring.h>
20#include <qdragobject.h> 20#include <qdragobject.h>
21#include <qtextbrowser.h> 21#include <qtextbrowser.h>
22 22
23#include <stdio.h> 23#include <stdio.h>
24 24
25#include "httpcomm.h" 25#include "httpcomm.h"
26 26
27class HttpFactory : public QMimeSourceFactory 27class HttpFactory : public QMimeSourceFactory
28{ 28{
29public: 29public:
30 HttpFactory(QTextBrowser *newBrowser); 30 HttpFactory(QTextBrowser *newBrowser);
31 const QMimeSource * data(const QString &abs_name) const; 31 const QMimeSource * data(const QString &abs_name) const;
32 const QMimeSource * data(const QString &abs_or_rel_name, const QString & context) const; 32 const QMimeSource * data(const QString &abs_or_rel_name, const QString & context) const;
33private: 33private:
34 QSocket *socket; 34 QSocket *socket;
35 HttpComm *comm; 35 HttpComm *comm;
36 QTextDrag *text; 36 QTextDrag *text;
37 QImageDrag *image;
37 QTextBrowser *browser; 38 QTextBrowser *browser;
38}; 39};