summaryrefslogtreecommitdiffstats
path: root/lanbrowsing/kio_lan
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /lanbrowsing/kio_lan
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lanbrowsing/kio_lan')
-rw-r--r--lanbrowsing/kio_lan/AUTHORS2
-rw-r--r--lanbrowsing/kio_lan/Makefile.am31
-rw-r--r--lanbrowsing/kio_lan/README16
-rw-r--r--lanbrowsing/kio_lan/TODO3
-rw-r--r--lanbrowsing/kio_lan/kio_lan.cpp794
-rw-r--r--lanbrowsing/kio_lan/kio_lan.h87
-rw-r--r--lanbrowsing/kio_lan/lan.desktop81
-rw-r--r--lanbrowsing/kio_lan/lan.protocol15
-rw-r--r--lanbrowsing/kio_lan/lisa.desktop66
-rw-r--r--lanbrowsing/kio_lan/rlan.protocol15
10 files changed, 1110 insertions, 0 deletions
diff --git a/lanbrowsing/kio_lan/AUTHORS b/lanbrowsing/kio_lan/AUTHORS
new file mode 100644
index 00000000..062f9d6c
--- /dev/null
+++ b/lanbrowsing/kio_lan/AUTHORS
@@ -0,0 +1,2 @@
+Written and maintained by:
+Alexander Neundorf, neundorf@kde.org
diff --git a/lanbrowsing/kio_lan/Makefile.am b/lanbrowsing/kio_lan/Makefile.am
new file mode 100644
index 00000000..e0f76e4b
--- /dev/null
+++ b/lanbrowsing/kio_lan/Makefile.am
@@ -0,0 +1,31 @@
+## Makefile.am of kdebase/kioslave/man
+
+INCLUDES= $(all_includes)
+
+####### Files
+
+kde_module_LTLIBRARIES = kio_lan.la
+
+kio_lan_la_SOURCES = kio_lan.cpp
+kio_lan_la_LIBADD = $(LIB_KIO)
+kio_lan_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries) $(KDE_RPATH)
+
+noinst_HEADERS = kio_lan.h
+
+kdelnk_DATA = lan.protocol rlan.protocol
+kdelnkdir = $(kde_servicesdir)
+
+remote_DATA = lan.desktop
+remotedir = $(kde_datadir)/konqueror/dirtree/remote
+
+remoteio_DATA = lan.desktop
+remoteiodir = $(kde_datadir)/remoteview
+
+konq_sidebartree_DATA = lisa.desktop
+konq_sidebartreedir = $(kde_datadir)/konqsidebartng/virtual_folders/services
+
+METASOURCES = AUTO
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kio_lan.pot
+
diff --git a/lanbrowsing/kio_lan/README b/lanbrowsing/kio_lan/README
new file mode 100644
index 00000000..0a49f83c
--- /dev/null
+++ b/lanbrowsing/kio_lan/README
@@ -0,0 +1,16 @@
+This is a brandnew ioslave for my brandnew LISa daemon/server.
+It provides something like a network neighbourhood
+only relying on the TCP/IP protocol stack for KDE. Enter lan:/ to see it.
+Read the README for lisa/reslisa.
+LISa/resLISa is in the subdir lisa/.
+Maybe you have to adjust the Makefile a little bit, it currently doesn't
+use the automake/configure stuff.
+On some systems (e.g. Solaris) you will have to add some libraries, like
+-lnsl, I think.
+
+Copy this directory e.g. under kdebase/kioslave and enter it in
+kdebase/kioslave/Makefile.am in the SUBDIR line. The rerun make in
+kdebase/kioslave.
+
+Alexander Neundorf
+<neundorf@kde.org>
diff --git a/lanbrowsing/kio_lan/TODO b/lanbrowsing/kio_lan/TODO
new file mode 100644
index 00000000..8640402e
--- /dev/null
+++ b/lanbrowsing/kio_lan/TODO
@@ -0,0 +1,3 @@
+mainly testing, I think
+
+Alex
diff --git a/lanbrowsing/kio_lan/kio_lan.cpp b/lanbrowsing/kio_lan/kio_lan.cpp
new file mode 100644
index 00000000..06368b8d
--- /dev/null
+++ b/lanbrowsing/kio_lan/kio_lan.cpp
@@ -0,0 +1,794 @@
+/* This file is part of the KDE project
+ Copyright (C) 2000,2001 Alexander Neundorf <neundorf@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kinstance.h>
+#include <kconfig.h>
+#include <kglobal.h>
+#include <kprocess.h>
+
+#include <qfile.h>
+
+#include <iostream>
+#include <string.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <time.h>
+#include <pwd.h>
+
+#include "kio_lan.h"
+
+#ifndef AF_LOCAL
+#define AF_LOCAL AF_UNIX
+#endif
+
+#define PORTSETTINGS_CHECK 0
+#define PORTSETTINGS_PROVIDE 1
+#define PORTSETTINGS_DISABLE 2
+
+using namespace KIO;
+
+#ifndef SHUT_RDWR
+#define SHUT_RDWR 2
+#endif
+
+extern "C" { KDE_EXPORT int kdemain(int argc, char **argv); }
+
+int kdemain( int argc, char **argv )
+{
+ KInstance instance( "kio_lan" );
+
+ if (argc != 4)
+ {
+ fprintf(stderr, "Usage: kio_lan protocol domain-socket1 domain-socket2\n");
+ exit(-1);
+ }
+ int isLanIoslave=(strcmp("lan",argv[1])==0);
+
+ // Trigger creation to make sure we pick up KIOSK settings correctly.
+ (void)KGlobal::dirs();
+ (void)KGlobal::locale();
+ (void)KGlobal::config();
+
+ kdDebug(7101) << "LAN: kdemain: starting" << endl;
+
+ LANProtocol slave(isLanIoslave, argv[2], argv[3]);
+ slave.dispatchLoop();
+ return 0;
+}
+
+LANProtocol::LANProtocol(int isLanIoslave, const QCString &pool, const QCString &app )
+:TCPSlaveBase(7741,isLanIoslave?"lan":"rlan", pool, app)
+,m_currentHost("")
+,m_port(7741)
+,m_maxAge(15*60)
+,m_isLanIoslave(isLanIoslave?true:false)
+{
+ KConfig *config=KGlobal::config();
+
+ m_protocolInfo[KIOLAN_FTP].enabled=config->readNumEntry("Support_FTP",PORTSETTINGS_CHECK);
+ m_protocolInfo[KIOLAN_HTTP].enabled=config->readNumEntry("Support_HTTP",PORTSETTINGS_CHECK);
+ m_protocolInfo[KIOLAN_NFS].enabled=config->readNumEntry("Support_NFS",PORTSETTINGS_CHECK);
+ m_protocolInfo[KIOLAN_SMB].enabled=config->readNumEntry("Support_SMB",PORTSETTINGS_CHECK);
+ m_protocolInfo[KIOLAN_FISH].enabled=config->readNumEntry("Support_FISH",PORTSETTINGS_CHECK);
+
+ m_defaultLisaHost=config->readEntry("DefaultLisaHost", "localhost");
+ m_shortHostnames=config->readBoolEntry("ShowShortHostnames",false);
+ m_maxAge=config->readNumEntry("MaxAge",15)*60;
+ if (m_maxAge<0) m_maxAge=0;
+
+ strcpy(m_protocolInfo[KIOLAN_NFS].name,"NFS");
+ strcpy(m_protocolInfo[KIOLAN_FTP].name,"FTP");
+ strcpy(m_protocolInfo[KIOLAN_SMB].name,"SMB");
+ strcpy(m_protocolInfo[KIOLAN_HTTP].name,"HTTP");
+ strcpy(m_protocolInfo[KIOLAN_FISH].name,"FISH");
+
+ // Now we check for port 445 for SMB/CIFS also. But we call both entries
+ // SMB. Clients will see only one SMB folder, though, whichever
+ // port (or both) is detected. The smb ioslave should be able
+ // to figure out which port to actually use.
+
+ m_protocolInfo[KIOLAN_NFS].ports.push_back(2049);
+ m_protocolInfo[KIOLAN_FTP].ports.push_back(21);
+ m_protocolInfo[KIOLAN_SMB].ports.push_back(445);
+ m_protocolInfo[KIOLAN_SMB].ports.push_back(139);
+ m_protocolInfo[KIOLAN_HTTP].ports.push_back(80);
+ m_protocolInfo[KIOLAN_FISH].ports.push_back(22);
+
+ m_hostInfoCache.setAutoDelete(true);
+}
+
+LANProtocol::~LANProtocol()
+{
+ m_hostInfoCache.clear();
+}
+
+int LANProtocol::readDataFromServer()
+{
+ if (m_isLanIoslave)
+ return lanReadDataFromServer();
+ else
+ return rlanReadDataFromServer();
+ return 0;
+}
+
+int LANProtocol::lanReadDataFromServer()
+{
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer() host: "<<m_currentHost<<" port: "<<m_port<<endl;
+ if (!connectToHost(m_currentHost.latin1(), m_port, false))
+ {
+ error(ERR_SLAVE_DEFINED, i18n("<qt>The Lisa daemon does not appear to be running.<p>"
+ "In order to use the LAN Browser the Lisa daemon must be "
+ "installed and activated by the system administrator."));
+ return 0;
+ }
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer() connected"<<endl;
+
+ int receivedBytes(0);
+ char* receiveBuffer(0);
+ char tmpBuf[64*1024];
+ int bytesRead(0);
+ do
+ {
+ fd_set tmpFDs;
+ FD_ZERO(&tmpFDs);
+ FD_SET(m_iSock,&tmpFDs);
+ timeval tv;
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ select(m_iSock+1,&tmpFDs,0,0,&tv);
+ if (FD_ISSET(m_iSock,&tmpFDs))
+ {
+ bytesRead=read(tmpBuf,64*1024);
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: read "<<bytesRead<<" bytes"<<endl;
+
+ if (bytesRead>0)
+ {
+ char *newBuf=new char[receivedBytes+bytesRead];
+ if (receiveBuffer!=0) memcpy(newBuf,receiveBuffer,receivedBytes);
+ memcpy(newBuf+receivedBytes,tmpBuf,bytesRead);
+ receivedBytes+=bytesRead;
+ if (receiveBuffer!=0) delete [] receiveBuffer;
+ receiveBuffer=newBuf;
+ }
+ }
+ } while (bytesRead>0);
+ closeDescriptor();
+ if ((bytesRead<0) || (receivedBytes<4))
+ {
+ delete [] receiveBuffer;
+ error(ERR_INTERNAL_SERVER,i18n("Received unexpected data from %1").arg(m_currentHost));
+ return 0;
+ }
+
+ UDSEntry entry;
+
+ char *currentBuf=receiveBuffer;
+ int bytesLeft=receivedBytes;
+ //this should be large enough for a name
+ char tmpName[4*1024];
+ //this should be large enough for the hostname
+ char tmpHostname[4*1024];
+ while (bytesLeft>0)
+ {
+ int tmpIP=2;
+ tmpName[0]='\0';
+ if ((memchr(currentBuf,0,bytesLeft)==0) || (memchr(currentBuf,int('\n'),bytesLeft)==0))
+ {
+ delete [] receiveBuffer;
+ error(ERR_INTERNAL_SERVER,i18n("Received unexpected data from %1").arg(m_currentHost));
+ return 0;
+ }
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: processing "<<currentBuf;
+ //since we check for 0 and \n with memchr() we can be sure
+ //at this point that tmpBuf is correctly terminated
+ int length=strlen(currentBuf)+1;
+ if (length<(4*1024))
+ sscanf(currentBuf,"%u %s\n",&tmpIP,tmpName);
+ else
+ {
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: buffer overflow attempt detected, aborting"<<endl;
+ break;
+ }
+
+ bytesLeft-=length;
+ currentBuf+=length;
+ if ((bytesLeft==0) && ((tmpIP==0) ||(tmpIP==1)) && (strstr(tmpName,"succeeded")!=0))
+ {
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: succeeded"<<endl;
+ }
+ else if (tmpIP!=2)
+ {
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: listing host: "<<tmpName<<" with ip: "<<tmpIP<<endl;
+ UDSAtom atom;
+
+ atom.m_uds = KIO::UDS_NAME;
+ if (m_shortHostnames)
+ {
+ if (inet_addr(tmpName)!=-1)
+ atom.m_str=tmpName;
+ else
+ {
+ sscanf(tmpName,"%[^.]",tmpHostname);
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: Hostname of " << tmpName << " is " << tmpHostname << "\n";
+ atom.m_str = tmpHostname;
+ }
+ }
+ else
+ atom.m_str = tmpName;
+
+ entry.append( atom );
+ atom.m_uds = KIO::UDS_SIZE;
+ atom.m_long = 1024;
+ entry.append(atom);
+ atom.m_uds = KIO::UDS_ACCESS;
+ atom.m_long = S_IRUSR | S_IRGRP | S_IROTH ;
+ //atom.m_long = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ entry.append(atom);
+ atom.m_uds = KIO::UDS_FILE_TYPE;
+ atom.m_long = S_IFDIR; // it is always a directory
+ entry.append( atom );
+ listEntry(entry,false);
+ }
+ }
+
+ listEntry( entry, true ); // ready
+ delete [] receiveBuffer;
+ return 1;
+}
+
+int LANProtocol::rlanReadDataFromServer()
+{
+ kdDebug(7101)<<"RLANProtocol::readDataFromServer"<<endl;
+
+ int sockFD=socket(AF_LOCAL, SOCK_STREAM, 0);
+ sockaddr_un addr;
+ memset((char*)&addr,0,sizeof(addr));
+ addr.sun_family=AF_LOCAL;
+ QCString socketname="/tmp/resLisa-";
+
+ struct passwd *user = getpwuid( getuid() );
+ if ( user )
+ socketname+=user->pw_name;
+ else
+ //should never happen
+ socketname+="???";
+
+ strlcpy(addr.sun_path,socketname,sizeof(addr.sun_path));
+ int result=::connect(sockFD,(sockaddr*)&addr, sizeof(addr));
+
+ kdDebug(7101)<<"readDataFromServer(): result: "<<result<<" name: "<<addr.sun_path<<" socket: "<<sockFD<<endl;
+
+ if (result!=0)
+ {
+ ::close(sockFD);
+ KProcess proc;
+ proc<<"reslisa";
+
+ bool ok=proc.start(KProcess::DontCare);
+ if (!ok)
+ {
+ error( ERR_CANNOT_LAUNCH_PROCESS, "reslisa" );
+ return 0;
+ }
+ //wait a moment
+ //reslisa starts kde-config, then does up to 64
+ //name lookups and then starts to ping
+ //results won't be available before this is done
+ kdDebug(7101)<<"sleeping..."<<endl;
+ ::sleep(1);
+ kdDebug(7101)<<"sleeping again..."<<endl;
+ ::sleep(5);
+ kdDebug(7101)<<"woke up "<<endl;
+ sockFD=socket(AF_LOCAL, SOCK_STREAM, 0);
+
+ memset((char*)&addr,0,sizeof(addr));
+ addr.sun_family=AF_LOCAL;
+ strlcpy(addr.sun_path,socketname,sizeof(addr.sun_path));
+
+ kdDebug(7101)<<"connecting..."<<endl;
+ result=::connect(sockFD,(sockaddr*)&addr, sizeof(addr));
+ kdDebug(7101)<<"readDataFromServer() after starting reslisa: result: "<<result<<" name: "<<addr.sun_path<<" socket: "<<sockFD<<endl;
+ if (result!=0)
+ {
+ error( ERR_CANNOT_OPEN_FOR_READING, socketname );
+ return 0;
+ }
+ kdDebug(7101)<<"succeeded :-)"<<endl;
+ }
+
+ int receivedBytes(0);
+ char* receiveBuffer(0);
+ char tmpBuf[64*1024];
+ int bytesRead(0);
+ do
+ {
+ fd_set tmpFDs;
+ FD_ZERO(&tmpFDs);
+ FD_SET(sockFD,&tmpFDs);
+ timeval tv;
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ select(sockFD+1,&tmpFDs,0,0,&tv);
+ if (FD_ISSET(sockFD,&tmpFDs))
+ {
+ bytesRead=::read(sockFD,tmpBuf,64*1024);
+ kdDebug(7101)<<"RLANProtocol::readDataFromServer: read "<<bytesRead<<" bytes"<<endl;
+
+ if (bytesRead>0)
+ {
+ char *newBuf=new char[receivedBytes+bytesRead];
+ if (receiveBuffer!=0) memcpy(newBuf,receiveBuffer,receivedBytes);
+ memcpy(newBuf+receivedBytes,tmpBuf,bytesRead);
+ receivedBytes+=bytesRead;
+ if (receiveBuffer!=0) delete [] receiveBuffer;
+ receiveBuffer=newBuf;
+ }
+ }
+ } while (bytesRead>0);
+ ::close(sockFD);
+
+
+ if ((bytesRead<0) || (receivedBytes<4))
+ {
+ delete [] receiveBuffer;
+ error(ERR_CANNOT_OPEN_FOR_READING,socketname);
+ return 0;
+ }
+
+ UDSEntry entry;
+
+ char *currentBuf=receiveBuffer;
+ int bytesLeft=receivedBytes;
+ //this should be large enough for a name
+ char tmpName[4*1024];
+ //this should be large enough for the hostname
+ char tmpHostname[4*1024];
+ while (bytesLeft>0)
+ {
+ int tmpIP=2;
+ tmpName[0]='\0';
+ if ((memchr(currentBuf,0,bytesLeft)==0) || (memchr(currentBuf,int('\n'),bytesLeft)==0))
+ {
+ delete [] receiveBuffer;
+ error(ERR_INTERNAL_SERVER,i18n("Received unexpected data from %1").arg(socketname));
+ return 0;
+ }
+ kdDebug(7101)<<"RLANProtocol::readDataFromServer: processing "<<currentBuf;
+ //since we check for 0 and \n with memchr() we can be sure
+ //at this point that tmpBuf is correctly terminated
+ int length=strlen(currentBuf)+1;
+ if (length<(4*1024))
+ sscanf(currentBuf,"%u %s\n",&tmpIP,tmpName);
+ else
+ {
+ kdDebug(7101)<<"RLANProtocol::readDataFromServer: buffer overflow attempt detected, aborting"<<endl;
+ break;
+ }
+
+ bytesLeft-=length;
+ currentBuf+=length;
+ if ((bytesLeft==0) && ((tmpIP==0) ||(tmpIP==1)) && (strstr(tmpName,"succeeded")!=0))
+ {
+ kdDebug(7101)<<"RLANProtocol::readDataFromServer: succeeded"<<endl;
+ }
+ else if (tmpIP!=2)
+ {
+ kdDebug(7101)<<"RLANProtocol::readDataFromServer: listing host: "<<tmpName<<" with ip: "<<tmpIP<<endl;
+ UDSAtom atom;
+
+ atom.m_uds = KIO::UDS_NAME;
+ if (m_shortHostnames)
+ {
+ if (inet_addr(tmpName)!=-1)
+ atom.m_str=tmpName;
+ else
+ {
+ sscanf(tmpName,"%[^.]",tmpHostname);
+ kdDebug(7101)<<"LANProtocol::lanReadDataFromServer: Hostname of " << tmpName << " is " << tmpHostname << "\n";
+ atom.m_str = tmpHostname;
+ }
+ }
+ else
+ atom.m_str = tmpName;
+ entry.append( atom );
+ atom.m_uds = KIO::UDS_SIZE;
+ atom.m_long = 1024;
+ entry.append(atom);
+ atom.m_uds = KIO::UDS_ACCESS;
+ atom.m_long = S_IRUSR | S_IRGRP | S_IROTH ;
+ //atom.m_long = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ entry.append(atom);
+ atom.m_uds = KIO::UDS_FILE_TYPE;
+ atom.m_long = S_IFDIR; // it is always a directory
+ entry.append( atom );
+ listEntry(entry,false);
+ }
+ }
+
+ listEntry( entry, true ); // ready
+ delete [] receiveBuffer;
+ return 1;
+}
+
+int LANProtocol::checkHost(const QString& host)
+{
+ kdDebug(7101)<<"LAN::checkHost() "<<host<<endl;
+
+ QString hostUpper=host.upper();
+ HostInfo* hostInfo=m_hostInfoCache[hostUpper];
+ if (hostInfo!=0)
+ {
+ kdDebug(7101)<<"LAN::checkHost() getting from cache"<<endl;
+ //this entry is too old, we delete it !
+ if ((time(0)-hostInfo->created)>m_maxAge)
+ {
+ kdDebug(7101)<<"LAN::checkHost() cache content too old, deleting it"<<endl;
+ m_hostInfoCache.remove(hostUpper);
+ hostInfo=0;
+ }
+ }
+ if (hostInfo==0)
+ {
+ hostInfo=new HostInfo;
+ in_addr ip;
+
+ struct hostent *hp=gethostbyname(host.latin1());
+ if (hp==0)
+ {
+ error( ERR_UNKNOWN_HOST, host.latin1() );
+ delete hostInfo;
+ return 0;
+ }
+ memcpy(&ip, hp->h_addr, sizeof(ip));
+
+ for (int i=0; i<KIOLAN_MAX; i++)
+ {
+ int result(0);
+ if (m_protocolInfo[i].enabled==PORTSETTINGS_DISABLE)
+ result=0;
+ else if (m_protocolInfo[i].enabled==PORTSETTINGS_PROVIDE)
+ result=1;
+ else if (m_protocolInfo[i].enabled==PORTSETTINGS_CHECK)
+ result=checkPort(m_protocolInfo[i].ports,ip);
+
+ //host not reachable
+ if (result==-1)
+ {
+ delete hostInfo;
+ hostInfo=0;
+ error( ERR_UNKNOWN_HOST, host.latin1() );
+ return 0;
+ }
+ hostInfo->services[i]=result;
+ }
+ hostInfo->created=time(0);
+ m_hostInfoCache.insert(hostUpper,hostInfo);
+ }
+ //here hostInfo is always != 0
+ if (hostInfo==0)
+ {
+ error( ERR_INTERNAL, "hostInfo==0" );
+ return 0;
+ }
+
+ UDSEntry entry;
+ for (int i=0; i<KIOLAN_MAX; i++)
+ {
+ if (hostInfo->services[i]==1)
+ {
+ kdDebug(7101)<<"LAN::checkHost(): Host ["<<hostUpper<<"] Service ["<<m_protocolInfo[i].name<<"]"<<endl;
+ UDSAtom atom;
+ // name
+ atom.m_uds = KIO::UDS_NAME;
+ atom.m_str = m_protocolInfo[i].name;
+ entry.append( atom );
+ // size
+ atom.m_uds = KIO::UDS_SIZE;
+ atom.m_long = 1024;
+ entry.append(atom);
+ // access permissions
+ atom.m_uds = KIO::UDS_ACCESS;
+ atom.m_long = S_IRUSR | S_IRGRP | S_IROTH ;
+ //atom.m_long = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ entry.append(atom);
+ // file type
+ atom.m_uds = KIO::UDS_FILE_TYPE;
+ if (strcmp(m_protocolInfo[i].name,"HTTP")==0)
+ {
+ // normal file -- if we called stat(2) on this,
+ // this flag would be set in the st_mode field of struct stat
+ atom.m_long=S_IFREG;
+ entry.append(atom);
+
+ // also define the mime-type for this file
+ atom.m_uds = KIO::UDS_MIME_TYPE;
+ atom.m_str="text/html";
+ entry.append( atom );
+ }
+ else
+ {
+ // directory -- if we called stat(2) on this, then this
+ // flag would be set in the st_mode field of the struct stat
+ atom.m_long = S_IFDIR; // it is always a directory
+ entry.append(atom);
+
+ // also set the mime-type
+ atom.m_uds = KIO::UDS_MIME_TYPE;
+ atom.m_str="inode/directory";
+ entry.append( atom );
+ }
+ listEntry(entry,false);
+ }
+ }
+ listEntry( entry, true ); // ready
+ return 1;
+}
+
+// Check if a service is running on a host with IP address 'ip'
+// by checking all the ports in '_ports', using a non-blocking connect.
+// Right now -- assume if *any* of these ports are active,
+// the service is active.
+int LANProtocol::checkPort( QValueVector<int>& _ports, in_addr ip )
+{
+ int _port=0;
+ struct sockaddr_in to_scan;
+
+ to_scan.sin_family = AF_INET;
+ to_scan.sin_addr = ip;
+
+ for (QValueVector<int>::iterator i= _ports.begin(); i != _ports.end(); i++)
+ {
+ _port=(*i);
+ kdDebug(7101)<<"LANProtocol::checkPort: "<<_port<<endl;
+ to_scan.sin_port = htons(_port);
+ // open a TCP socket
+ int mysocket = ::socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (mysocket< 0 )
+ {
+ std::cerr << "LanProt::checkPort: Error while opening Socket" << std::endl;
+ ::close( mysocket );
+ return 0;
+ }
+ //make the socket non blocking
+ long int options = O_NONBLOCK | ::fcntl(mysocket, F_GETFL);
+ if (::fcntl( mysocket, F_SETFL, options )!=0)
+ {
+ std::cerr << "LanProt::checkPort: Error making it nonblocking"<< std::endl;
+ ::close( mysocket );
+ return 0;
+ }
+ int result=connect( mysocket, (struct sockaddr *) &to_scan, sizeof( to_scan ));
+ //it succeeded immediately
+ if (result==0)
+ {
+ std::cerr<<"LANProtocol::checkPort("<<_port<<") connect succeeded immediately"<<std::endl;
+ ::shutdown( mysocket, SHUT_RDWR );
+ return 1;
+ }
+ //it failed
+ if ((result<0) && (errno!=EINPROGRESS))
+ {
+ // errno was not EINPROGRESS, so there is some serious problem
+ ::shutdown( mysocket, SHUT_RDWR );
+ // maybe some other port will work
+ continue;
+ }
+ // last errno was EINPROGRESS, so we should select() on socket
+ // and wait for the final verdict
+ timeval tv;
+ tv.tv_sec=5;
+ tv.tv_usec=0;
+ fd_set rSet, wSet;
+ FD_ZERO(&rSet);
+ FD_SET(mysocket,&rSet);
+ wSet=rSet;
+ //timeout or error
+ result=select(mysocket+1,&rSet,&wSet,0,&tv);
+ ::shutdown( mysocket, SHUT_RDWR );
+ if (result==1)
+ return 1;
+ }
+ // gosh, no port worked
+ return 0;
+
+}
+
+void LANProtocol::setHost( const QString& host, int port, const QString& , const QString& )
+{
+ if (m_isLanIoslave)
+ {
+ m_currentHost=host;
+ if (port==0)
+ m_port=7741;
+ else
+ m_port=port;
+ kdDebug(7101)<<"LANProtocol::setHost: "<<m_currentHost<<endl;
+ }
+ else
+ {
+ if (!host.isEmpty())
+ error(ERR_MALFORMED_URL,i18n("No hosts allowed in rlan:/ URL"));
+ }
+}
+
+void LANProtocol::mimetype( const KURL& url)
+{
+ kdDebug(7101)<<"LANProtocol::mimetype -"<<url.prettyURL()<<"-"<<endl;
+ QString path( QFile::encodeName(url.path()));
+ QStringList pathList=QStringList::split( "/",path);
+ if ((pathList.count()==2) && (pathList[1].upper()=="HTTP"))
+ {
+ //kdDebug(7101)<<"LANProtocol::mimeType text/html"<<endl;
+ mimeType("text/html");
+ }
+ else
+ {
+ mimeType("inode/directory");
+ //kdDebug(7101)<<"LANProtocol::mimeType inode/directory"<<endl;
+ }
+ finished();
+}
+
+void LANProtocol::listDir( const KURL& _url)
+{
+ KURL url(_url);
+ QString path( QFile::encodeName(url.path()));
+ if (path.isEmpty())
+ {
+ url.setPath("/");
+ redirection(url);
+ finished();
+ return;
+ }
+ if ((m_currentHost.isEmpty()) && (m_isLanIoslave))
+ {
+ url.setHost(m_defaultLisaHost);
+ redirection(url);
+ finished();
+ return;
+ }
+ kdDebug(7101)<<"LANProtocol::listDir: host: "<<m_currentHost<<" port: "<<m_port<<" path: "<<path<<endl;
+ QStringList pathList=QStringList::split("/", path);
+ kdDebug(7101)<<"parts are: "<<endl;
+ for (QStringList::Iterator it=pathList.begin(); it !=pathList.end(); it++)
+ kdDebug(7101)<<"-"<<(*it)<<"-"<<endl;
+ if (pathList.count()>2)
+ {
+ kdDebug(7101)<<"LANProtocol::listDir: too deep path: "<<pathList.count()<<endl;
+ error(ERR_DOES_NOT_EXIST,_url.prettyURL());
+ return;
+ }
+ int succeeded(0);
+ if (path=="/")
+ {
+ //get the stuff from the netland server
+ succeeded=readDataFromServer();
+ }
+ else if (pathList.count()==1)
+ {
+ //check the ports and stuff
+ succeeded=checkHost(pathList[0]);
+ }
+ else
+ {
+ kdDebug(7101)<<"LANProtocol::listDir: trying to redirect"<<endl;
+ int isSupportedProtocol(0);
+ for (int i=0; i<KIOLAN_MAX; i++)
+ {
+ if (pathList[1].upper()==m_protocolInfo[i].name)
+ {
+ isSupportedProtocol=m_protocolInfo[i].enabled;
+ break;
+ }
+ }
+ if (isSupportedProtocol==PORTSETTINGS_DISABLE)
+ {
+ kdDebug(7101)<<"LANProtocol::listDir: protocol not enabled "<<endl;
+ error(ERR_DOES_NOT_EXIST,_url.prettyURL());
+ return;
+ }
+ //redirect it
+ KURL newUrl(pathList[1]+"://"+pathList[0]);
+ redirection(newUrl);
+ succeeded=1;
+ }
+ if (succeeded) finished();
+}
+
+void LANProtocol::stat( const KURL & url)
+{
+ kdDebug(7101)<<"LANProtocol::stat: "<<endl;
+ UDSEntry entry;
+ UDSAtom atom;
+
+ atom.m_uds = KIO::UDS_NAME;
+ atom.m_str = url.path();
+ entry.append( atom );
+ atom.m_uds = KIO::UDS_SIZE;
+ atom.m_long = 1024;
+ entry.append(atom);
+
+ atom.m_uds = KIO::UDS_ACCESS;
+ atom.m_long = S_IRUSR | S_IRGRP | S_IROTH ;
+ //atom.m_long = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ entry.append(atom);
+
+
+ QString path( QFile::encodeName(url.path()));
+ QStringList pathList=QStringList::split( "/",path);
+ if ((pathList.count()==2) && (pathList[1].upper()=="HTTP"))
+ {
+ atom.m_uds = KIO::UDS_FILE_TYPE;
+ atom.m_long=S_IFREG;
+ entry.append(atom);
+ atom.m_uds = KIO::UDS_MIME_TYPE;
+ atom.m_str="text/html";
+ //kdDebug(7101)<<"LANProtocol::stat: http is reg file"<<endl;
+ entry.append( atom );
+ }
+ else
+ {
+ atom.m_uds = KIO::UDS_FILE_TYPE;
+ atom.m_long = S_IFDIR; // it is always a directory
+ entry.append(atom);
+ atom.m_uds = KIO::UDS_MIME_TYPE;
+ atom.m_str="inode/directory";
+ //kdDebug(7101)<<"LANProtocol::stat: is dir"<<endl;
+ entry.append( atom );
+ }
+
+ statEntry( entry );
+ finished();
+}
+
+void LANProtocol::get(const KURL& url )
+{
+ QString path(QFile::encodeName(url.path()));
+
+ kdDebug(7101)<<"LANProtocol::get: "<<path<<endl;
+ QStringList pathList=QStringList::split("/", path);
+ kdDebug(7101)<<"parts are: "<<endl;
+ for (QStringList::Iterator it=pathList.begin(); it !=pathList.end(); it++)
+ kdDebug(7101)<<"-"<<(*it)<<"-"<<endl;
+ if ((pathList.count()!=2) || (pathList[1].upper()!="HTTP"))
+ {
+ kdDebug(7101)<<"LANProtocol::get: invalid url: "<<pathList.count()<<endl;
+ error(ERR_DOES_NOT_EXIST,url.prettyURL());
+ return;
+ }
+ KURL newUrl("http://"+pathList[0]);
+ redirection(newUrl);
+ finished();
+ return;
+}
diff --git a/lanbrowsing/kio_lan/kio_lan.h b/lanbrowsing/kio_lan/kio_lan.h
new file mode 100644
index 00000000..26bff398
--- /dev/null
+++ b/lanbrowsing/kio_lan/kio_lan.h
@@ -0,0 +1,87 @@
+/* This file is part of the KDE project
+ Copyright (C) 2000 Alexander Neundorf <neundorf@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KIO_XLAN_H
+#define KIO_XLAN_H
+
+#include <kio/slavebase.h>
+#include <kio/tcpslavebase.h>
+#include <kio/global.h>
+
+#include <qvaluevector.h>
+#include <qcstring.h>
+#include <qstring.h>
+#include <qdict.h>
+
+#include <arpa/inet.h>
+#include <sys/types.h>
+
+#define KIOLAN_HTTP 0
+#define KIOLAN_FTP 1
+#define KIOLAN_SMB 2
+#define KIOLAN_NFS 3
+#define KIOLAN_FISH 4
+#define KIOLAN_MAX 5
+
+#define NAMELEN 8
+
+struct MyProtocolInfo
+{
+ int enabled;
+ QValueVector<int> ports;
+ //this should be large enough for things like "FTP" and so on
+ char name[NAMELEN];
+};
+
+struct HostInfo
+{
+ time_t created;
+ int services[KIOLAN_MAX];
+};
+
+class LANProtocol : public KIO::TCPSlaveBase
+{
+ public:
+ LANProtocol (int isLanIoSlave, const QCString &pool, const QCString &app );
+ virtual ~LANProtocol();
+
+ virtual void setHost( const QString& host, int port, const QString& user, const QString& pass );
+ virtual void mimetype( const KURL& );
+
+ virtual void listDir( const KURL& url);
+ virtual void stat( const KURL & url);
+ virtual void get( const KURL& url );
+
+ protected:
+ QDict<HostInfo> m_hostInfoCache;
+ int readDataFromServer();
+ int lanReadDataFromServer();
+ int rlanReadDataFromServer();
+ int checkHost(const QString& host);
+ int checkPort(QValueVector<int>& _ports, in_addr ip);
+ QString m_currentHost;
+ unsigned short int m_port;
+ MyProtocolInfo m_protocolInfo[KIOLAN_MAX];
+ int m_maxAge;
+ bool m_isLanIoslave;
+ bool m_shortHostnames;
+ QString m_defaultLisaHost;
+};
+
+#endif
diff --git a/lanbrowsing/kio_lan/lan.desktop b/lanbrowsing/kio_lan/lan.desktop
new file mode 100644
index 00000000..cb4716db
--- /dev/null
+++ b/lanbrowsing/kio_lan/lan.desktop
@@ -0,0 +1,81 @@
+[Desktop Entry]
+Type=Link
+DocPath=lisa/index.html
+URL=lan:/
+Icon=network_local
+Name=Local Network
+Name[af]=Plaaslike Netwerk
+Name[ar]=الشبكة المحلية
+Name[az]=Yerli Şəbəkə
+Name[be]=Мясцовая сетка
+Name[bg]=Локална мрежа
+Name[bn]=স্থানীয় নেটওয়ার্ক
+Name[br]=Rouedad lec'hel
+Name[bs]=Lokalna mreža
+Name[ca]=Xarxa local
+Name[cs]=Lokální síť
+Name[cy]=Rhwydwaith Lleol
+Name[da]=Lokalt netværk
+Name[de]=Lokales Netzwerk
+Name[el]=Τοπικό δίκτυο
+Name[eo]=Loka reto
+Name[es]=Red local
+Name[et]=Kohalik võrk
+Name[eu]=Sare lokala
+Name[fa]=شبکۀ محلی
+Name[fi]=Paikallisverkko
+Name[fr]=Réseau local
+Name[ga]=Gréasán Logánta
+Name[gl]=Rede Local
+Name[he]=רשת מקומית
+Name[hi]=स्थानीय नेटवर्क
+Name[hr]=Lokalna mreža
+Name[hu]=Helyi hálózat
+Name[id]=Jaringan lokal
+Name[is]=Staðarnet
+Name[it]=Rete locale
+Name[ja]=ローカルネットワーク
+Name[ka]=ლოკალური ქსელი
+Name[kk]=Жергілікті желі
+Name[km]=បណ្ដាញ​មូលដ្ឋាន
+Name[ko]=지역 네트워크
+Name[lt]=Vietinis tinklas
+Name[lv]=Lokālais Tīkls
+Name[mk]=Локална мрежа
+Name[mn]=Дотоод сүлжээ
+Name[ms]=Jaringan Setempat
+Name[mt]=Network Lokali
+Name[nb]=Lokalt nettverk
+Name[nds]=Lokaal Nettwark
+Name[ne]=स्थानीय सञ्जाल
+Name[nl]=Lokaal netwerk
+Name[nn]=Lokalt nettverk
+Name[nso]=Kgokagano Selegae
+Name[pa]=ਲੋਕਲ ਨੈੱਟਵਰਕ
+Name[pl]=Sieć lokalna
+Name[pt]=Rede Local
+Name[pt_BR]=Rede local
+Name[ro]=Reţea locală
+Name[ru]=Локальная сеть
+Name[se]=Báikkálaš fierpmádat
+Name[sk]=Lokálna sieť
+Name[sl]=Krajevno omrežje
+Name[sr]=Локална мрежа
+Name[sr@Latn]=Lokalna mreža
+Name[sv]=Lokalt nätverk
+Name[ta]=உள்ளக பிணையம்
+Name[tg]=Шабакаи Маҳаллӣ
+Name[th]=เครือข่ายท้องถิ่น
+Name[tr]=Yerel Ağ
+Name[uk]=Локальна мережа
+Name[uz]=Lokal tarmoq
+Name[uz@cyrillic]=Локал тармоқ
+Name[ven]=Vhukwamani ha tsini
+Name[wa]=Rantoele locåle
+Name[xh]=Umsebenzi womnatha Wobulali
+Name[zh_CN]=局域网
+Name[zh_HK]=區域網絡
+Name[zh_TW]=區域網路
+Name[zu]=Oluseduze Uxhumaniso olusakazekile
+Open=false
+X-KDE-TreeModule=Directory
diff --git a/lanbrowsing/kio_lan/lan.protocol b/lanbrowsing/kio_lan/lan.protocol
new file mode 100644
index 00000000..ba72a216
--- /dev/null
+++ b/lanbrowsing/kio_lan/lan.protocol
@@ -0,0 +1,15 @@
+[Protocol]
+exec=kio_lan
+protocol=lan
+input=none
+output=filesystem
+listing=Name,Type
+reading=true
+writing=false
+makedir=false
+deleting=false
+linking=false
+moving=false
+DocPath=kioslave/lan.html
+Icon=network_local
+Class=:local
diff --git a/lanbrowsing/kio_lan/lisa.desktop b/lanbrowsing/kio_lan/lisa.desktop
new file mode 100644
index 00000000..207ee3e5
--- /dev/null
+++ b/lanbrowsing/kio_lan/lisa.desktop
@@ -0,0 +1,66 @@
+[Desktop Entry]
+Type=Link
+URL=lan:/
+Icon=network
+Name=LAN Browser
+Name[be]=Аглядальнік мясцовай сеткі
+Name[bg]=Браузър на локалната мрежа
+Name[bn]=ল্যান ব্রাউজার
+Name[br]=Furcher LAN
+Name[bs]=LAN preglednik
+Name[ca]=Navegador LAN
+Name[cs]=Prohlížení lokální sítě
+Name[da]=LAN-søger
+Name[de]=LAN durchsuchen
+Name[el]=Περιηγητής LAN
+Name[eo]=Rigardilo por loka reto
+Name[es]=Navegador de red
+Name[et]=Kohtvõrgu sirvija
+Name[eu]=LAN arakatzailea
+Name[fa]=مرورگر شبکۀ داخلی
+Name[fi]=Lähiverkon selain
+Name[fr]=Navigateur réseau
+Name[ga]=Brabhsálaí an Ghréasáin Logánta
+Name[gl]=Explorador LAN
+Name[he]=LAN דפדפן
+Name[hr]=Preglednik LAN-a
+Name[hu]=Hálózatböngésző
+Name[is]=Netflakkari
+Name[it]=Navigazione della rete locale
+Name[ja]=LAN ブラウザ
+Name[ka]=LAN ბროუზერი
+Name[kk]=LAN шолғышы
+Name[km]=កម្មវិធី​រុករក​បណ្ដាញ​មូលដ្ឋាន
+Name[lt]=Vietinio tinklo naršyklė
+Name[lv]=LAN Pārlūks
+Name[mk]=Прегледувач на LAN
+Name[nb]=LAN-los
+Name[nds]=Nettwark-Kieker
+Name[ne]=LAN ब्राउजर
+Name[nn]=LAN-lesar
+Name[pa]=LAN ਝਲਕਾਰਾ
+Name[pl]=Przeglądarka sieci lokalnej
+Name[pt]=Navegador de Rede
+Name[pt_BR]=Navegador LAN
+Name[ru]=Проводник LAN
+Name[se]=LAN-bláđđejeaddji
+Name[sk]=Prehliadač siete
+Name[sl]=Brskalnik po krajevnem omrežju
+Name[sr]=Претраживач LAN-а
+Name[sr@Latn]=Pretraživač LAN-a
+Name[sv]=Bläddrare i lokalt nätverk
+Name[ta]=LAN உலாவி
+Name[tg]=Барраси Шабакаи Маҳаллӣ
+Name[th]=การเรียกดูระบบแลน
+Name[tr]=LAN Tarayıcı
+Name[uk]=Навігатор ЛОМ
+Name[ven]=Buronza ya LAN
+Name[xh]=Umkhangeli zincwadi we LAN
+Name[zh_CN]=局域网浏览器
+Name[zh_HK]=區域網絡瀏覽器
+Name[zh_TW]=LAN 瀏覽器
+Name[zu]=Umbheki zincwadi ze LAN
+Open=false
+X-KDE-TreeModule=Directory
+X-KDE-KonqSidebarModule=konqsidebar_tree
+X-KDE-ConfiguredURL=kio_lanrc:noGroup:sidebarURL
diff --git a/lanbrowsing/kio_lan/rlan.protocol b/lanbrowsing/kio_lan/rlan.protocol
new file mode 100644
index 00000000..de2c0ad4
--- /dev/null
+++ b/lanbrowsing/kio_lan/rlan.protocol
@@ -0,0 +1,15 @@
+[Protocol]
+exec=kio_lan
+protocol=rlan
+input=none
+output=filesystem
+listing=Name,Type
+reading=true
+writing=false
+makedir=false
+deleting=false
+linking=false
+moving=false
+DocPath=kioslave/rlan.html
+Icon=network_local
+Class=:local