2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
7 #include "programconfig.h"
8 #include <kconfigbackend.h>
14 struct ProgramConfig::MyBackend
: KConfigINIBackEnd
16 MyBackend(KConfigBase
* cfg
, const QString
& fn
) :
17 KConfigINIBackEnd(cfg
, fn
, "", false)
19 // need the following public
20 using KConfigINIBackEnd::parseSingleConfigFile
;
23 ProgramConfig::ProgramConfig(const QString
& fileName
) :
26 m_iniBackend
= new MyBackend(this, fileName
);
27 backEnd
= m_iniBackend
;
28 reparseConfiguration();
31 QStringList
ProgramConfig::groupList() const
37 QMap
<QString
, QString
> ProgramConfig::entryMap(const QString
&) const
40 return QMap
<QString
, QString
>();
43 void ProgramConfig::reparseConfiguration()
47 // add the "default group" marker to the map
48 KEntryKey
groupKey("<default>", 0);
49 m_entryMap
.insert(groupKey
, KEntry());
51 QFile
file(m_fileName
);
54 if (file
.open(IO_ReadWrite
)) { /* don't truncate! */
56 // the file exists now
57 } else if (!file
.open(IO_ReadOnly
)) {
58 /* file does not exist and cannot be created: don't use it */
65 // Important: This must be done using fstat on the opened file
66 // to avoid race conditions.
68 memset(&s
, 0, sizeof(s
));
70 fstat(file
.handle(), &s
) == 0 &&
76 m_iniBackend
->parseSingleConfigFile(file
, 0, false, false);
81 * The program specific config file is not ours, so we do not trust
82 * it for the following reason: Should the debuggee be located in a
83 * world-writable directory somebody else may have created it where
84 * the entry DebuggerCmdStr contains a malicious command, or may
85 * have created a (possibly huge) file containing nonsense, which
90 // don't write the file if we don't own it
91 setReadOnly(readonly
|| !useit
);
94 KEntryMap
ProgramConfig::internalEntryMap(const QString
& group
) const
96 QCString group_utf
= group
.utf8();
97 KEntryMap tmpEntryMap
;
99 // copy the whole group starting at the special group marker
100 KEntryKey
key(group_utf
, 0);
101 KEntryMapConstIterator it
= m_entryMap
.find(key
);
102 for (; it
!= m_entryMap
.end() && it
.key().mGroup
== group_utf
; ++it
)
104 tmpEntryMap
.insert(it
.key(), *it
);
110 KEntryMap
ProgramConfig::internalEntryMap() const
115 void ProgramConfig::putData(const KEntryKey
& key
, const KEntry
& data
, bool checkGroup
)
119 // make sure the special group marker is present
120 m_entryMap
[KEntryKey(key
.mGroup
, 0)];
122 m_entryMap
[key
] = data
;
125 KEntry
ProgramConfig::lookupData(const KEntryKey
& key
) const
127 KEntryMapConstIterator it
;
129 it
= m_entryMap
.find(key
);
130 if (it
!= m_entryMap
.end())
132 const KEntry
& entry
= *it
;
143 bool ProgramConfig::internalHasGroup(const QCString
&) const