Debian Codegraph @

src/fdosecrets/dbus/DBusTypes.h

raw
1 /*
2 * Copyright (C) 2019 Aetf <[email protected]>
3 * Copyright 2010, Michael Leupold <[email protected]>
4 * Copyright 2010-2011, Valentin Rusu <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 or (at your option)
9 * version 3 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef KEEPASSXC_FDOSECRETS_DBUSTYPES_H
21 #define KEEPASSXC_FDOSECRETS_DBUSTYPES_H
22
23 #include <QDBusArgument>
24
25 namespace FdoSecrets
26 {
27 struct Secret;
28 class DBusMgr;
29
30 // types used directly in Qt DBus system
31 namespace wire
32 {
33 struct Secret
34 {
35 QDBusObjectPath session;
36 QByteArray parameters;
37 QByteArray value;
38 QString contentType;
39
40 ::FdoSecrets::Secret unmarshal(const QWeakPointer<DBusMgr>& weak) const;
41 };
42
43 inline QDBusArgument& operator<<(QDBusArgument& argument, const Secret& secret)
44 {
45 argument.beginStructure();
46 argument << secret.session << secret.parameters << secret.value << secret.contentType;
47 argument.endStructure();
48 return argument;
49 }
50
51 inline const QDBusArgument& operator>>(const QDBusArgument& argument, Secret& secret)
52 {
53 argument.beginStructure();
54 argument >> secret.session >> secret.parameters >> secret.value >> secret.contentType;
55 argument.endStructure();
56 return argument;
57 }
58
59 using StringStringMap = QMap<QString, QString>;
60 using ObjectPathSecretMap = QMap<QDBusObjectPath, Secret>;
61 } // namespace wire
62
63 // types used in method parameters
64 class Session;
65 class Item;
66 struct Secret
67 {
68 const Session* session;
69 QByteArray parameters;
70 QByteArray value;
71 QString contentType;
72
73 wire::Secret marshal() const;
74 };
75 using wire::StringStringMap;
76 using ItemSecretMap = QHash<Item*, Secret>;
77
78 /**
79 * Register the types needed for the fd.o Secrets D-Bus interface.
80 */
81 void registerDBusTypes(const QSharedPointer<DBusMgr>& dbus);
82
83 struct ParamData
84 {
85 QByteArray signature;
86 int dbusTypeId;
87 };
88
89 /**
90 * @brief Convert parameter type to on-the-wire type and associated dbus signature.
91 * This is NOT a generic version, and only handles types used in org.freedesktop.secrets
92 * @param id
93 * @return ParamData
94 */
95 ParamData typeToWireType(int id);
96 } // namespace FdoSecrets
97
98 Q_DECLARE_METATYPE(FdoSecrets::wire::Secret)
99 Q_DECLARE_METATYPE(FdoSecrets::wire::StringStringMap);
100 Q_DECLARE_METATYPE(FdoSecrets::wire::ObjectPathSecretMap);
101
102 Q_DECLARE_METATYPE(FdoSecrets::Secret)
103
104 #endif // KEEPASSXC_FDOSECRETS_DBUSTYPES_H