3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 struct _PurpleE2eeState
28 PurpleE2eeProvider
*provider
;
36 struct _PurpleE2eeProvider
39 PurpleE2eeConvMenuCallback conv_menu_cb
;
42 static PurpleE2eeProvider
*main_provider
= NULL
;
44 /*** Encryption states for conversations. *************************************/
47 purple_e2ee_state_new(PurpleE2eeProvider
*provider
)
49 PurpleE2eeState
*state
;
51 g_return_val_if_fail(provider
!= NULL
, NULL
);
53 state
= g_new0(PurpleE2eeState
, 1);
54 state
->provider
= provider
;
61 purple_e2ee_state_ref(PurpleE2eeState
*state
)
63 g_return_if_fail(state
!= NULL
);
69 purple_e2ee_state_unref(PurpleE2eeState
*state
)
75 if (state
->ref_count
> 0)
79 g_free(state
->stock_icon
);
86 purple_e2ee_state_get_provider(PurpleE2eeState
*state
)
88 g_return_val_if_fail(state
!= NULL
, NULL
);
90 return state
->provider
;
94 purple_e2ee_state_set_name(PurpleE2eeState
*state
, const gchar
*name
)
96 g_return_if_fail(state
!= NULL
);
97 g_return_if_fail(name
!= NULL
);
100 state
->name
= g_strdup(name
);
104 purple_e2ee_state_get_name(PurpleE2eeState
*state
)
106 g_return_val_if_fail(state
!= NULL
, NULL
);
112 purple_e2ee_state_set_stock_icon(PurpleE2eeState
*state
,
113 const gchar
*stock_icon
)
115 g_return_if_fail(state
!= NULL
);
116 g_return_if_fail(stock_icon
!= NULL
);
118 g_free(state
->stock_icon
);
119 state
->stock_icon
= g_strdup(stock_icon
);
123 purple_e2ee_state_get_stock_icon(PurpleE2eeState
*state
)
125 g_return_val_if_fail(state
, NULL
);
127 return state
->stock_icon
;
130 /*** Encryption providers API. ************************************************/
133 purple_e2ee_provider_new(void)
135 PurpleE2eeProvider
*provider
;
137 provider
= g_new0(PurpleE2eeProvider
, 1);
143 purple_e2ee_provider_free(PurpleE2eeProvider
*provider
)
145 g_return_if_fail(provider
!= NULL
);
147 if (provider
== main_provider
) {
148 purple_debug_error("e2ee", "This provider is still registered");
152 g_free(provider
->name
);
157 purple_e2ee_provider_register(PurpleE2eeProvider
*provider
)
159 g_return_val_if_fail(provider
!= NULL
, FALSE
);
161 if (main_provider
!= NULL
)
164 main_provider
= provider
;
169 purple_e2ee_provider_unregister(PurpleE2eeProvider
*provider
)
171 GList
*it
, *clear_states
= NULL
;
172 g_return_if_fail(provider
!= NULL
);
174 if (main_provider
!= provider
) {
175 purple_debug_warning("e2ee", "This provider is not registered");
179 for (it
= purple_conversations_get_all(); it
; it
= g_list_next(it
)) {
180 PurpleConversation
*conv
= it
->data
;
181 PurpleE2eeState
*state
;
183 state
= purple_conversation_get_e2ee_state(conv
);
186 if (provider
== purple_e2ee_state_get_provider(state
))
187 clear_states
= g_list_prepend(clear_states
, conv
);
190 main_provider
= NULL
;
192 for (it
= clear_states
; it
; it
= g_list_next(it
))
193 purple_conversation_set_e2ee_state(it
->data
, NULL
);
194 g_list_free(clear_states
);
198 purple_e2ee_provider_get_main(void)
200 return main_provider
;
204 purple_e2ee_provider_set_name(PurpleE2eeProvider
*provider
, const gchar
*name
)
206 g_return_if_fail(provider
!= NULL
);
207 g_return_if_fail(name
!= NULL
);
209 g_free(provider
->name
);
210 provider
->name
= g_strdup(name
);
214 purple_e2ee_provider_get_name(PurpleE2eeProvider
*provider
)
216 g_return_val_if_fail(provider
!= NULL
, NULL
);
218 return provider
->name
;
222 purple_e2ee_provider_set_conv_menu_cb(PurpleE2eeProvider
*provider
,
223 PurpleE2eeConvMenuCallback conv_menu_cb
)
225 g_return_if_fail(provider
!= NULL
);
227 provider
->conv_menu_cb
= conv_menu_cb
;
230 PurpleE2eeConvMenuCallback
231 purple_e2ee_provider_get_conv_menu_cb(PurpleE2eeProvider
*provider
)
233 g_return_val_if_fail(provider
!= NULL
, NULL
);
235 return provider
->conv_menu_cb
;
239 purple_e2ee_provider_get_conv_menu_actions(PurpleE2eeProvider
*provider
,
240 PurpleConversation
*conv
)
242 PurpleE2eeConvMenuCallback cb
;
244 g_return_val_if_fail(provider
, NULL
);
245 g_return_val_if_fail(conv
, NULL
);
247 cb
= purple_e2ee_provider_get_conv_menu_cb(provider
);