Diffstat (limited to 'noncore/net/ubrowser/httpfactory.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/ubrowser/httpfactory.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/noncore/net/ubrowser/httpfactory.cpp b/noncore/net/ubrowser/httpfactory.cpp new file mode 100644 index 0000000..92718fb --- a/dev/null +++ b/noncore/net/ubrowser/httpfactory.cpp @@ -0,0 +1,104 @@ +/* +Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing +Copyright (C) 2002 Thomas Stephens + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public +License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the +implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "httpfactory.h" + +HttpFactory::HttpFactory(QTextBrowser *newBrowser):QMimeSourceFactory() +{ + socket = new QSocket; + text = new QTextDrag; + browser=newBrowser; + comm = new HttpComm(socket, browser); +} + +const QMimeSource * HttpFactory::data(const QString &abs_name) const +{ + printf("HttpFactory::data: using absolute data func\n"); + + int port=80, addrEnd, portSep; + QString host, file, portS, name, tempString; + bool done=false; + + comm->setUp((QString *)&abs_name); + + name = abs_name; +// name = name.lower(); + name = name.stripWhiteSpace(); + + printf("%s\n", name.latin1()); + + if(name.startsWith("http://")) + { + name = name.remove(0, 7); + } + else + { + return 0; + } + + addrEnd = name.find('/'); + if(addrEnd == -1) + { + name += '/'; + addrEnd = name.length()-1; + } + + host = name; + file = name; + + host.truncate(addrEnd); + file.remove(0, addrEnd); + + portSep = host.find(':'); + if(portSep != -1) + { + portS=host; + host.truncate(portSep); + portS.remove(0, portSep+1); + port = portS.toInt(); + } + + printf("%s %s %d\n", host.latin1(), file.latin1(), port); + + if(port == 80) + { + portS="80"; + } + + comm->setStuff(host, portS, file, text); + + socket->connectToHost(host, port); + + text->setText(""); + + return text; +} + +const QMimeSource * HttpFactory::data(const QString &abs_or_rel_name, const QString & context) const +{ + printf("HttpFactory::data: using relative data func\n"); + + if(abs_or_rel_name.startsWith(context)) + { + return data(abs_or_rel_name); + } + else + { + return data(context + abs_or_rel_name); + } + + return 0; +} |