Add authentication token support for wayland windos
authorLasse Holmstedt <lasse.holmstedt@nokia.com>
Wed, 25 May 2011 10:55:26 +0000 (12:55 +0200)
committerLasse Holmstedt <lasse.holmstedt@nokia.com>
Wed, 25 May 2011 12:53:49 +0000 (14:53 +0200)
For compositors that support it, the wayland clients can associate themselves
with an auth token which is transmitted by the windowmanager protocol
extension.

Reviewed-by: Samuel Rødal
src/qt-compositor/wayland_wrapper/wlcompositor.cpp
src/qt-compositor/wayland_wrapper/wlsurface.cpp
src/qt-compositor/wayland_wrapper/wlsurface.h
src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-protocol.c
src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-server-protocol.h
src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp
src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h

index 8ddcbee..b95eea8 100644 (file)
@@ -241,9 +241,13 @@ void Compositor::createSurface(struct wl_client *client, int id)
     addClientResource(client, &surface->base()->resource, id, &wl_surface_interface,
             &surface_interface, destroy_surface);
 
-    quint32 processId = m_windowManagerWaylandProtocol->pidForClient(client);
-    // if there is no PID, the client does not support the protocol.
-    surface->setProcessId(processId);
+    WaylandManagedClient *managedClient = m_windowManagerWaylandProtocol->managedClient(client);
+    if (managedClient) {
+        // if there is no PID, the client does not support the protocol.
+        surface->setProcessId(managedClient->processId());
+        surface->setAuthenticationToken(managedClient->authenticationToken());
+    }
+
     m_qt_compositor->surfaceCreated(surface->handle());
 
     QList<struct wl_client *> prevClientList = clients();
index 0fb93fc..76346a0 100644 (file)
@@ -110,6 +110,7 @@ public:
     bool textureCreatedForBuffer;
     wl_buffer *directRenderBuffer;
     qint64 processId;
+    QByteArray authenticationToken;
 
 private:
     struct wl_buffer *surfaceBuffer;
@@ -313,6 +314,18 @@ void Surface::setProcessId(qint64 processId)
     d->processId = processId;
 }
 
+QByteArray Surface::authenticationToken() const
+{
+    Q_D(const Surface);
+    return d->authenticationToken;
+}
+
+void Surface::setAuthenticationToken(const QByteArray &authenticationToken)
+{
+    Q_D(Surface);
+    d->authenticationToken = authenticationToken;
+}
+
 uint32_t toWaylandButton(Qt::MouseButton button)
 {
     switch (button) {
index ff345d1..73f19fd 100644 (file)
@@ -100,6 +100,9 @@ public:
     wl_client *clientHandle() const;
     qint64 processId() const;
     void setProcessId(qint64 processId);
+    QByteArray authenticationToken() const;
+    void setAuthenticationToken(const QByteArray &authenticationToken);
+
     void setSurfaceCreationFinished(bool isCreated);
 
 protected:
index 48049d8..b753b16 100644 (file)
@@ -26,7 +26,8 @@
 #include "wayland-util.h"
 
 static const struct wl_message wl_windowmanager_requests[] = {
-        { "map_client_to_process", "u", NULL },
+        { "map_client_to_process", "u" },
+        { "authenticate_with_token", "s" },
 };
 
 WL_EXPORT const struct wl_interface wl_windowmanager_interface = {
@@ -34,3 +35,4 @@ WL_EXPORT const struct wl_interface wl_windowmanager_interface = {
         ARRAY_LENGTH(wl_windowmanager_requests), wl_windowmanager_requests,
         0, NULL,
 };
+
index bde9d97..8738146 100644 (file)
@@ -40,8 +40,11 @@ extern const struct wl_interface wl_windowmanager_interface;
 
 struct wl_windowmanager_interface {
         void (*map_client_to_process)(struct wl_client *client,
-                                      struct wl_windowmanager *wl_windowmanager,
+                                      struct wl_windowmanager *windowmanager,
                                       uint32_t processid);
+        void (*authenticate_with_token)(struct wl_client *client,
+                                        struct wl_windowmanager *windowmanager,
+                                        const char *wl_authentication_token);
 };
 
 #ifdef  __cplusplus
index 3f19b3d..5783959 100644 (file)
@@ -66,6 +66,11 @@ public:
         WindowManagerServerIntegration::instance()->mapClientToProcess(client, processId);
     }
 
+    void authenticateWithToken(wl_client *client, const char *authenticationToken)
+    {
+        WindowManagerServerIntegration::instance()->authenticateWithToken(client, authenticationToken);
+    }
+
 };
 
 void map_client_to_process(wl_client *client, struct wl_windowmanager *windowMgr, uint32_t processId)
@@ -73,8 +78,14 @@ void map_client_to_process(wl_client *client, struct wl_windowmanager *windowMgr
     reinterpret_cast<WindowManagerObject *>(windowMgr)->mapClientToProcess(client, processId);
 }
 
+void authenticate_with_token(wl_client *client, struct wl_windowmanager *windowMgr, const char *wl_authentication_token)
+{
+    reinterpret_cast<WindowManagerObject *>(windowMgr)->authenticateWithToken(client, wl_authentication_token);
+}
+
 const static struct wl_windowmanager_interface windowmanager_interface = {
-    map_client_to_process
+    map_client_to_process,
+    authenticate_with_token
 };
 
 WindowManagerServerIntegration *WindowManagerServerIntegration::m_instance = 0;
@@ -94,22 +105,50 @@ void WindowManagerServerIntegration::initialize(Wayland::Display *waylandDisplay
 
 void WindowManagerServerIntegration::removeClient(wl_client *client)
 {
-    m_clientToProcessId.remove(client);
+    WaylandManagedClient *managedClient = m_managedClients.take(client);
+    delete managedClient;
 }
 
 void WindowManagerServerIntegration::mapClientToProcess(wl_client *client, uint32_t processId)
 {
-    m_clientToProcessId.insert(client, processId);
-    emit clientMappedToProcess(client, processId);
+    WaylandManagedClient *managedClient = m_managedClients.value(client, new WaylandManagedClient);
+    managedClient->m_processId = processId;
+    m_managedClients.insert(client, managedClient);
 }
 
+void WindowManagerServerIntegration::authenticateWithToken(wl_client *client, const char *token)
+{
+    WaylandManagedClient *managedClient = m_managedClients.value(client, new WaylandManagedClient);
+    managedClient->m_authenticationToken = QByteArray(token);
+    m_managedClients.insert(client, managedClient);
+}
 
-qint64 WindowManagerServerIntegration::pidForClient(wl_client *client) const
+WaylandManagedClient *WindowManagerServerIntegration::managedClient(wl_client *client) const
 {
-    return m_clientToProcessId.value(client, 0);
+    return m_managedClients.value(client, 0);
 }
 
 WindowManagerServerIntegration *WindowManagerServerIntegration::instance()
 {
     return m_instance;
 }
+
+/// ///
+/// / WaylandManagedClient
+/// ///
+
+WaylandManagedClient::WaylandManagedClient()
+    : m_processId(0)
+{
+
+}
+
+qint64 WaylandManagedClient::processId() const
+{
+    return m_processId;
+}
+
+QByteArray WaylandManagedClient::authenticationToken() const
+{
+    return m_authenticationToken;
+}
index e198c44..b3e90af 100644 (file)
@@ -53,6 +53,7 @@
 struct wl_client;
 
 class WindowManagerObject;
+class WaylandManagedClient;
 
 class WindowManagerServerIntegration : public QObject
 {
@@ -63,16 +64,14 @@ public:
     void initialize(Wayland::Display *waylandDisplay);
     void removeClient(wl_client *client);
 
-    qint64 pidForClient(wl_client *client) const;
-
-signals:
-    void clientMappedToProcess(wl_client *client, quint32 processId);
+    WaylandManagedClient *managedClient(wl_client *client) const;
 
 private:
     void mapClientToProcess(wl_client *client, uint32_t processId);
+    void authenticateWithToken(wl_client *client, const char *token);
 
 private:
-    QMap<wl_client*, qint64> m_clientToProcessId;
+    QMap<wl_client*, WaylandManagedClient*> m_managedClients;
     static WindowManagerServerIntegration *m_instance;
 
     WindowManagerObject *m_windowManagerObject;
@@ -80,4 +79,18 @@ private:
     friend class WindowManagerObject;
 };
 
+class WaylandManagedClient
+{
+public:
+    WaylandManagedClient();
+    qint64 processId() const;
+    QByteArray authenticationToken() const;
+
+private:
+    qint64 m_processId;
+    QByteArray m_authenticationToken;
+
+    friend class WindowManagerServerIntegration;
+};
+
 #endif // WAYLANDWINDOWMANAGERINTEGRATION_H