1 /*
2  * This file is part of libsecret-d.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/
7  */
8 
9 // generated automatically - do not change
10 // find conversion definition on APILookup.txt
11 
12 
13 module libsecret.Secret;
14 
15 private import gio.AsyncResultIF;
16 private import gio.Cancellable;
17 private import glib.ErrorG;
18 private import glib.GException;
19 private import glib.HashTable;
20 private import glib.Str;
21 private import gobject.ObjectG;
22 private import libsecret.Schema;
23 private import libsecret.c.functions;
24 public  import libsecret.c.types;
25 
26 
27 /** */
28 public struct Secret
29 {
30 
31 	/**
32 	 * Build up a hash table of attribute values.
33 	 *
34 	 * The variable argument list should contain pairs of a) The attribute name as
35 	 * a null-terminated string, followed by b) attribute value, either a character
36 	 * string, an int number, or a gboolean value, as defined in the password
37 	 * @schema. The list of attribtues should be terminated with a %NULL.
38 	 *
39 	 * Params:
40 	 *     schema = the schema for the attributes
41 	 *     va = the attribute keys and values, terminated with %NULL
42 	 *
43 	 * Returns: a new table of
44 	 *     attributes, to be released with g_hash_table_unref()
45 	 */
46 	public static HashTable attributesBuildv(Schema schema, void* va)
47 	{
48 		auto p = secret_attributes_buildv((schema is null) ? null : schema.getSchemaStruct(), va);
49 
50 		if(p is null)
51 		{
52 			return null;
53 		}
54 
55 		return new HashTable(cast(GHashTable*) p, true);
56 	}
57 
58 	/** */
59 	public static GQuark errorGetQuark()
60 	{
61 		return secret_error_get_quark();
62 	}
63 
64 	/**
65 	 * Get a secret storage schema of the given @type.
66 	 *
67 	 * C code may access the schemas (such as %SECRET_SCHEMA_NOTE) directly, but
68 	 * language bindings cannot, and must use this accessor.
69 	 *
70 	 * Params:
71 	 *     type = type of schema to get
72 	 *
73 	 * Returns: schema type
74 	 *
75 	 * Since: 0.18.6
76 	 */
77 	public static Schema getSchema(SecretSchemaType type)
78 	{
79 		auto p = secret_get_schema(type);
80 
81 		if(p is null)
82 		{
83 			return null;
84 		}
85 
86 		return ObjectG.getDObject!(Schema)(cast(SecretSchema*) p);
87 	}
88 
89 	/**
90 	 * Finish an asynchronous operation to remove passwords from the secret
91 	 * service.
92 	 *
93 	 * Params:
94 	 *     result = the asynchronous result passed to the callback
95 	 *
96 	 * Returns: whether any passwords were removed
97 	 *
98 	 * Throws: GException on failure.
99 	 */
100 	public static bool passwordClearFinish(AsyncResultIF result)
101 	{
102 		GError* err = null;
103 
104 		auto p = secret_password_clear_finish((result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
105 
106 		if (err !is null)
107 		{
108 			throw new GException( new ErrorG(err) );
109 		}
110 
111 		return p;
112 	}
113 
114 	/**
115 	 * Remove unlocked matching passwords from the secret service.
116 	 *
117 	 * The @attributes should be a set of key and value string pairs.
118 	 *
119 	 * All unlocked items that match the attributes will be deleted.
120 	 *
121 	 * This method will return immediately and complete asynchronously.
122 	 *
123 	 * Params:
124 	 *     schema = the schema for the attributes
125 	 *     attributes = the attribute keys and values
126 	 *     cancellable = optional cancellation object
127 	 *     callback = called when the operation completes
128 	 *     userData = data to be passed to the callback
129 	 */
130 	public static void passwordClearv(Schema schema, HashTable attributes, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
131 	{
132 		secret_password_clearv((schema is null) ? null : schema.getSchemaStruct(), (attributes is null) ? null : attributes.getHashTableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
133 	}
134 
135 	/**
136 	 * Remove unlocked matching passwords from the secret service.
137 	 *
138 	 * The @attributes should be a set of key and value string pairs.
139 	 *
140 	 * All unlocked items that match the attributes will be deleted.
141 	 *
142 	 * This method may block indefinitely and should not be used in user interface
143 	 * threads.
144 	 *
145 	 * Params:
146 	 *     schema = the schema for the attributes
147 	 *     attributes = the attribute keys and values
148 	 *     cancellable = optional cancellation object
149 	 *
150 	 * Returns: whether any passwords were removed
151 	 *
152 	 * Throws: GException on failure.
153 	 */
154 	public static bool passwordClearvSync(Schema schema, HashTable attributes, Cancellable cancellable)
155 	{
156 		GError* err = null;
157 
158 		auto p = secret_password_clearv_sync((schema is null) ? null : schema.getSchemaStruct(), (attributes is null) ? null : attributes.getHashTableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
159 
160 		if (err !is null)
161 		{
162 			throw new GException( new ErrorG(err) );
163 		}
164 
165 		return p;
166 	}
167 
168 	/**
169 	 * Clear the memory used by a password, and then free it.
170 	 *
171 	 * This function must be used to free nonpageable memory returned by
172 	 * secret_password_lookup_nonpageable_finish(),
173 	 * secret_password_lookup_nonpageable_sync() or
174 	 * secret_password_lookupv_nonpageable_sync().
175 	 *
176 	 * Params:
177 	 *     password = password to free
178 	 */
179 	public static void passwordFree(string password)
180 	{
181 		secret_password_free(Str.toStringz(password));
182 	}
183 
184 	/**
185 	 * Finish an asynchronous operation to lookup a password in the secret service.
186 	 *
187 	 * Params:
188 	 *     result = the asynchronous result passed to the callback
189 	 *
190 	 * Returns: a new password string which should be freed with
191 	 *     secret_password_free() or may be freed with g_free() when done
192 	 *
193 	 * Throws: GException on failure.
194 	 */
195 	public static string passwordLookupFinish(AsyncResultIF result)
196 	{
197 		GError* err = null;
198 
199 		auto retStr = secret_password_lookup_finish((result is null) ? null : result.getAsyncResultStruct(), &err);
200 
201 		if (err !is null)
202 		{
203 			throw new GException( new ErrorG(err) );
204 		}
205 
206 		scope(exit) Str.freeString(retStr);
207 		return Str.toString(retStr);
208 	}
209 
210 	/**
211 	 * Finish an asynchronous operation to lookup a password in the secret service.
212 	 *
213 	 * Params:
214 	 *     result = the asynchronous result passed to the callback
215 	 *
216 	 * Returns: a new password string stored in nonpageable memory
217 	 *     which must be freed with secret_password_free() when done
218 	 *
219 	 * Throws: GException on failure.
220 	 */
221 	public static string passwordLookupNonpageableFinish(AsyncResultIF result)
222 	{
223 		GError* err = null;
224 
225 		auto retStr = secret_password_lookup_nonpageable_finish((result is null) ? null : result.getAsyncResultStruct(), &err);
226 
227 		if (err !is null)
228 		{
229 			throw new GException( new ErrorG(err) );
230 		}
231 
232 		scope(exit) Str.freeString(retStr);
233 		return Str.toString(retStr);
234 	}
235 
236 	/**
237 	 * Lookup a password in the secret service.
238 	 *
239 	 * The @attributes should be a set of key and value string pairs.
240 	 *
241 	 * If no secret is found then %NULL is returned.
242 	 *
243 	 * This method will return immediately and complete asynchronously.
244 	 *
245 	 * Params:
246 	 *     schema = the schema for attributes
247 	 *     attributes = the attribute keys and values
248 	 *     cancellable = optional cancellation object
249 	 *     callback = called when the operation completes
250 	 *     userData = data to be passed to the callback
251 	 */
252 	public static void passwordLookupv(Schema schema, HashTable attributes, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
253 	{
254 		secret_password_lookupv((schema is null) ? null : schema.getSchemaStruct(), (attributes is null) ? null : attributes.getHashTableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
255 	}
256 
257 	/**
258 	 * Lookup a password in the secret service.
259 	 *
260 	 * The @attributes should be a set of key and value string pairs.
261 	 *
262 	 * If no secret is found then %NULL is returned.
263 	 *
264 	 * This method may block indefinitely and should not be used in user interface
265 	 * threads.
266 	 *
267 	 * Params:
268 	 *     schema = the schema for attributes
269 	 *     attributes = the attribute keys and values
270 	 *     cancellable = optional cancellation object
271 	 *
272 	 * Returns: a new password string stored in non pageable memory
273 	 *     which should be freed with secret_password_free() when done
274 	 *
275 	 * Throws: GException on failure.
276 	 */
277 	public static string passwordLookupvNonpageableSync(Schema schema, HashTable attributes, Cancellable cancellable)
278 	{
279 		GError* err = null;
280 
281 		auto retStr = secret_password_lookupv_nonpageable_sync((schema is null) ? null : schema.getSchemaStruct(), (attributes is null) ? null : attributes.getHashTableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
282 
283 		if (err !is null)
284 		{
285 			throw new GException( new ErrorG(err) );
286 		}
287 
288 		scope(exit) Str.freeString(retStr);
289 		return Str.toString(retStr);
290 	}
291 
292 	/**
293 	 * Lookup a password in the secret service.
294 	 *
295 	 * The @attributes should be a set of key and value string pairs.
296 	 *
297 	 * If no secret is found then %NULL is returned.
298 	 *
299 	 * This method may block indefinitely and should not be used in user interface
300 	 * threads.
301 	 *
302 	 * Params:
303 	 *     schema = the schema for attributes
304 	 *     attributes = the attribute keys and values
305 	 *     cancellable = optional cancellation object
306 	 *
307 	 * Returns: a new password string which should be freed with
308 	 *     secret_password_free() or may be freed with g_free() when done
309 	 *
310 	 * Throws: GException on failure.
311 	 */
312 	public static string passwordLookupvSync(Schema schema, HashTable attributes, Cancellable cancellable)
313 	{
314 		GError* err = null;
315 
316 		auto retStr = secret_password_lookupv_sync((schema is null) ? null : schema.getSchemaStruct(), (attributes is null) ? null : attributes.getHashTableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
317 
318 		if (err !is null)
319 		{
320 			throw new GException( new ErrorG(err) );
321 		}
322 
323 		scope(exit) Str.freeString(retStr);
324 		return Str.toString(retStr);
325 	}
326 
327 	/**
328 	 * Finish asynchronous operation to store a password in the secret service.
329 	 *
330 	 * Params:
331 	 *     result = the asynchronous result passed to the callback
332 	 *
333 	 * Returns: whether the storage was successful or not
334 	 *
335 	 * Throws: GException on failure.
336 	 */
337 	public static bool passwordStoreFinish(AsyncResultIF result)
338 	{
339 		GError* err = null;
340 
341 		auto p = secret_password_store_finish((result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
342 
343 		if (err !is null)
344 		{
345 			throw new GException( new ErrorG(err) );
346 		}
347 
348 		return p;
349 	}
350 
351 	/**
352 	 * Store a password in the secret service.
353 	 *
354 	 * The @attributes should be a set of key and value string pairs.
355 	 *
356 	 * If the attributes match a secret item already stored in the collection, then
357 	 * the item will be updated with these new values.
358 	 *
359 	 * If @collection is %NULL, then the default collection will be
360 	 * used. Use #SECRET_COLLECTION_SESSION to store the password in the session
361 	 * collection, which doesn't get stored across login sessions.
362 	 *
363 	 * This method will return immediately and complete asynchronously.
364 	 *
365 	 * Params:
366 	 *     schema = the schema for attributes
367 	 *     attributes = the attribute keys and values
368 	 *     collection = a collection alias, or D-Bus object path of the collection where to store the secret
369 	 *     label = label for the secret
370 	 *     password = the null-terminated password to store
371 	 *     cancellable = optional cancellation object
372 	 *     callback = called when the operation completes
373 	 *     userData = data to be passed to the callback
374 	 */
375 	public static void passwordStorev(Schema schema, HashTable attributes, string collection, string label, string password, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
376 	{
377 		secret_password_storev((schema is null) ? null : schema.getSchemaStruct(), (attributes is null) ? null : attributes.getHashTableStruct(), Str.toStringz(collection), Str.toStringz(label), Str.toStringz(password), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
378 	}
379 
380 	/**
381 	 * Store a password in the secret service.
382 	 *
383 	 * The @attributes should be a set of key and value string pairs.
384 	 *
385 	 * If the attributes match a secret item already stored in the collection, then
386 	 * the item will be updated with these new values.
387 	 *
388 	 * If @collection is %NULL, then the default collection will be
389 	 * used. Use #SECRET_COLLECTION_SESSION to store the password in the session
390 	 * collection, which doesn't get stored across login sessions.
391 	 *
392 	 * This method may block indefinitely and should not be used in user interface
393 	 * threads.
394 	 *
395 	 * Params:
396 	 *     schema = the schema for attributes
397 	 *     attributes = the attribute keys and values
398 	 *     collection = a collection alias, or D-Bus object path of the collection where to store the secret
399 	 *     label = label for the secret
400 	 *     password = the null-terminated password to store
401 	 *     cancellable = optional cancellation object
402 	 *
403 	 * Returns: whether the storage was successful or not
404 	 *
405 	 * Throws: GException on failure.
406 	 */
407 	public static bool passwordStorevSync(Schema schema, HashTable attributes, string collection, string label, string password, Cancellable cancellable)
408 	{
409 		GError* err = null;
410 
411 		auto p = secret_password_storev_sync((schema is null) ? null : schema.getSchemaStruct(), (attributes is null) ? null : attributes.getHashTableStruct(), Str.toStringz(collection), Str.toStringz(label), Str.toStringz(password), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
412 
413 		if (err !is null)
414 		{
415 			throw new GException( new ErrorG(err) );
416 		}
417 
418 		return p;
419 	}
420 
421 	/**
422 	 * Clear the memory used by a password.
423 	 *
424 	 * Params:
425 	 *     password = password to clear
426 	 */
427 	public static void passwordWipe(string password)
428 	{
429 		secret_password_wipe(Str.toStringz(password));
430 	}
431 }