Merge lp:~mardy/online-accounts-api/dbus-api into lp:online-accounts-api

Proposed by Alberto Mardegan
Status: Superseded
Proposed branch: lp:~mardy/online-accounts-api/dbus-api
Merge into: lp:online-accounts-api
Diff against target: 481 lines (+157/-158)
6 files modified
src/daemon/aacontext.cpp (+31/-26)
src/daemon/aacontext.h (+2/-2)
src/daemon/main.cpp (+2/-1)
src/daemon/manager.cpp (+77/-64)
src/daemon/manager.h (+26/-22)
src/daemon/manager.xml (+19/-43)
To merge this branch: bzr merge lp:~mardy/online-accounts-api/dbus-api
Reviewer Review Type Date Requested Status
James Henstridge Needs Fixing
Review via email: mp+249089@code.launchpad.net

This proposal has been superseded by a proposal from 2015-02-11.

Commit message

Update D-Bus API, fix warnings

Description of the change

Update D-Bus API, fix warnings

To post a comment you must log in.
Revision history for this message
James Henstridge (jamesh) wrote :

Hi Alberto,

Many of these changes seem to be things that we disagreed about in the meeting previously. I have also been working on updating the interface as we discussed at that meeting, so can we hold off on this?

I've left some inline comments in the diff.

review: Needs Fixing
Revision history for this message
Alberto Mardegan (mardy) wrote :

> Many of these changes seem to be things that we disagreed about in the meeting
> previously. I have also been working on updating the interface as we
> discussed at that meeting, so can we hold off on this?

I'm proposing this exactly in order to discuss about the disagreements. :-)
Keep in mind that what we currently have in trunk has not been agreed upon either. Anyway, I won't merge this until we've got a consensus, or until we come to the conclusion that a consensus cannot be reached.
On the other hand, defining this interface is our top priority, because all the client side will be blocked until we settle this.

5. By Alberto Mardegan

Update

Revision history for this message
Alberto Mardegan (mardy) wrote :

I just pushed a new commit, taking your comments into account. I also replied to them, but in order to see my replies you'll have to select the "r4 into r3" diff into the "Preview Diff" selection box below.

Revision history for this message
James Henstridge (jamesh) wrote :

Replies to r4 comments.

review: Needs Fixing
Revision history for this message
James Henstridge (jamesh) wrote :

Now for r5:

As a general question, what style guide are you trying to convert this code to conform to exactly? I'd really appreciate it if you didn't mix these kinds of code clean ups in with functional changes: all it does is obscure what you're changing.

6. By Alberto Mardegan

merge from style

7. By Alberto Mardegan

Update

8. By Alberto Mardegan

style

9. By Alberto Mardegan

merge style

10. By Alberto Mardegan

from trunk

11. By Alberto Mardegan

Update docstring

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/daemon/aacontext.cpp'
2--- src/daemon/aacontext.cpp 2015-02-10 08:12:59 +0000
3+++ src/daemon/aacontext.cpp 2015-02-10 16:00:33 +0000
4@@ -1,47 +1,52 @@
5+#include <QDBusConnection>
6+#include <QDBusMessage>
7+#include <QDebug>
8 #include "aacontext.h"
9-#include <stdexcept>
10 #include <sys/apparmor.h>
11-#include <QDebug>
12-#include <QDBusConnection>
13-#include <QDBusMessage>
14-
15-const int max_cache_size = 50;
16-
17-AppArmorContext::AppArmorContext() {
18-}
19-
20-AppArmorContext::~AppArmorContext() {
21-}
22-
23-QString AppArmorContext::getPeerSecurityContext(const QDBusConnection &bus, const QDBusMessage &message) {
24+
25+const int maxCacheSize = 50;
26+
27+AppArmorContext::AppArmorContext()
28+{
29+}
30+
31+AppArmorContext::~AppArmorContext()
32+{
33+}
34+
35+QString AppArmorContext::getPeerSecurityContext(const QDBusConnection &bus,
36+ const QDBusMessage &message)
37+{
38 if (!aa_is_enabled()) {
39 return "unconfined";
40 }
41
42 QString peer_address = message.service();
43- try {
44- return contexts.at(peer_address);
45- } catch (const std::out_of_range &e) {
46+ QString &context = m_contexts[peer_address];
47+ /* If the peer_address was now known, it's now been added as an empty
48+ * QString. */
49+ if (!context.isEmpty()) {
50+ return context;
51 }
52
53- QDBusMessage msg = QDBusMessage::createMethodCall(
54- "org.freedesktop.DBus", "/org/freedesktop/DBus",
55- "org.freedesktop.DBus", "GetConnectionAppArmorSecurityContext");
56+ QDBusMessage msg =
57+ QDBusMessage::createMethodCall("org.freedesktop.DBus",
58+ "/org/freedesktop/DBus",
59+ "org.freedesktop.DBus",
60+ "GetConnectionAppArmorSecurityContext");
61 msg << peer_address;
62 QDBusMessage reply = bus.call(msg, QDBus::Block);
63
64- QString context;
65 if (reply.type() == QDBusMessage::ReplyMessage) {
66 context = reply.arguments().value(0).value<QString>();
67 } else {
68- qWarning() << "Could not determine AppArmor context: "
69- << reply.errorName() << ": " << reply.errorMessage();
70+ qWarning() << "Could not determine AppArmor context: " <<
71+ reply.errorName() << ": " << reply.errorMessage();
72 }
73
74 // If the context cache has hit the maximum size, clear it
75- if (contexts.size() >= max_cache_size) {
76- contexts.clear();
77+ if (m_contexts.size() >= maxCacheSize) {
78+ m_contexts.clear();
79 }
80- contexts[peer_address] = context;
81 return context;
82 }
83
84=== modified file 'src/daemon/aacontext.h'
85--- src/daemon/aacontext.h 2015-02-09 05:18:22 +0000
86+++ src/daemon/aacontext.h 2015-02-10 16:00:33 +0000
87@@ -1,9 +1,9 @@
88 #ifndef AACONTEXT_H
89 #define AACONTEXT_H
90
91-#include <map>
92 #include <QDBusConnection>
93 #include <QDBusMessage>
94+#include <QHash>
95 #include <QString>
96
97 class AppArmorContext {
98@@ -14,7 +14,7 @@
99 QString getPeerSecurityContext(const QDBusConnection &bus, const QDBusMessage &message);
100
101 private:
102- std::map<QString,QString> contexts;
103+ QHash<QString,QString> m_contexts;
104 };
105
106 #endif
107
108=== modified file 'src/daemon/main.cpp'
109--- src/daemon/main.cpp 2015-02-10 06:24:38 +0000
110+++ src/daemon/main.cpp 2015-02-10 16:00:33 +0000
111@@ -1,7 +1,8 @@
112 #include "manager.h"
113 #include "manageradaptor.h"
114
115-int main(int argc, char **argv) {
116+int main(int argc, char **argv)
117+{
118 QCoreApplication app(argc, argv);
119
120 qDBusRegisterMetaType<AccountInfo>();
121
122=== modified file 'src/daemon/manager.cpp'
123--- src/daemon/manager.cpp 2015-02-10 06:24:38 +0000
124+++ src/daemon/manager.cpp 2015-02-10 16:00:33 +0000
125@@ -1,40 +1,48 @@
126-#include "manager.h"
127+#include <QDBusMessage>
128 #include <QDebug>
129-#include <QDBusMessage>
130 #include "aacontext.h"
131-
132-using namespace std;
133+#include "manager.h"
134
135 static const char FORBIDDEN_ERROR[] = "com.ubuntu.OnlineAccounts.Error.Forbidden";
136
137-QDBusArgument &operator<<(QDBusArgument &argument, const AccountInfo &info) {
138- argument.beginStructure();
139- argument << info.account_id << info.details;
140- argument.endStructure();
141- return argument;
142-}
143-
144-const QDBusArgument &operator>>(const QDBusArgument &argument, AccountInfo &info) {
145- argument.beginStructure();
146- argument >> info.account_id >> info.details;
147- argument.endStructure();
148- return argument;
149-}
150-
151-
152-struct Manager::Private {
153- AppArmorContext apparmor;
154+QDBusArgument &operator<<(QDBusArgument &argument, const AccountInfo &info)
155+{
156+ argument.beginStructure();
157+ argument << info.accountId << info.details;
158+ argument.endStructure();
159+ return argument;
160+}
161+
162+const QDBusArgument &operator>>(const QDBusArgument &argument,
163+ AccountInfo &info)
164+{
165+ argument.beginStructure();
166+ argument >> info.accountId >> info.details;
167+ argument.endStructure();
168+ return argument;
169+}
170+
171+class ManagerPrivate {
172+public:
173+ AppArmorContext m_apparmor;
174 };
175
176-Manager::Manager(QObject *parent)
177- : QObject(parent), p(new Private) {
178-}
179-
180-Manager::~Manager() {
181-}
182-
183-bool Manager::canAccess(const QString &service_id) {
184- QString context = p->apparmor.getPeerSecurityContext(connection(), message());
185+Manager::Manager(QObject *parent):
186+ QObject(parent),
187+ d_ptr(new ManagerPrivate)
188+{
189+}
190+
191+Manager::~Manager()
192+{
193+}
194+
195+bool Manager::canAccess(const QString &serviceId)
196+{
197+ Q_D(Manager);
198+
199+ QString context = d->m_apparmor.getPeerSecurityContext(connection(),
200+ message());
201 // Could not determine peer's AppArmor context, so deny access
202 if (context.isEmpty()) {
203 return false;
204@@ -55,51 +63,56 @@
205 // Do the same on the service ID: we are only dealing with
206 // confined apps at this point, so only $pkgname prefixed
207 // services are accessible.
208- pos = service_id.indexOf('_');
209+ pos = serviceId.indexOf('_');
210 if (pos < 0) {
211 return false;
212 }
213- return service_id.left(pos) == pkgname;
214-}
215-
216-bool Manager::checkAccess(const QString &service_id) {
217- bool has_access = canAccess(service_id);
218- if (!has_access) {
219- sendErrorReply(FORBIDDEN_ERROR, QString("Access to service ID %1 forbidden").arg(service_id));
220- }
221- return has_access;
222-}
223-
224-QList<AccountInfo> Manager::GetAccounts(const QStringList &service_ids) {
225- for (const auto &service_id : service_ids) {
226- if (!checkAccess(service_id)) {
227- return QList<AccountInfo>();
228- }
229- }
230-
231- return QList<AccountInfo>({AccountInfo(0, QVariantMap())});
232-}
233-
234-AccountInfo Manager::GetAccountInfo(const QString &service_id, uint account_id) {
235- if (!checkAccess(service_id)) {
236- return AccountInfo();
237- }
238-
239- return AccountInfo(account_id, QVariantMap());
240-}
241-
242-QVariantMap Manager::Authenticate(const QString &service_id, uint account_id, bool interactive, bool invalidate) {
243- if (!checkAccess(service_id)) {
244+ return serviceId.left(pos) == pkgname;
245+}
246+
247+bool Manager::checkAccess(const QString &serviceId)
248+{
249+ bool hasAccess = canAccess(serviceId);
250+ if (!hasAccess) {
251+ sendErrorReply(FORBIDDEN_ERROR,
252+ QString("Access to service ID %1 forbidden").arg(serviceId));
253+ }
254+ return hasAccess;
255+}
256+
257+QList<AccountInfo> Manager::GetAccounts(const QVariantMap &filters)
258+{
259+ Q_UNUSED(filters);
260+
261+ return QList<AccountInfo>();
262+}
263+
264+QVariantMap Manager::Authenticate(quint32 accountId, const QString &serviceId,
265+ bool interactive, bool invalidate,
266+ const QVariantMap &parameters)
267+{
268+ Q_UNUSED(accountId);
269+ Q_UNUSED(interactive);
270+ Q_UNUSED(invalidate);
271+ Q_UNUSED(parameters);
272+
273+ if (!checkAccess(serviceId)) {
274 return QVariantMap();
275 }
276
277 return QVariantMap();
278 }
279
280-AccountInfo Manager::Register(const QString &service_id, QVariantMap &credentials) {
281- if (!checkAccess(service_id)) {
282+AccountInfo Manager::RequestAccess(const QString &serviceId,
283+ const QVariantMap &parameters,
284+ QVariantMap &credentials)
285+{
286+ Q_UNUSED(parameters);
287+
288+ if (!checkAccess(serviceId)) {
289 return AccountInfo();
290 }
291
292+ credentials = QVariantMap();
293 return AccountInfo();
294 }
295
296=== modified file 'src/daemon/manager.h'
297--- src/daemon/manager.h 2015-02-10 06:24:38 +0000
298+++ src/daemon/manager.h 2015-02-10 16:00:33 +0000
299@@ -1,50 +1,54 @@
300-
301 #ifndef MANAGER_H
302 #define MANAGER_H
303
304-#include <memory>
305+#include <QDBusArgument>
306+#include <QDBusContext>
307 #include <QList>
308 #include <QObject>
309 #include <QVariantMap>
310-#include <QDBusArgument>
311-#include <QDBusContext>
312
313 struct AccountInfo {
314- uint account_id = 0;
315+ quint32 accountId;
316 QVariantMap details;
317
318- AccountInfo() {}
319- AccountInfo(uint account_id, const QVariantMap &details)
320- : account_id(account_id), details(details) {}
321-
322+ AccountInfo(): accountId(0) {}
323+ AccountInfo(uint accountId, const QVariantMap &details):
324+ accountId(accountId), details(details) {}
325 };
326 Q_DECLARE_METATYPE(AccountInfo)
327
328 QDBusArgument &operator<<(QDBusArgument &argument, const AccountInfo &info);
329-const QDBusArgument &operator>>(const QDBusArgument &argument, AccountInfo &info);
330+const QDBusArgument &operator>>(const QDBusArgument &argument,
331+ AccountInfo &info);
332
333-class Manager : public QObject, protected QDBusContext {
334+class ManagerPrivate;
335+class Manager: public QObject, protected QDBusContext
336+{
337 Q_OBJECT
338- struct Private;
339+
340 public:
341- explicit Manager(QObject *parent=nullptr);
342+ explicit Manager(QObject *parent = 0);
343 ~Manager();
344
345 public Q_SLOTS:
346- QList<AccountInfo> GetAccounts(const QStringList &service_ids);
347- AccountInfo GetAccountInfo(const QString &service_id, uint account_id);
348- QVariantMap Authenticate(const QString &service_id, uint account_id, bool interactive, bool invalidate);
349- AccountInfo Register(const QString &service_id, QVariantMap &credentials);
350+ QList<AccountInfo> GetAccounts(const QVariantMap &filters);
351+ QVariantMap Authenticate(quint32 accountId, const QString &serviceId,
352+ bool interactive, bool invalidate,
353+ const QVariantMap &parameters);
354+ AccountInfo RequestAccess(const QString &serviceId,
355+ const QVariantMap &parameters,
356+ QVariantMap &credentials);
357
358 Q_SIGNALS:
359- void AccountChanged(const QString &service_id, uint account_id, bool enabled);
360- void CredentialsChanged(const QString &service_id, uint account_id);
361+ void AccountChanged(AccountInfo accountInfo);
362
363 private:
364- bool canAccess(const QString &service_id);
365- bool checkAccess(const QString &service_id);
366+ bool canAccess(const QString &serviceId);
367+ bool checkAccess(const QString &serviceId);
368 QString getPeerSecurityContext();
369- std::unique_ptr<Private> p;
370+
371+ Q_DECLARE_PRIVATE(Manager)
372+ ManagerPrivate *d_ptr;
373 };
374
375 #endif
376
377=== modified file 'src/daemon/manager.xml'
378--- src/daemon/manager.xml 2015-02-10 07:33:36 +0000
379+++ src/daemon/manager.xml 2015-02-10 16:00:33 +0000
380@@ -5,27 +5,18 @@
381 <interface name="com.ubuntu.OnlineAccounts.Manager">
382
383 <!--
384- GetAccounts: returns a list containing account information for
385- accounts that provide one of a list of service IDs.
386+ GetAccounts: returns a list of account IDs that satisfy the given
387+ filters.
388 -->
389 <method name="GetAccounts">
390- <arg name="service_ids" type="as" direction="in" />
391+ <arg name="filters" type="a{sv}" direction="in" />
392 <arg name="accounts" type="a(ua{sv})" direction="out" />
393+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
394 <annotation name="org.qtproject.QtDBus.QtTypeName.Out0"
395 value="QList&lt;AccountInfo&gt;"/>
396 </method>
397
398 <!--
399- GetAccountInfo: return information about a given account ID
400- -->
401- <method name="GetAccountInfo">
402- <arg name="service_id" type="s" direction="in" />
403- <arg name="account_id" type="u" direction="in" />
404- <arg name="details" type="(ua{sv})" direction="out" />
405- <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="AccountInfo"/>
406- </method>
407-
408- <!--
409 Authenticate: request authentication credentials for the given
410 account ID in the context of a particualr service.
411
412@@ -38,54 +29,39 @@
413 provider.
414 -->
415 <method name="Authenticate">
416- <arg name="service_id" type="s" direction="in" />
417- <arg name="account_id" type="u" direction="in" />
418+ <arg name="accountId" type="u" direction="in" />
419+ <arg name="serviceId" type="s" direction="in" />
420 <arg name="interactive" type="b" direction="in" />
421 <arg name="invalidate" type="b" direction="in" />
422- <!-- <arg name="reply_socket" type="h" direction="in" /> -->
423+ <arg name="parameters" type="a{sv}" direction="in" />
424 <arg name="credentials" type="a{sv}" direction="out" />
425+ <annotation name="org.qtproject.QtDBus.QtTypeName.In4" value="QVariantMap"/>
426 <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
427 </method>
428
429 <!--
430- Register: register a new account for use with the given
431+ RequestAccess: register a new account for use with the given
432 service.
433 -->
434- <method name="Register">
435- <arg name="service_id" type="s" direction="in" />
436- <!-- <arg name="reply_socket" type="h" direction="in" /> -->
437+ <method name="RequestAccess">
438+ <arg name="serviceId" type="s" direction="in" />
439+ <arg name="parameters" type="a{sv}" direction="in" />
440 <arg name="account" type="(ua{sv})" direction="out" />
441+ <arg name="credentials" type="a{sv}" direction="out" />
442+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
443 <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="AccountInfo"/>
444- <arg name="credentials" type="a{sv}" direction="out" />
445 <annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
446 </method>
447
448 <!--
449 AccountChanged: emitted when account details are changed.
450-
451- This signal will be emitted when new accounts are enabled, and
452- when existing accounts are disabled. Clients can detect these
453- cases by checking the "enabled" flag and comparing the account
454- ID with the list of accounts they currently know about.
455-
456- The actual changed account details can be retrieved with
457- GetAccountInfo().
458 -->
459 <signal name="AccountChanged">
460- <arg name="service_id" type="s" />
461- <arg name="account_id" type="u" />
462- <arg name="enabled" type="b" />
463- </signal>
464-
465- <!--
466- CredentialsChanged: emitted when the credentials for the given
467- service ID on the given account change.
468-
469- The new credentials can be retrieved with Authenticate().
470- -->
471- <signal name="CredentialsChanged">
472- <arg name="service_id" type="s" />
473- <arg name="account_id" type="u" />
474+ <!-- the dictionary ontains a changeType key, type "u", whose value is
475+ enum { enabled, disabled, changed }
476+ -->
477+ <arg name="account" type="(ua{sv})" />
478+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="AccountInfo"/>
479 </signal>
480
481 </interface>

Subscribers

People subscribed via source and target branches