Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-keyring.c
Go to the documentation of this file.
1 /* ev-keyring.c
2  * this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * 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, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "config.h"
22 
23 #include <glib/gi18n.h>
24 
25 #include "ev-keyring.h"
26 
27 #ifdef WITH_KEYRING
28 #include <libsecret/secret.h>
29 
30 static const SecretSchema doc_password_schema = {
31  "org.gnome.Evince.Document",
32  SECRET_SCHEMA_DONT_MATCH_NAME,
33  {
34  { "type", SECRET_SCHEMA_ATTRIBUTE_STRING },
35  { "uri", SECRET_SCHEMA_ATTRIBUTE_STRING },
36  { NULL, 0 }
37  }
38 };
39 const SecretSchema *EV_DOCUMENT_PASSWORD_SCHEMA = &doc_password_schema;
40 #endif /* WITH_KEYRING */
41 
42 gboolean
44 {
45 #ifdef WITH_KEYRING
46  return TRUE;
47 #else
48  return FALSE;
49 #endif
50 }
51 
52 gchar *
53 ev_keyring_lookup_password (const gchar *uri)
54 {
55 #ifdef WITH_KEYRING
56  g_return_val_if_fail (uri != NULL, NULL);
57 
58  return secret_password_lookup_sync (EV_DOCUMENT_PASSWORD_SCHEMA,
59  NULL, NULL,
60  "type", "document_password",
61  "uri", uri,
62  NULL);
63 #else
64  return NULL;
65 #endif /* WITH_KEYRING */
66 }
67 
68 gboolean
69 ev_keyring_save_password (const gchar *uri,
70  const gchar *password,
71  GPasswordSave flags)
72 {
73 #ifdef WITH_KEYRING
74  const gchar *keyring;
75  gchar *name;
76  gchar *unescaped_uri;
77  gboolean retval;
78 
79  g_return_val_if_fail (uri != NULL, FALSE);
80 
81  if (flags == G_PASSWORD_SAVE_NEVER)
82  return FALSE;
83 
84  keyring = (flags == G_PASSWORD_SAVE_FOR_SESSION) ? SECRET_COLLECTION_SESSION : NULL;
85  unescaped_uri = g_uri_unescape_string (uri, NULL);
86  name = g_strdup_printf (_("Password for document %s"), unescaped_uri);
87  g_free (unescaped_uri);
88 
89  retval = secret_password_store_sync (EV_DOCUMENT_PASSWORD_SCHEMA, keyring,
90  name, password, NULL, NULL,
91  "type", "document_password",
92  "uri", uri,
93  NULL);
94  g_free (name);
95 
96  return retval;
97 #else
98  return FALSE;
99 #endif /* WITH_KEYRING */
100 }