3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include "programconfig.h"
7 #include <kconfigbackend.h>
13 struct ProgramConfig::MyBackend
: KConfigINIBackEnd
15 MyBackend(KConfigBase
* cfg
, const QString
& fn
) :
16 KConfigINIBackEnd(cfg
, fn
, "", false)
18 // need the following public
19 using KConfigINIBackEnd::parseSingleConfigFile
;
22 ProgramConfig::ProgramConfig(const QString
& fileName
) :
25 m_iniBackend
= new MyBackend(this, fileName
);
26 backEnd
= m_iniBackend
;
27 reparseConfiguration();
30 QStringList
ProgramConfig::groupList() const
36 QMap
<QString
, QString
> ProgramConfig::entryMap(const QString
&) const
39 return QMap
<QString
, QString
>();
42 void ProgramConfig::reparseConfiguration()
46 // add the "default group" marker to the map
47 KEntryKey
groupKey("<default>", 0);
48 m_entryMap
.insert(groupKey
, KEntry());
50 QFile
file(m_fileName
);
53 if (file
.open(IO_ReadWrite
)) { /* don't truncate! */
55 // the file exists now
56 } else if (!file
.open(IO_ReadOnly
)) {
57 /* file does not exist and cannot be created: don't use it */
64 // Important: This must be done using fstat on the opened file
65 // to avoid race conditions.
67 memset(&s
, 0, sizeof(s
));
69 fstat(file
.handle(), &s
) == 0 &&
75 m_iniBackend
->parseSingleConfigFile(file
, 0, false, false);
80 * The program specific config file is not ours, so we do not trust
81 * it for the following reason: Should the debuggee be located in a
82 * world-writable directory somebody else may have created it where
83 * the entry DebuggerCmdStr contains a malicious command, or may
84 * have created a (possibly huge) file containing nonsense, which
89 // don't write the file if we don't own it
90 setReadOnly(readonly
|| !useit
);
93 KEntryMap
ProgramConfig::internalEntryMap(const QString
& group
) const
95 QCString group_utf
= group
.utf8();
96 KEntryMap tmpEntryMap
;
98 // copy the whole group starting at the special group marker
99 KEntryKey
key(group_utf
, 0);
100 KEntryMapConstIterator it
= m_entryMap
.find(key
);
101 for (; it
!= m_entryMap
.end() && it
.key().mGroup
== group_utf
; ++it
)
103 tmpEntryMap
.insert(it
.key(), *it
);
109 KEntryMap
ProgramConfig::internalEntryMap() const
114 void ProgramConfig::putData(const KEntryKey
& key
, const KEntry
& data
, bool checkGroup
)
118 // make sure the special group marker is present
119 m_entryMap
[KEntryKey(key
.mGroup
, 0)];
121 m_entryMap
[key
] = data
;
124 KEntry
ProgramConfig::lookupData(const KEntryKey
& key
) const
126 KEntryMapConstIterator it
;
128 it
= m_entryMap
.find(key
);
129 if (it
!= m_entryMap
.end())
131 const KEntry
& entry
= *it
;
142 bool ProgramConfig::internalHasGroup(const QCString
&) const