Show invite menu in wlm chat window immediately
[kdenetwork.git] / filesharing / advanced / nfs / nfsentry.cpp
blob9770e9d3d5afc62268f24baf7ef0b5558dd2d227
1 /*
2 Copyright (c) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <kdebug.h>
22 #include "nfsentry.h"
24 NFSHost::NFSHost(const QString & hostString)
26 readonly = true;
28 QString s = hostString;
30 int l = s.indexOf('(');
31 int r = s.indexOf(')');
33 initParams();
35 // get hostname
36 if (l>=0)
37 name = s.left(l);
38 else
39 name = s;
41 kDebug(5009) << "NFSHost: name='" << name << "'";
43 if (l>=0 && r>=0)
45 QString params = s.mid(l+1,r-l-1);
47 parseParamsString(params);
51 NFSHost::NFSHost() {
52 initParams();
53 name="";
56 NFSHost::~NFSHost()
60 /**
61 * Set the parameters to their default values
63 void NFSHost::initParams()
65 readonly = true;
66 sync = false;
67 secure = true;
68 wdelay = true;
69 hide = true;
70 subtreeCheck = true;
71 secureLocks = true;
72 allSquash = false;
73 rootSquash = true;
75 anonuid = 65534;
76 anongid = 65534;
80 void NFSHost::parseParamsString(const QString & s)
83 if (s.isEmpty())
84 return;
86 int i;
88 QString rest = s;
89 QString p;
93 i = rest.indexOf(",",0);
95 if (i==-1)
96 p = rest;
97 else
99 p = rest.left( i );
100 rest = rest.mid(i+1);
103 setParam(p);
105 while (i>-1);
109 QString NFSHost::paramString() const
111 QString s;
113 if (!readonly) s+="rw,";
114 if (!rootSquash) s+="no_root_squash,";
115 if (!secure) s+="insecure,";
116 if (!secureLocks) s+="insecure_locks,";
117 if (!subtreeCheck) s+="no_subtree_check,";
118 if (sync)
119 s+="sync,";
120 else
121 s+="async,";
123 if (!wdelay) s+="wdelay,";
124 if (allSquash) s+="all_squash,";
125 if (!hide) s+="nohide,";
127 if (anongid!=65534)
128 s+=QString("anongid=%1,").arg(anongid);
130 if (anonuid!=65534)
131 s+=QString("anonuid=%1,").arg(anonuid);
133 // get rid of the last ','
134 s.truncate(s.length()-1);
136 return s;
139 QString NFSHost::toString() const
141 QString s = name;
143 s+='(';
144 s+=paramString();
145 s+=')';
147 return s;
151 NFSHost* NFSHost::copy() const {
152 NFSHost* result = new NFSHost();
154 result->name = name;
156 result->readonly = readonly;
157 result->sync = sync;
158 result->secure = secure;
159 result->wdelay = wdelay;
160 result->hide = hide;
161 result->subtreeCheck = subtreeCheck;
162 result->secureLocks = secureLocks;
163 result->allSquash = allSquash;
164 result->rootSquash = rootSquash;
166 result->anonuid = anonuid;
167 result->anongid = anongid;
169 return result;
172 bool NFSHost::isPublic() const {
173 return name == "*";
176 void NFSHost::setParam(const QString & s)
178 QString p = s.toLower();
180 if (p=="ro") {
181 readonly = true;
182 return; }
184 if (p=="rw") {
185 readonly = false;
186 return; }
188 if (p=="sync") {
189 sync = true;
190 return; }
192 if (p=="async") {
193 sync = false;
194 return; }
196 if (p=="secure") {
197 secure = true;
198 return; }
200 if (p=="insecure") {
201 secure = false;
202 return; }
204 if (p=="wdelay") {
205 wdelay = true;
206 return; }
208 if (p=="no_wdelay") {
209 wdelay = false;
210 return; }
212 if (p=="hide") {
213 hide = true;
214 return; }
216 if (p=="nohide") {
217 hide = false;
218 return; }
220 if (p=="subtree_check") {
221 subtreeCheck = true;
222 return; }
224 if (p=="no_subtree_check") {
225 subtreeCheck = false;
226 return; }
228 if (p=="secure_locks" ||
229 p=="auth_nlm") {
230 secureLocks = true;
231 return; }
233 if (p=="insecure_locks" ||
234 p=="no_auth_nlm" ) {
235 secureLocks = true;
236 return; }
238 if (p=="all_squash") {
239 allSquash = true;
240 return; }
242 if (p=="no_all_squash") {
243 allSquash = false;
244 return; }
246 if (p=="root_squash") {
247 rootSquash = true;
248 return; }
250 if (p=="no_root_squash") {
251 rootSquash = false;
252 return; }
254 int i = p.indexOf('=',0);
256 // get anongid or anonuid
257 if (i>-1)
259 QString name = p.left(i).toLower();
260 kDebug(5009) << name;
262 QString value = p.mid(i+1);
263 kDebug(5009) << value;
265 if (name=="anongid")
266 anongid = value.toInt();
268 if (name=="anonuid")
269 anonuid = value.toInt();
274 NFSEntry::NFSEntry(const QString & path)
276 _hosts.setAutoDelete(true);
277 setPath(path);
280 NFSEntry::~NFSEntry()
284 void NFSEntry::clear() {
285 _hosts.clear();
288 NFSEntry* NFSEntry::copy() {
289 NFSEntry* result = new NFSEntry(path());
290 result->copyFrom(this);
291 return result;
294 void NFSEntry::copyFrom(NFSEntry* entry) {
295 clear();
296 HostIterator it = entry->getHosts();
298 NFSHost* host;
299 while ( (host = it.current()) != 0 ) {
300 ++it;
301 addHost(host->copy());
305 QString NFSEntry::toString() const
307 QString s = _path.trimmed();
309 if (_path.contains(' ')) {
310 s = '"'+s+'"';
313 s += ' ';
315 HostIterator it = getHosts();
317 NFSHost* host;
319 while ( (host = it.current()) != 0 )
321 ++it;
322 s+= host->toString() ;
323 if (it.current())
324 s+= " \\\n\t ";
328 return s;
331 void NFSEntry::addHost(NFSHost * host)
333 _hosts.append(host);
336 void NFSEntry::removeHost(NFSHost * host)
338 _hosts.remove(host);
341 NFSHost* NFSEntry::getHostByName(const QString & name) const
343 HostIterator it = getHosts();
344 NFSHost* host;
346 while ( (host = it.current()) != 0 )
348 ++it;
350 if (host->name==name)
351 return host;
354 return 0;
357 NFSHost* NFSEntry::getPublicHost() const
359 NFSHost* result = getHostByName("*");
360 if (result)
361 return result;
363 return getHostByName(QString::null); //krazy:exclude=nullstrassign for old broken gcc
367 HostIterator NFSEntry::getHosts() const
369 return HostIterator(_hosts);
372 QString NFSEntry::path() const
374 return _path;
377 void NFSEntry::setPath(const QString & path)
379 _path = path;