• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • auth
  • backends
  • polkit-1
kauth-policy-gen-polkit1.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2008 Nicola Gigante <nicola.gigante@gmail.com>
3 * Copyright (C) 2009-2010 Dario Freddi <drf@kde.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA .
19 */
20 
21 #include <auth/policy-gen/policy-gen.h>
22 
23 #include <cstdio>
24 #include <QDebug>
25 #include <QTextStream>
26 
27 const char header[] = ""
28  "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
29  "<!DOCTYPE policyconfig PUBLIC\n"
30  "\"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN\"\n"
31  "\"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd\">\n"
32  "<policyconfig>\n";
33 
34 const char policy_tag[] = ""
35  " <defaults>\n"
36  " <allow_inactive>%1</allow_inactive>\n"
37  " <allow_active>%2</allow_active>\n"
38  " </defaults>\n";
39 
40 const char dent[] = " ";
41 
42 void output(QList<Action> actions, QHash<QString, QString> domain)
43 {
44  QTextStream out(stdout);
45  out.setCodec("UTF-8");
46 
47  out << header;
48 
49  // Blacklisted characters + replacements
50  QHash< QChar, QString > blacklist;
51  blacklist.insert(QLatin1Char('&'), QLatin1String("&amp;"));
52 
53  if (domain.contains(QLatin1String("vendor"))) {
54  QHash< QChar, QString >::const_iterator blI;
55  QString vendor = domain[QLatin1String("vendor")];
56  for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
57  vendor.replace(blI.key(), blI.value());
58  }
59  out << "<vendor>" << vendor << "</vendor>\n";
60  }
61  if (domain.contains(QLatin1String("vendorurl"))) {
62  out << "<vendor_url>" << domain[QLatin1String("vendorurl")] << "</vendor_url>\n";
63  }
64  if (domain.contains(QLatin1String("icon"))) {
65  out << "<icon_name>" << domain[QLatin1String("icon")] << "</icon_name>\n";
66  }
67 
68  foreach (const Action &action, actions) {
69  out << dent << "<action id=\"" << action.name << "\" >\n";
70 
71  // Not a typo, messages and descriptions are actually inverted
72  for (QHash< QString, QString >::const_iterator i = action.messages.constBegin(); i != action.messages.constEnd(); ++i) {
73  out << dent << dent << "<description";
74  if (i.key() != QLatin1String("en")) {
75  out << " xml:lang=\"" << i.key() << '"';
76  }
77 
78  QHash< QChar, QString >::const_iterator blI;
79  QString description = i.value();
80  for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
81  description.replace(blI.key(), blI.value());
82  }
83 
84  out << '>' << description << "</description>\n";
85  }
86 
87  QHash< QString, QString >::const_iterator i;
88  for (QHash< QString, QString >::const_iterator i = action.descriptions.constBegin();
89  i != action.descriptions.constEnd();
90  ++i) {
91  out << dent << dent << "<message";
92  if (i.key() != QLatin1String("en")) {
93  out << " xml:lang=\"" << i.key() << '"';
94  }
95 
96  QHash< QChar, QString >::const_iterator blI;
97  QString message = i.value();
98  for (blI = blacklist.constBegin(); blI != blacklist.constEnd(); ++blI) {
99  message.replace(blI.key(), blI.value());
100  }
101 
102  out << '>' << message << "</message>\n";
103  }
104 
105  QString policy = action.policy;
106  QString policyInactive = action.policyInactive.isEmpty() ? QLatin1String("no") : action.policyInactive;
107  if (!action.persistence.isEmpty() && policy != QLatin1String("yes") && policy !=
108  QLatin1String("no")) {
109  policy += QLatin1String("_keep");
110  }
111  if (!action.persistence.isEmpty() && policyInactive != QLatin1String("yes") && policyInactive !=
112  QLatin1String("no")) {
113  policyInactive += QLatin1String("_keep");
114  }
115 
116  out << QString(QLatin1String(policy_tag)).arg(policyInactive).arg(policy);
117 
118  out << dent << "</action>\n";
119  }
120 
121  out << "</policyconfig>\n";
122 }
QTextStream::setCodec
void setCodec(QTextCodec *codec)
KMessage::message
void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
Display a long message of a certain type.
Definition: kmessage.cpp:92
Action::name
QString name
Definition: policy-gen.h:29
QHash::insert
iterator insert(const Key &key, const T &value)
QTextStream
output
void output(QList< Action > actions, QHash< QString, QString > domain)
Definition: kauth-policy-gen-polkit1.cpp:42
QHash::constEnd
const_iterator constEnd() const
QHash< QString, QString >
policy-gen.h
QString
QList
Definition: kaboutdata.h:33
Action
Definition: policy-gen.h:28
QLatin1Char
QHash::const_iterator
QString::replace
QString & replace(int position, int n, QChar after)
QHash::constBegin
const_iterator constBegin() const
policy_tag
const char policy_tag[]
Definition: kauth-policy-gen-polkit1.cpp:34
QLatin1String
header
const char header[]
Definition: kauth-policy-gen-polkit1.cpp:27
QHash::contains
bool contains(const Key &key) const
dent
const char dent[]
Definition: kauth-policy-gen-polkit1.cpp:40
Action::messages
QHash< QString, QString > messages
Definition: policy-gen.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal