~ubuntu-branches/ubuntu/oneiric/kdenetwork/oneiric-updates

« back to all changes in this revision

Viewing changes to .pc/kubuntu_05_samba_sharing.diff/filesharing/advanced/nfs/nfsentry.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac, Philip Muškovac
  • Date: 2011-07-10 12:36:35 UTC
  • mfrom: (1.1.59 upstream)
  • Revision ID: package-import@ubuntu.com-20110710123635-3db9oyxdswp4sp1e
Tags: 4:4.6.90-0ubuntu1
* New upstream release
 - Bump on kde-sc-dev-latest
 - s/kdebase-runtime-dev/kde-runtime-dev
* Dropped kubuntu_05_samba_sharing.diff <- went upstream
* Added kubuntu_05_make_old_symbols_reappear_and_fix_building.diff
* Refreshed *.install
* Refreshed symbols

[ Philip Muškovac ]
* fix debug package depends on kdebase-runtime-dbg -> kde-runtime-dbg 
  and recommends on kde-workspace-dbg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Copyright (c) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de>
3
 
 
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.
8
 
 
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.
13
 
 
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.
17
 
 
18
 
*/
19
 
 
20
 
#include <kdebug.h>
21
 
 
22
 
#include "nfsentry.h"
23
 
 
24
 
NFSHost::NFSHost(const QString & hostString)
25
 
{
26
 
  readonly = true;
27
 
 
28
 
  QString s = hostString;
29
 
 
30
 
  int l = s.indexOf('(');
31
 
  int r = s.indexOf(')');
32
 
 
33
 
  initParams();
34
 
 
35
 
  // get hostname
36
 
  if (l>=0)
37
 
    name = s.left(l);
38
 
  else
39
 
    name = s;
40
 
 
41
 
  kDebug(5009) << "NFSHost: name='" << name << "'";
42
 
 
43
 
  if (l>=0 && r>=0)
44
 
  {
45
 
    QString params = s.mid(l+1,r-l-1);
46
 
 
47
 
    parseParamsString(params);
48
 
  }
49
 
}
50
 
 
51
 
NFSHost::NFSHost() {
52
 
  initParams();
53
 
  name="";
54
 
}
55
 
 
56
 
NFSHost::~NFSHost()
57
 
{
58
 
}
59
 
 
60
 
/**
61
 
 * Set the parameters to their default values
62
 
 */
63
 
void NFSHost::initParams()
64
 
{
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;
74
 
 
75
 
  anonuid = 65534;
76
 
  anongid = 65534;
77
 
}
78
 
 
79
 
 
80
 
void NFSHost::parseParamsString(const QString & s)
81
 
{
82
 
 
83
 
  if (s.isEmpty())
84
 
      return;
85
 
 
86
 
  int i;
87
 
 
88
 
  QString rest = s;
89
 
  QString p;
90
 
 
91
 
  do
92
 
  {
93
 
    i = rest.indexOf(",",0);
94
 
 
95
 
    if (i==-1)
96
 
      p = rest;
97
 
    else
98
 
    {
99
 
      p = rest.left( i );
100
 
      rest = rest.mid(i+1);
101
 
    }
102
 
 
103
 
    setParam(p);
104
 
  }
105
 
  while (i>-1);
106
 
 
107
 
}
108
 
 
109
 
QString NFSHost::paramString() const
110
 
{
111
 
  QString s;
112
 
 
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,";
122
 
 
123
 
  if (!wdelay) s+="wdelay,";
124
 
  if (allSquash) s+="all_squash,";
125
 
  if (!hide) s+="nohide,";
126
 
 
127
 
  if (anongid!=65534)
128
 
     s+=QString("anongid=%1,").arg(anongid);
129
 
 
130
 
  if (anonuid!=65534)
131
 
     s+=QString("anonuid=%1,").arg(anonuid);
132
 
 
133
 
  // get rid of the last ','
134
 
  s.truncate(s.length()-1);
135
 
 
136
 
  return s;
137
 
}
138
 
 
139
 
QString NFSHost::toString() const
140
 
{
141
 
  QString s = name;
142
 
 
143
 
  s+='(';
144
 
  s+=paramString();
145
 
  s+=')';
146
 
 
147
 
  return s;
148
 
 
149
 
}
150
 
 
151
 
NFSHost* NFSHost::copy() const {
152
 
  NFSHost* result = new NFSHost();
153
 
 
154
 
  result->name = name;
155
 
 
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;
165
 
 
166
 
  result->anonuid = anonuid;
167
 
  result->anongid = anongid;
168
 
 
169
 
  return result;
170
 
}
171
 
 
172
 
bool NFSHost::isPublic() const {
173
 
  return name == "*";
174
 
}
175
 
 
176
 
void NFSHost::setParam(const QString & s)
177
 
{
178
 
  QString p = s.toLower();
179
 
 
180
 
  if (p=="ro") {
181
 
     readonly = true;
182
 
     return; }
183
 
 
184
 
  if (p=="rw") {
185
 
     readonly = false;
186
 
     return; }
187
 
 
188
 
  if (p=="sync") {
189
 
     sync = true;
190
 
     return; }
191
 
 
192
 
  if (p=="async") {
193
 
     sync = false;
194
 
     return; }
195
 
 
196
 
  if (p=="secure") {
197
 
     secure = true;
198
 
     return; }
199
 
 
200
 
  if (p=="insecure") {
201
 
     secure = false;
202
 
     return; }
203
 
 
204
 
  if (p=="wdelay") {
205
 
     wdelay = true;
206
 
     return; }
207
 
 
208
 
  if (p=="no_wdelay") {
209
 
     wdelay = false;
210
 
     return; }
211
 
 
212
 
  if (p=="hide") {
213
 
     hide = true;
214
 
     return; }
215
 
 
216
 
  if (p=="nohide") {
217
 
     hide = false;
218
 
     return; }
219
 
 
220
 
  if (p=="subtree_check") {
221
 
     subtreeCheck = true;
222
 
     return; }
223
 
 
224
 
  if (p=="no_subtree_check") {
225
 
     subtreeCheck = false;
226
 
     return; }
227
 
 
228
 
  if (p=="secure_locks" ||
229
 
      p=="auth_nlm") {
230
 
     secureLocks = true;
231
 
     return; }
232
 
 
233
 
  if (p=="insecure_locks" ||
234
 
      p=="no_auth_nlm" ) {
235
 
     secureLocks = true;
236
 
     return; }
237
 
 
238
 
  if (p=="all_squash") {
239
 
     allSquash = true;
240
 
     return; }
241
 
 
242
 
  if (p=="no_all_squash") {
243
 
     allSquash = false;
244
 
     return; }
245
 
 
246
 
  if (p=="root_squash") {
247
 
     rootSquash = true;
248
 
     return; }
249
 
 
250
 
  if (p=="no_root_squash") {
251
 
     rootSquash = false;
252
 
     return; }
253
 
 
254
 
  int i = p.indexOf('=',0);
255
 
 
256
 
  // get anongid or anonuid
257
 
  if (i>-1)
258
 
  {
259
 
     QString name = p.left(i).toLower();
260
 
     kDebug(5009) << name;
261
 
 
262
 
     QString value = p.mid(i+1);
263
 
     kDebug(5009) << value;
264
 
 
265
 
    if (name=="anongid")
266
 
       anongid = value.toInt();
267
 
 
268
 
    if (name=="anonuid")
269
 
       anonuid = value.toInt();
270
 
  }
271
 
 
272
 
}
273
 
 
274
 
NFSEntry::NFSEntry(const QString & path)
275
 
{
276
 
  _hosts.setAutoDelete(true);
277
 
  setPath(path);
278
 
}
279
 
 
280
 
NFSEntry::~NFSEntry()
281
 
{
282
 
}
283
 
 
284
 
void NFSEntry::clear() {
285
 
  _hosts.clear();
286
 
}
287
 
 
288
 
NFSEntry* NFSEntry::copy() {
289
 
  NFSEntry* result = new NFSEntry(path());
290
 
  result->copyFrom(this);
291
 
  return result;
292
 
}
293
 
 
294
 
void NFSEntry::copyFrom(NFSEntry* entry) {
295
 
  clear();
296
 
  HostIterator it = entry->getHosts();
297
 
 
298
 
  NFSHost* host;
299
 
  while ( (host = it.current()) != 0 )  {
300
 
    ++it;
301
 
    addHost(host->copy());
302
 
  }
303
 
}
304
 
 
305
 
QString NFSEntry::toString() const
306
 
{
307
 
  QString s = _path.trimmed();
308
 
 
309
 
  if (_path.contains(' ')) {
310
 
    s = '"'+s+'"';
311
 
  }
312
 
 
313
 
  s += ' ';
314
 
 
315
 
  HostIterator it = getHosts();
316
 
 
317
 
  NFSHost* host;
318
 
 
319
 
  while ( (host = it.current()) != 0 )
320
 
  {
321
 
    ++it;
322
 
    s+= host->toString() ;
323
 
    if (it.current())
324
 
        s+= " \\\n\t ";
325
 
  }
326
 
 
327
 
 
328
 
  return s;
329
 
}
330
 
 
331
 
void NFSEntry::addHost(NFSHost * host)
332
 
{
333
 
  _hosts.append(host);
334
 
}
335
 
 
336
 
void NFSEntry::removeHost(NFSHost * host)
337
 
{
338
 
  _hosts.remove(host);
339
 
}
340
 
 
341
 
NFSHost* NFSEntry::getHostByName(const QString & name) const
342
 
{
343
 
  HostIterator it = getHosts();
344
 
  NFSHost* host;
345
 
 
346
 
  while ( (host = it.current()) != 0 )
347
 
  {
348
 
    ++it;
349
 
 
350
 
    if (host->name==name)
351
 
      return host;
352
 
  }
353
 
 
354
 
  return 0;
355
 
}
356
 
 
357
 
NFSHost* NFSEntry::getPublicHost() const
358
 
{
359
 
  NFSHost* result = getHostByName("*");
360
 
  if (result)
361
 
      return result;
362
 
 
363
 
  return getHostByName(QString::null);  //krazy:exclude=nullstrassign for old broken gcc
364
 
}
365
 
 
366
 
 
367
 
HostIterator NFSEntry::getHosts() const
368
 
{
369
 
  return HostIterator(_hosts);
370
 
}
371
 
 
372
 
QString NFSEntry::path() const
373
 
{
374
 
  return _path;
375
 
}
376
 
 
377
 
void NFSEntry::setPath(const QString & path)
378
 
{
379
 
  _path = path;
380
 
}
381