Replace functions which called once with their bodies
[pidgin-git.git] / libpurple / plugins / one_time_password.c
blob66e062024a194559303a81e0b9d44976d3cfdb4e
1 /*
2 * One Time Password support plugin for libpurple
4 * Copyright (C) 2009, Daniel Atallah <datallah@pidgin.im>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program 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.
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
19 * 02111-1301, USA.
21 #include "internal.h"
22 #include <purple.h>
24 #define PLUGIN_ID "core-one_time_password"
25 #define PREF_NAME PLUGIN_ID "_enabled"
27 static void
28 signed_on_cb(PurpleConnection *conn, void *data)
30 PurpleAccount *account = purple_connection_get_account(conn);
32 if (purple_account_get_bool(account, PREF_NAME, FALSE)) {
33 if(purple_account_get_remember_password(account))
34 purple_debug_error("One Time Password",
35 "Unable to enforce one time password for account %s (%s).\n"
36 "Account is set to remember the password.\n",
37 purple_account_get_username(account),
38 purple_account_get_protocol_name(account));
39 else {
41 purple_debug_info("One Time Password", "Clearing password for account %s (%s).\n",
42 purple_account_get_username(account),
43 purple_account_get_protocol_name(account));
45 purple_account_set_password(account, NULL, NULL, NULL);
46 /* TODO: Do we need to somehow clear conn->password ? */
51 static PurplePluginInfo *
52 plugin_query(GError **error)
54 const gchar * const authors[] = {
55 "Daniel Atallah <datallah@pidgin.im>",
56 NULL
59 return purple_plugin_info_new(
60 "id", PLUGIN_ID,
61 "name", N_("One Time Password Support"),
62 "version", DISPLAY_VERSION,
63 "category", N_("Security"),
64 "summary", N_("Enforce that passwords are used only once."),
65 "description", N_("Allows you to enforce on a per-account basis that "
66 "passwords not being saved are only used in a "
67 "single successful connection.\n"
68 "Note: The account password must not be saved for "
69 "this to work."),
70 "authors", authors,
71 "website", PURPLE_WEBSITE,
72 "abi-version", PURPLE_ABI_VERSION,
73 NULL
77 static gboolean
78 plugin_load(PurplePlugin *plugin, GError **error)
80 PurpleProtocol *protocol;
81 PurpleAccountOption *option;
82 GList *list, *l;
84 list = purple_protocols_get_all();
86 /* Register protocol preference. */
87 for (l = list; l != NULL; l = l->next) {
88 protocol = PURPLE_PROTOCOL(l->data);
89 if (protocol != NULL && !(purple_protocol_get_options(protocol) & OPT_PROTO_NO_PASSWORD)) {
90 option = purple_account_option_bool_new(_("One Time Password"),
91 PREF_NAME, FALSE);
92 protocol->account_options = g_list_append(protocol->account_options, option);
95 g_list_free(list);
97 /* Register callback. */
98 purple_signal_connect(purple_connections_get_handle(), "signed-on",
99 plugin, PURPLE_CALLBACK(signed_on_cb), NULL);
101 return TRUE;
104 static gboolean
105 plugin_unload(PurplePlugin *plugin, GError **error)
107 PurpleProtocol *protocol;
108 PurpleAccountOption *option;
109 GList *list, *l, *options;
111 list = purple_protocols_get_all();
113 /* Remove protocol preference. */
114 for (l = list; l != NULL; l = l->next) {
115 protocol = PURPLE_PROTOCOL(l->data);
116 if (protocol != NULL && !(purple_protocol_get_options(protocol) & OPT_PROTO_NO_PASSWORD)) {
117 options = purple_protocol_get_account_options(protocol);
118 while (options != NULL) {
119 option = (PurpleAccountOption *) options->data;
120 if (purple_strequal(PREF_NAME, purple_account_option_get_setting(option))) {
121 protocol->account_options = g_list_delete_link(protocol->account_options, options);
122 purple_account_option_destroy(option);
123 break;
125 options = options->next;
129 g_list_free(list);
131 /* Callback will be automagically unregistered */
133 return TRUE;
136 PURPLE_PLUGIN_INIT(one_time_password, plugin_query, plugin_load, plugin_unload);