24 #include <QCoreApplication>
27 #include <QStringList>
35 int main(
int argc,
char **argv)
37 QCoreApplication app(argc, argv);
40 qCritical(
"Too few arguments");
44 QSettings ini(QFile::decodeName(argv[1]), QSettings::IniFormat);
45 ini.setIniCodec(
"UTF-8");
47 qCritical(
"Error loading file: %s", argv[1]);
57 QRegExp actionExp(QLatin1String(
"[0-9a-z]+(\\.[0-9a-z]+)*"));
58 QRegExp descriptionExp(QLatin1String(
"description(?:\\[(\\w+)\\])?"));
59 QRegExp nameExp(QLatin1String(
"name(?:\\[(\\w+)\\])?"));
60 QRegExp policyExp(QLatin1String(
"yes|no|auth_self|auth_admin"));
62 descriptionExp.setCaseSensitivity(Qt::CaseInsensitive);
63 nameExp.setCaseSensitivity(Qt::CaseInsensitive);
65 foreach(
const QString &name, ini.childGroups()) {
68 if (name == QLatin1String(
"Domain")) {
72 if (!actionExp.exactMatch(name)) {
73 qCritical(
"Wrong action syntax: %s\n", name.toLatin1().data());
80 foreach(
const QString &key, ini.childKeys()) {
81 if (descriptionExp.exactMatch(key)) {
82 QString lang = descriptionExp.capturedTexts().at(1);
85 lang = QString::fromLatin1(
"en");
87 action.
descriptions.insert(lang, ini.value(key).toString());
89 }
else if (nameExp.exactMatch(key)) {
90 QString lang = nameExp.capturedTexts().at(1);
93 lang = QString::fromLatin1(
"en");
95 action.
messages.insert(lang, ini.value(key).toString());
97 }
else if (key.toLower() == QLatin1String(
"policy")) {
98 QString policy = ini.value(key).toString();
99 if (!policyExp.exactMatch(policy)) {
100 qCritical(
"Wrong policy: %s", policy.toLatin1().data());
105 }
else if (key.toLower() == QLatin1String(
"policyinactive")) {
106 QString policyInactive = ini.value(key).toString();
107 if (!policyExp.exactMatch(policyInactive)) {
108 qCritical(
"Wrong policy: %s", policyInactive.toLatin1().data());
113 }
else if (key.toLower() == QLatin1String(
"persistence")) {
114 QString persistence = ini.value(key).toString();
115 if (persistence != QLatin1String(
"session") && persistence != QLatin1String(
"always")) {
116 qCritical(
"Wrong persistence: %s", persistence.toLatin1().data());
124 qCritical(
"Missing option in action: %s", name.toLatin1().data());
129 actions.append(action);
140 if (ini.childGroups().contains(QString::fromLatin1(
"Domain"))) {
141 if (ini.contains(QString::fromLatin1(
"Domain/Name"))) {
142 rethash[QString::fromLatin1(
"vendor")] = ini.value(QString::fromLatin1(
"Domain/Name")).toString();
144 if (ini.contains(QString::fromLatin1(
"Domain/URL"))) {
145 rethash[QString::fromLatin1(
"vendorurl")] = ini.value(QString::fromLatin1(
"Domain/URL")).toString();
147 if (ini.contains(QString::fromLatin1(
"Domain/Icon"))) {
148 rethash[QString::fromLatin1(
"icon")] = ini.value(QString::fromLatin1(
"Domain/Icon")).toString();
QHash< QString, QString > descriptions
QHash< QString, QString > parseDomain(QSettings &ini)
int main(int argc, char **argv)
void output(QList< Action > actions, QHash< QString, QString > domain)
QList< Action > parse(QSettings &ini)
QHash< QString, QString > messages