summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
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
@@ -36,18 +36,20 @@ HttpComm::HttpComm(QSocket *newSocket, QTextBrowser *newBrowser):QObject()
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}
@@ -67,18 +69,21 @@ void HttpComm::connected()
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 {
@@ -129,12 +134,13 @@ void HttpComm::incoming()
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());
@@ -185,26 +191,31 @@ void HttpComm::incoming()
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() );
@@ -224,26 +235,31 @@ void HttpComm::incoming()
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() );
@@ -305,13 +321,22 @@ void HttpComm::processBody()
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
@@ -17,22 +17,24 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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();
@@ -46,12 +48,14 @@ private:
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
@@ -19,21 +19,22 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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();
@@ -43,13 +44,14 @@ const QMimeSource * HttpFactory::data(const QString &abs_name) const
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 += '/';
@@ -74,20 +76,31 @@ const QMimeSource * HttpFactory::data(const QString &abs_name) const
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
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
@@ -31,8 +31,9 @@ public:
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};