libpurple/purplecredentialmanager.c

Mon, 11 Jan 2021 01:51:14 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 11 Jan 2021 01:51:14 -0600
changeset 40697
81f81f5d2f39
parent 40684
a0c11a532ee7
child 40730
12b38cca63d7
permissions
-rw-r--r--

Split PurpleProtocolChat to its own file and clean up the API.

Testing Done:
* Compiled and tested bonjour (not affected) and irc locally.
* Built and verified the docs.
* verified `ninja pidgin-pot` was successful.

Bugs closed: 17457

Reviewed at https://reviews.imfreedom.org/r/406/

40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 * (at your option) any later version.
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 * GNU General Public License for more details.
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * along with this program; if not, see <https://www.gnu.org/licenses/>.
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 */
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #include <glib/gi18n-lib.h>
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 #include "purplecredentialmanager.h"
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 #include "purpleprivate.h"
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 enum {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 SIG_PROVIDER_REGISTERED,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 SIG_PROVIDER_UNREGISTERED,
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
27 SIG_ACTIVE_PROVIDER_CHANGED,
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 N_SIGNALS,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 };
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 static guint signals[N_SIGNALS] = {0, };
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 typedef struct {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 GHashTable *providers;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 PurpleCredentialProvider *active_provider;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 } PurpleCredentialManagerPrivate;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 G_DEFINE_TYPE_WITH_PRIVATE(PurpleCredentialManager, purple_credential_manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 G_TYPE_OBJECT);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 static PurpleCredentialManager *default_manager = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 /******************************************************************************
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 * Async Callbacks
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 *****************************************************************************/
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 static void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 purple_credential_manager_read_password_callback(GObject *obj,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 GAsyncResult *res,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 gpointer data)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 PurpleCredentialProvider *provider = PURPLE_CREDENTIAL_PROVIDER(obj);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 GError *error = NULL;
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
53 GTask *task = G_TASK(data);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 gchar *password = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
56 password = purple_credential_provider_read_password_finish(provider, res,
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 &error);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 if(error != NULL) {
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
60 g_task_return_error(task, error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 } else {
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
62 g_task_return_pointer(task, password, g_free);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 /* Clean up our initial reference to the task. */
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
66 g_object_unref(G_OBJECT(task));
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 static void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 purple_credential_manager_write_password_callback(GObject *obj,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 GAsyncResult *res,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 gpointer data)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 PurpleCredentialProvider *provider = PURPLE_CREDENTIAL_PROVIDER(obj);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 GError *error = NULL;
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
76 GTask *task = G_TASK(data);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 gboolean ret = FALSE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
79 ret = purple_credential_provider_write_password_finish(provider, res,
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
80 &error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 if(error != NULL) {
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
83 g_task_return_error(task, error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 } else {
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
85 g_task_return_boolean(task, ret);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 /* Clean up our initial reference to the task. */
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
89 g_object_unref(G_OBJECT(task));
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 static void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 purple_credential_manager_clear_password_callback(GObject *obj,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 GAsyncResult *res,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 gpointer data)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 PurpleCredentialProvider *provider = PURPLE_CREDENTIAL_PROVIDER(obj);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 GError *error = NULL;
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
99 GTask *task = G_TASK(data);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 gboolean ret = FALSE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
102 ret = purple_credential_provider_clear_password_finish(provider, res,
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
103 &error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 if(error != NULL) {
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
106 g_task_return_error(task, error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 } else {
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
108 g_task_return_boolean(task, ret);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 /* Clean up our initial reference to the task. */
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
112 g_object_unref(G_OBJECT(task));
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 /******************************************************************************
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 * GObject Implementation
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 *****************************************************************************/
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 static void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 purple_credential_manager_finalize(GObject *obj) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 PurpleCredentialManager *manager = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 manager = PURPLE_CREDENTIAL_MANAGER(obj);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 g_clear_pointer(&priv->providers, g_hash_table_destroy);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 g_clear_object(&priv->active_provider);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 G_OBJECT_CLASS(purple_credential_manager_parent_class)->finalize(obj);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 static void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 purple_credential_manager_init(PurpleCredentialManager *manager) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 priv->providers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 g_object_unref);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 static void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 purple_credential_manager_class_init(PurpleCredentialManagerClass *klass) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 obj_class->finalize = purple_credential_manager_finalize;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 /**
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150 * PurpleCredentialManager::provider-registered:
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 * @manager: The #PurpleCredentialManager instance.
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 * @provider: The #PurpleCredentialProvider that was registered.
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 * Emitted after @provider has been registered in @manager.
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
155 *
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
156 * Since: 3.0.0
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 */
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 signals[SIG_PROVIDER_REGISTERED] = g_signal_new(
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 "provider-registered",
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160 G_OBJECT_CLASS_TYPE(klass),
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 G_SIGNAL_RUN_LAST,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 G_STRUCT_OFFSET(PurpleCredentialManagerClass, provider_registered),
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 NULL,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 NULL,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 NULL,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 G_TYPE_NONE,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 1,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 PURPLE_TYPE_CREDENTIAL_PROVIDER);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 /**
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 * PurpleCredentialManager::provider-unregistered:
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 * @manager: The #PurpleCredentialManager instance.
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 * @provider: The #PurpleCredentialProvider that was unregistered.
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 * Emitted after @provider has been unregistered from @manager.
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
176 *
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
177 * Since: 3.0.0
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 */
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 signals[SIG_PROVIDER_UNREGISTERED] = g_signal_new(
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 "provider-unregistered",
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 G_OBJECT_CLASS_TYPE(klass),
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 G_SIGNAL_RUN_LAST,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 G_STRUCT_OFFSET(PurpleCredentialManagerClass, provider_unregistered),
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 NULL,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 NULL,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 NULL,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 G_TYPE_NONE,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 1,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 PURPLE_TYPE_CREDENTIAL_PROVIDER);
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
190
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
191 /**
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
192 * PurpleCredentialManager::active-provider-changed:
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
193 * @manager: The #PurpleCredentialManager instance.
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
194 * @old: The #PurpleCredentialProvider that was previously active.
40680
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
195 * @current: The #PurpleCredentialProvider that is now currently active.
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
196 *
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
197 * Emitted after @provider has become the active provider for @manager.
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
198 *
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
199 * Since: 3.0.0
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
200 */
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
201 signals[SIG_ACTIVE_PROVIDER_CHANGED] = g_signal_new(
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
202 "active-provider-changed",
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
203 G_OBJECT_CLASS_TYPE(klass),
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
204 G_SIGNAL_RUN_LAST,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
205 G_STRUCT_OFFSET(PurpleCredentialManagerClass, active_provider_changed),
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
206 NULL,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
207 NULL,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
208 NULL,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
209 G_TYPE_NONE,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
210 2,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
211 PURPLE_TYPE_CREDENTIAL_PROVIDER,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
212 PURPLE_TYPE_CREDENTIAL_PROVIDER);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 /******************************************************************************
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 * Private API
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 *****************************************************************************/
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 purple_credential_manager_startup(void) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220 if(default_manager == NULL) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 default_manager = g_object_new(PURPLE_TYPE_CREDENTIAL_MANAGER, NULL);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225 void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 purple_credential_manager_shutdown(void) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 g_clear_object(&default_manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 /******************************************************************************
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 * Public API
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 *****************************************************************************/
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 PurpleCredentialManager *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 purple_credential_manager_get_default(void) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 return default_manager;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 gboolean
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 purple_credential_manager_register_provider(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 PurpleCredentialProvider *provider,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 const gchar *id = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_PROVIDER(provider), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 if(!purple_credential_provider_is_valid(provider, error)) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 /* purple_credential_provider_is_valid sets the error on failure. */
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 return FALSE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 id = purple_credential_provider_get_id(provider);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258 if(g_hash_table_lookup(priv->providers, id) != NULL) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 g_set_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260 _("provider %s is already registered"), id);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 return FALSE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 g_hash_table_insert(priv->providers, g_strdup(id), g_object_ref(provider));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 g_signal_emit(G_OBJECT(manager), signals[SIG_PROVIDER_REGISTERED], 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 provider);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 return TRUE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 gboolean
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274 purple_credential_manager_unregister_provider(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 PurpleCredentialProvider *provider,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 const gchar *id = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_PROVIDER(provider), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 id = purple_credential_provider_get_id(provider);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 if(provider == priv->active_provider) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288 g_set_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289 _("provider %s is currently in use"), id);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 return FALSE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294 if(g_hash_table_remove(priv->providers, id)) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
295 g_signal_emit(G_OBJECT(manager), signals[SIG_PROVIDER_UNREGISTERED], 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 provider);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298 return TRUE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 g_set_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 _("provider %s is not registered"), id);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 return FALSE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 gboolean
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 purple_credential_manager_set_active_provider(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 const gchar *id, GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 PurpleCredentialManagerPrivate *priv = NULL;
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
312 PurpleCredentialProvider *old = NULL, *provider = NULL;
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
318 /* First look up the new provider if we're given one. */
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
319 if(id != NULL) {
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
320 provider = g_hash_table_lookup(priv->providers, id);
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
321 if(!PURPLE_IS_CREDENTIAL_PROVIDER(provider)) {
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
322 g_set_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
323 "no credential provider found with id %s", id);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
325 return FALSE;
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
326 }
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
329 if(PURPLE_IS_CREDENTIAL_PROVIDER(priv->active_provider)) {
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
330 old = PURPLE_CREDENTIAL_PROVIDER(g_object_ref(priv->active_provider));
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332
40670
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
333 if(g_set_object(&priv->active_provider, provider)) {
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
334 g_signal_emit(G_OBJECT(manager), signals[SIG_ACTIVE_PROVIDER_CHANGED],
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
335 0, old, priv->active_provider);
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
336 }
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
337
c4665659625a Add an active-provider-changed signal to PurpleCredentialManager
Gary Kramlich <grim@reaperworld.com>
parents: 40583
diff changeset
338 g_clear_object(&old);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 return TRUE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 purple_credential_manager_read_password_async(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 PurpleAccount *account,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 GCancellable *cancellable,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 GAsyncReadyCallback callback,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348 gpointer data)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
349 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 GTask *task = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353 g_return_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 task = g_task_new(manager, cancellable, callback, data);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360 if(priv->active_provider == NULL) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 GError *error = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 error = g_error_new_literal(PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364 _("can not read password, no active "
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 "credential provider"));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
367 g_task_return_error(task, error);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
368
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369 return;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 purple_credential_provider_read_password_async(priv->active_provider,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
373 account,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 cancellable,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
375 purple_credential_manager_read_password_callback,
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
376 task);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379 gchar *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380 purple_credential_manager_read_password_finish(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 GAsyncResult *result,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), NULL);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
386 return g_task_propagate_pointer(G_TASK(result), error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389 void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 purple_credential_manager_write_password_async(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391 PurpleAccount *account,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392 const gchar *password,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 GCancellable *cancellable,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394 GAsyncReadyCallback callback,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395 gpointer data)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
396 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
397 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
398 GTask *task = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
399
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 g_return_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
401 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
404
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
405 task = g_task_new(manager, cancellable, callback, data);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406
40680
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
407 if(!purple_account_get_remember_password(account)) {
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
408 GError *error = NULL;
40684
a0c11a532ee7 Fix some broken unit tests
Gary Kramlich <grim@reaperworld.com>
parents: 40680
diff changeset
409 const gchar *name = purple_account_get_username(account);
40680
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
410
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
411 error = g_error_new(PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
412 _("account \"%s\" is not marked to be stored"),
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
413 name);
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
414
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
415 g_task_return_error(task, error);
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
416
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
417 return;
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
418 }
f9ea6d5e8992 Use PurpleCredentialManager instead of the old keyring api.
Gary Kramlich <grim@reaperworld.com>
parents: 40679
diff changeset
419
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
420 if(priv->active_provider == NULL) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
421 GError *error = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
422
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423 error = g_error_new_literal(PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
424 _("can not write password, no active "
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
425 "credential provider"));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
426
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
427 g_task_return_error(task, error);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
428
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
429 return;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
430 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
431
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
432 purple_credential_provider_write_password_async(priv->active_provider,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
433 account, password,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
434 cancellable,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
435 purple_credential_manager_write_password_callback,
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
436 task);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
437 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
438
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
439 gboolean
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
440 purple_credential_manager_write_password_finish(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
441 GAsyncResult *result,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442 GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
443 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
444 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
445
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
446 return g_task_propagate_boolean(G_TASK(result), error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
447 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
448
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
449 void
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
450 purple_credential_manager_clear_password_async(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
451 PurpleAccount *account,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
452 GCancellable *cancellable,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
453 GAsyncReadyCallback callback,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
454 gpointer data)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
455 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
456 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
457 GTask *task = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
458
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
459 g_return_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
460 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
461
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
462 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
463
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
464 task = g_task_new(manager, cancellable, callback, data);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
465
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
466 if(priv->active_provider == NULL) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
467 GError *error = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
468
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
469 error = g_error_new_literal(PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
470 _("can not clear password, no active "
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
471 "credential provider"));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
472
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
473 g_task_return_error(task, error);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
474
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
475 return;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
476 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
477
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
478 purple_credential_provider_clear_password_async(priv->active_provider,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
479 account,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
480 cancellable,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
481 purple_credential_manager_clear_password_callback,
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
482 task);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
483 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
484
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
485 gboolean
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
486 purple_credential_manager_clear_password_finish(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
487 GAsyncResult *result,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
488 GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
489 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
490 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
491
40679
062a4574af3e Remove the account parameter from purple_credential_provider_*_finish functions.
Gary Kramlich <grim@reaperworld.com>
parents: 40670
diff changeset
492 return g_task_propagate_boolean(G_TASK(result), error);
40583
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
493 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
494
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
495 PurpleRequestFields *
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
496 purple_credential_manager_read_settings(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
497 GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
498 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
499 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
500
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
501 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
502
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
503 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
504
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
505 if(priv->active_provider == NULL) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
506 g_set_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
507 _("can not read settings, no active credential provider"));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
508
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
509 return NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
510 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
511
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
512 return purple_credential_provider_read_settings(priv->active_provider);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
513 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
514
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
515 gboolean
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
516 purple_credential_manager_write_settings(PurpleCredentialManager *manager,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
517 PurpleRequestFields *fields,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
518 GError **error)
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
519 {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
520 PurpleCredentialManagerPrivate *priv = NULL;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
521
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
522 g_return_val_if_fail(PURPLE_IS_CREDENTIAL_MANAGER(manager), FALSE);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
523
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
524 priv = purple_credential_manager_get_instance_private(manager);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
525
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
526 if(priv->active_provider == NULL) {
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
527 g_set_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
528 _("can not write settings, no active credential provider"));
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
529
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
530 return FALSE;
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
531 }
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
532
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
533 return purple_credential_provider_write_settings(priv->active_provider,
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
534 fields);
28964322556c Add the new PurpleCredentialManager API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
535 }

mercurial