3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 1999,2000 Geert Jansen <g.t.jansen@stud.tue.nl>
16 Repository::Repository()
18 head_time
= (unsigned) -1;
22 Repository::~Repository()
26 void Repository::add(const QByteArray
&key
, Data_entry
&data
)
28 RepoIterator it
= repo
.find(key
);
31 if (data
.timeout
== 0)
32 data
.timeout
= (unsigned) -1;
34 data
.timeout
+= time(0L);
35 head_time
= qMin(head_time
, data
.timeout
);
36 repo
.insert(key
, data
);
39 int Repository::remove(const QByteArray
&key
)
44 RepoIterator it
= repo
.find(key
);
47 it
.value().value
.fill('x');
48 it
.value().group
.fill('x');
53 int Repository::removeSpecialKey(const QByteArray
&key
)
58 QStack
<QByteArray
> rm_keys
;
59 for (RepoCIterator it
=repo
.constBegin(); it
!=repo
.constEnd(); ++it
)
61 if ( key
.indexOf( it
.value().group
) == 0 &&
62 it
.key().indexOf( key
) >= 0 )
64 rm_keys
.push(it
.key());
68 while (!rm_keys
.isEmpty())
70 kDebug(1205) << "Removed key: " << rm_keys
.top();
71 remove(rm_keys
.pop());
77 int Repository::removeGroup(const QByteArray
&group
)
80 if ( !group
.isEmpty() )
82 QStack
<QByteArray
> rm_keys
;
83 for (RepoCIterator it
=repo
.constBegin(); it
!=repo
.constEnd(); ++it
)
85 if (it
.value().group
== group
)
87 rm_keys
.push(it
.key());
91 while (!rm_keys
.isEmpty())
93 kDebug(1205) << "Removed key: " << rm_keys
.top();
94 remove(rm_keys
.pop());
100 int Repository::hasGroup(const QByteArray
&group
) const
102 if ( !group
.isEmpty() )
105 for (it
=repo
.begin(); it
!=repo
.end(); ++it
)
107 if (it
.value().group
== group
)
114 QByteArray
Repository::findKeys(const QByteArray
&group
, const char *sep
) const
117 if( !group
.isEmpty() )
119 kDebug(1205) << "Looking for matching key with group key: " << group
;
123 for (it
=repo
.begin(); it
!=repo
.end(); ++it
)
125 if (it
.value().group
== group
)
128 kDebug(1205) << "Matching key found: " << key
;
129 pos
= key
.lastIndexOf(sep
);
134 // Add the same keys only once please :)
135 if( !list
.contains(key
) )
137 kDebug(1205) << "Key added to list: " << key
;
138 list
+= '\007'; // I do not know
150 QByteArray
Repository::find(const QByteArray
&key
) const
155 RepoCIterator it
= repo
.find(key
);
156 if (it
== repo
.end())
158 return it
.value().value
;
162 int Repository::expire()
164 unsigned current
= time(0L);
165 if (current
< head_time
)
169 QStack
<QByteArray
> keys
;
170 head_time
= (unsigned) -1;
172 for (it
=repo
.begin(); it
!=repo
.end(); ++it
)
174 t
= it
.value().timeout
;
178 head_time
= qMin(head_time
, t
);
181 int n
= keys
.count();
182 while (!keys
.isEmpty())