1 /* libsecret - GLib wrapper for Secret Service
2  *
3  * Copyright 2019 Red Hat, Inc.
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
7  * by the Free Software Foundation; either version 2.1 of the licence or (at
8  * your option) any later version.
9  *
10  * See the included COPYING file for more information.
11  *
12  * Author: Daiki Ueno
13  */
14 
15 #if !defined (__SECRET_INSIDE_HEADER__) && !defined (SECRET_COMPILATION)
16 #error "Only <libsecret/secret.h> can be included directly."
17 #endif
18 
19 #ifndef __SECRET_BACKEND_H__
20 #define __SECRET_BACKEND_H__
21 
22 #include <glib-object.h>
23 #include "secret-schema.h"
24 #include "secret-service.h"
25 #include "secret-value.h"
26 
27 G_BEGIN_DECLS
28 
29 typedef enum {
30         SECRET_BACKEND_NONE = SECRET_SERVICE_NONE,
31         SECRET_BACKEND_OPEN_SESSION = SECRET_SERVICE_OPEN_SESSION,
32         SECRET_BACKEND_LOAD_COLLECTIONS = SECRET_SERVICE_LOAD_COLLECTIONS,
33 } SecretBackendFlags;
34 
35 #define SECRET_TYPE_BACKEND secret_backend_get_type ()
36 G_DECLARE_INTERFACE (SecretBackend, secret_backend, SECRET, BACKEND, GObject)
37 
38 struct _SecretBackendInterface
39 {
40         GTypeInterface parent_iface;
41 
42         void         (*ensure_for_flags)        (SecretBackend *self,
43                                                  SecretBackendFlags flags,
44 						 GCancellable *cancellable,
45 						 GAsyncReadyCallback callback,
46                                                  gpointer user_data);
47         gboolean     (*ensure_for_flags_finish) (SecretBackend *self,
48                                                  GAsyncResult *result,
49                                                  GError **error);
50 
51         void         (*store)                   (SecretBackend *self,
52                                                  const SecretSchema *schema,
53                                                  GHashTable *attributes,
54                                                  const gchar *collection,
55                                                  const gchar *label,
56                                                  SecretValue *value,
57                                                  GCancellable *cancellable,
58                                                  GAsyncReadyCallback callback,
59                                                  gpointer user_data);
60         gboolean     (*store_finish)            (SecretBackend *self,
61                                                  GAsyncResult *result,
62                                                  GError **error);
63 
64         void         (*lookup)                  (SecretBackend *self,
65                                                  const SecretSchema *schema,
66                                                  GHashTable *attributes,
67                                                  GCancellable *cancellable,
68                                                  GAsyncReadyCallback callback,
69                                                  gpointer user_data);
70         SecretValue *(*lookup_finish)           (SecretBackend *self,
71                                                  GAsyncResult *result,
72                                                  GError **error);
73 
74         void         (*clear)                   (SecretBackend *self,
75                                                  const SecretSchema *schema,
76                                                  GHashTable *attributes,
77                                                  GCancellable *cancellable,
78                                                  GAsyncReadyCallback callback,
79                                                  gpointer user_data);
80         gboolean     (*clear_finish)            (SecretBackend *self,
81                                                  GAsyncResult *result,
82                                                  GError **error);
83 
84         void         (*search)                  (SecretBackend *self,
85                                                  const SecretSchema *schema,
86                                                  GHashTable *attributes,
87                                                  SecretSearchFlags flags,
88                                                  GCancellable *cancellable,
89                                                  GAsyncReadyCallback callback,
90                                                  gpointer user_data);
91         GList *      (*search_finish)           (SecretBackend *self,
92                                                  GAsyncResult *result,
93                                                  GError **error);
94 };
95 
96 #define SECRET_BACKEND_EXTENSION_POINT_NAME "secret-backend"
97 
98 void           _secret_backend_ensure_extension_point
99                                          (void);
100 void           _secret_backend_uncache_instance
101                                          (void);
102 
103 void           secret_backend_get        (SecretBackendFlags flags,
104                                           GCancellable *cancellable,
105                                           GAsyncReadyCallback callback,
106                                           gpointer user_data);
107 
108 SecretBackend *secret_backend_get_finish (GAsyncResult *result,
109                                           GError **error);
110 
111 G_END_DECLS
112 
113 #endif /* __SECRET_BACKEND_H__ */
114