• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
knfsshare.cpp
1/* This file is part of the KDE project
2 Copyright (c) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include <tqdict.h>
20#include <tqfile.h>
21#include <tqtextstream.h>
22
23#include <kdirwatch.h>
24#include <kstaticdeleter.h>
25#include <kdebug.h>
26#include <tdeconfig.h>
27
28#include "knfsshare.h"
29
30class KNFSSharePrivate
31{
32public:
33 KNFSSharePrivate();
34
35 bool readExportsFile();
36 bool findExportsFile();
37
38 TQDict<bool> sharedPaths;
39 TQString exportsFile;
40};
41
42KNFSSharePrivate::KNFSSharePrivate()
43{
44 if (findExportsFile())
45 readExportsFile();
46}
47
54bool KNFSSharePrivate::findExportsFile() {
55 TDEConfig config("knfsshare");
56 config.setGroup("General");
57 exportsFile = config.readPathEntry("exportsFile");
58
59 if ( TQFile::exists(exportsFile) )
60 return true;
61
62 if ( TQFile::exists("/etc/exports") )
63 exportsFile = "/etc/exports";
64 else {
65 kdDebug(7000) << "KNFSShare: Could not found exports file!" << endl;
66 return false;
67 }
68
69 config.writeEntry("exportsFile",exportsFile);
70 return true;
71}
72
77bool KNFSSharePrivate::readExportsFile() {
78 TQFile f(exportsFile);
79
80 kdDebug(7000) << "KNFSShare::readExportsFile " << exportsFile << endl;
81
82 if (!f.open(IO_ReadOnly)) {
83 kdError() << "KNFSShare: Could not open " << exportsFile << endl;
84 return false;
85 }
86
87
88 sharedPaths.clear();
89
90 TQTextStream s( &f );
91
92 bool continuedLine = false; // is true if the line before ended with a backslash
93 TQString completeLine;
94
95 while ( !s.eof() )
96 {
97 TQString currentLine = s.readLine().stripWhiteSpace();
98
99 if (continuedLine) {
100 completeLine += currentLine;
101 continuedLine = false;
102 }
103 else
104 completeLine = currentLine;
105
106 // is the line continued in the next line ?
107 if ( completeLine[completeLine.length()-1] == '\\' )
108 {
109 continuedLine = true;
110 // remove the ending backslash
111 completeLine.truncate( completeLine.length()-1 );
112 continue;
113 }
114
115 // comments or empty lines
116 if (completeLine.isEmpty() ||
117 '#' == completeLine[0])
118 {
119 continue;
120 }
121
122 TQString path;
123
124 // Handle quotation marks
125 if ( completeLine[0] == '"' ) {
126 int i = completeLine.find('"',1);
127 if (i == -1) {
128 kdError() << "KNFSShare: Parse error: Missing quotation mark: " << completeLine << endl;
129 continue;
130 }
131 path = completeLine.mid(1,i-1);
132
133 } else { // no quotation marks
134 int i = completeLine.find(' ');
135 if (i == -1)
136 i = completeLine.find('\t');
137
138 if (i == -1)
139 path = completeLine;
140 else
141 path = completeLine.left(i);
142
143 }
144
145 kdDebug(7000) << "KNFSShare: Found path: " << path << endl;
146
147 // normalize path
148 if ( path[path.length()-1] != '/' )
149 path += '/';
150
151 bool b = true;
152 sharedPaths.insert(path,&b);
153 }
154
155 f.close();
156
157 return true;
158
159}
160
161KNFSShare::KNFSShare() {
162 d = new KNFSSharePrivate();
163 if (TQFile::exists(d->exportsFile)) {
164 KDirWatch::self()->addFile(d->exportsFile);
165 connect(KDirWatch::self(), TQ_SIGNAL(dirty (const TQString&)),this,
166 TQ_SLOT(slotFileChange(const TQString&)));
167 }
168}
169
170KNFSShare::~KNFSShare() {
171 if (TQFile::exists(d->exportsFile)) {
172 KDirWatch::self()->removeFile(d->exportsFile);
173 }
174 delete d;
175}
176
177
178bool KNFSShare::isDirectoryShared( const TQString & path ) const {
179 TQString fixedPath = path;
180 if ( path[path.length()-1] != '/' )
181 fixedPath += '/';
182
183 return d->sharedPaths.find(fixedPath) != 0;
184}
185
186TQStringList KNFSShare::sharedDirectories() const {
187 TQStringList result;
188 TQDictIterator<bool> it(d->sharedPaths);
189 for( ; it.current(); ++it )
190 result << it.currentKey();
191
192 return result;
193}
194
195TQString KNFSShare::exportsPath() const {
196 return d->exportsFile;
197}
198
199
200
201void KNFSShare::slotFileChange( const TQString & path ) {
202 if (path == d->exportsFile)
203 d->readExportsFile();
204
205 emit changed();
206}
207
208KNFSShare* KNFSShare::_instance = 0L;
209static KStaticDeleter<KNFSShare> ksdNFSShare;
210
211KNFSShare* KNFSShare::instance() {
212 if (! _instance )
213 _instance = ksdNFSShare.setObject(_instance, new KNFSShare());
214
215 return _instance;
216}
217
218#include "knfsshare.moc"
219
KDirWatch::self
static KDirWatch * self()
The KDirWatch instance usually globally used in an application.
Definition kdirwatch.cpp:1634
KDirWatch::addFile
void addFile(const TQString &file)
Adds a file to be watched.
Definition kdirwatch.cpp:1696
KDirWatch::removeFile
void removeFile(const TQString &file)
Removes a file from the list of watched files.
Definition kdirwatch.cpp:1723
KNFSShare
Similar functionality like KFileShare, but works only for NFS and do not need any suid script.
Definition knfsshare.h:36
KNFSShare::changed
void changed()
Emitted when the /etc/exports file has changed.
KNFSShare::isDirectoryShared
bool isDirectoryShared(const TQString &path) const
Wether or not the given path is shared by NFS.
Definition knfsshare.cpp:178
KNFSShare::instance
static KNFSShare * instance()
Returns the one and only instance of KNFSShare.
Definition knfsshare.cpp:211
KNFSShare::sharedDirectories
TQStringList sharedDirectories() const
Returns a list of all directories shared by NFS.
Definition knfsshare.cpp:186
KNFSShare::~KNFSShare
virtual ~KNFSShare()
KNFSShare destructor.
Definition knfsshare.cpp:170
KNFSShare::exportsPath
TQString exportsPath() const
Returns the path to the used exports file, or null if no exports file was found.
Definition knfsshare.cpp:195

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.8
This website is maintained by Timothy Pearson.