purple: update to latest 3.x.x plugin interfaces
[siplcs.git] / src / purple / purple-plugin3.c
blob0f959876524f76334aaa4187bbf68a42612e0400
1 /**
2 * @file purple-plugin3.c
4 * pidgin-sipe
6 * Copyright (C) 2015-2019 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <glib.h>
28 #include <gmodule.h>
30 /* Flag needed for correct version of PURPLE_INIT_PLUGIN() */
31 #ifndef PURPLE_PLUGINS
32 #define PURPLE_PLUGINS
33 #endif
35 #include "protocol.h"
37 #include "purple-private.h"
38 #include "sipe-common.h"
39 #include "sipe-core.h"
41 #define SIPE_TYPE_PROTOCOL (sipe_protocol_get_type())
43 typedef struct _SipeProtocol {
44 PurpleProtocol parent;
45 } SipeProtocol;
47 typedef struct _NullProtocolClass {
48 PurpleProtocolClass parent_class;
49 } SipeProtocolClass;
51 G_MODULE_EXPORT GType sipe_protocol_get_type(void);
53 static void
54 sipe_protocol_class_init(PurpleProtocolClass *klass,
55 SIPE_UNUSED_PARAMETER void *unused)
57 klass->login = sipe_purple_login;
58 klass->close = sipe_purple_close;
59 klass->status_types = sipe_purple_status_types;
60 klass->list_icon = sipe_purple_list_icon;
63 static void
64 sipe_protocol_init(PurpleProtocol *protocol,
65 SIPE_UNUSED_PARAMETER void *unused)
67 sipe_core_init(LOCALEDIR);
69 protocol->id = SIPE_PURPLE_PLUGIN_ID;
70 protocol->name = SIPE_PURPLE_PLUGIN_NAME;
71 protocol->options = SIPE_PURPLE_PROTOCOL_OPTIONS;
72 protocol->user_splits = g_list_append(NULL, sipe_purple_user_split());
73 protocol->account_options = sipe_purple_account_options();
76 static GList *
77 get_actions(SIPE_UNUSED_PARAMETER PurpleConnection *gc)
79 return sipe_purple_actions();
82 static void
83 sipe_protocol_client_iface_init(PurpleProtocolClientIface *client_iface,
84 SIPE_UNUSED_PARAMETER void *unused)
86 client_iface->get_actions = get_actions;
87 client_iface->status_text = sipe_purple_status_text;
88 client_iface->tooltip_text = sipe_purple_tooltip_text;
89 client_iface->blist_node_menu = sipe_purple_blist_node_menu;
90 client_iface->convo_closed = sipe_purple_convo_closed;
91 client_iface->normalize = purple_normalize_nocase;
92 client_iface->get_account_text_table = sipe_purple_get_account_text_table;
95 static void
96 sipe_protocol_server_iface_init(PurpleProtocolServerIface *server_iface,
97 SIPE_UNUSED_PARAMETER void *unused)
99 server_iface->get_info = sipe_purple_get_info;
100 server_iface->set_status = sipe_purple_set_status;
101 server_iface->set_idle = sipe_purple_set_idle;
102 server_iface->add_buddy = sipe_purple_add_buddy;
103 server_iface->remove_buddy = sipe_purple_remove_buddy;
104 server_iface->alias_buddy = sipe_purple_alias_buddy;
105 server_iface->group_buddy = sipe_purple_group_buddy;
106 server_iface->rename_group = sipe_purple_group_rename;
107 server_iface->remove_group = sipe_purple_group_remove;
110 static int
111 send_im(PurpleConnection *gc, PurpleMessage *msg)
113 sipe_core_im_send(PURPLE_GC_TO_SIPE_CORE_PUBLIC,
114 purple_message_get_recipient(msg),
115 purple_message_get_contents(msg));
116 return 1;
119 static void
120 sipe_protocol_im_iface_init(PurpleProtocolIMIface *im_iface,
121 SIPE_UNUSED_PARAMETER void *unused)
123 im_iface->send = send_im;
124 im_iface->send_typing = sipe_purple_send_typing;
127 static void
128 sipe_protocol_chat_iface_init(PurpleProtocolChatIface *chat_iface,
129 SIPE_UNUSED_PARAMETER void *unused)
131 chat_iface->info = sipe_purple_chat_info;
132 chat_iface->info_defaults = sipe_purple_chat_info_defaults;
133 chat_iface->join = sipe_purple_chat_join;
134 chat_iface->invite = sipe_purple_chat_invite;
135 chat_iface->leave = sipe_purple_chat_leave;
136 chat_iface->send = sipe_purple_chat_send;
139 static void
140 sipe_protocol_privacy_iface_init(PurpleProtocolPrivacyIface *privacy_iface,
141 SIPE_UNUSED_PARAMETER void *unused)
143 privacy_iface->add_permit = sipe_purple_add_permit;
144 privacy_iface->add_deny = sipe_purple_add_deny;
145 privacy_iface->rem_permit = sipe_purple_add_deny;
146 privacy_iface->rem_deny = sipe_purple_add_permit;
149 static void
150 sipe_protocol_xfer_iface_init(PurpleProtocolXferInterface *xfer_iface,
151 SIPE_UNUSED_PARAMETER void *unused)
153 xfer_iface->send_file = sipe_purple_ft_send_file;
156 static void
157 sipe_protocol_roomlist_iface_init(PurpleProtocolRoomlistIface *roomlist_iface,
158 SIPE_UNUSED_PARAMETER void *unused)
160 roomlist_iface->get_list = sipe_purple_roomlist_get_list;
161 roomlist_iface->cancel = sipe_purple_roomlist_cancel;
164 #ifdef HAVE_VV
165 static void
166 sipe_protocol_media_iface_init(PurpleProtocolMediaIface *media_iface,
167 SIPE_UNUSED_PARAMETER void *unused)
169 media_iface->initiate_session = sipe_purple_initiate_media;
170 media_iface->get_caps = sipe_purple_get_media_caps;
172 #endif /* HAVE_VV */
174 PURPLE_DEFINE_TYPE_EXTENDED(
175 SipeProtocol, sipe_protocol, PURPLE_TYPE_PROTOCOL, 0,
177 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_CLIENT_IFACE,
178 sipe_protocol_client_iface_init)
179 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_SERVER_IFACE,
180 sipe_protocol_server_iface_init)
181 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_IM_IFACE,
182 sipe_protocol_im_iface_init)
183 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_CHAT_IFACE,
184 sipe_protocol_chat_iface_init)
185 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_PRIVACY_IFACE,
186 sipe_protocol_privacy_iface_init)
187 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_XFER,
188 sipe_protocol_xfer_iface_init)
189 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_ROOMLIST_IFACE,
190 sipe_protocol_roomlist_iface_init)
191 #ifdef HAVE_VV
192 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_MEDIA_IFACE,
193 sipe_protocol_media_iface_init)
194 #endif /* HAVE_VV */
197 static PurplePluginInfo *
198 plugin_query(SIPE_UNUSED_PARAMETER GError **error)
200 gchar ** authors = g_strsplit(SIPE_PURPLE_PLUGIN_AUTHORS, ", ", -1);
201 PurplePluginInfo *info = purple_plugin_info_new(
202 "id", SIPE_PURPLE_PLUGIN_ID,
203 "name", SIPE_PURPLE_PLUGIN_NAME,
204 "version", PACKAGE_VERSION,
205 "category", "Protocol",
206 "summary", SIPE_PURPLE_PLUGIN_SUMMARY,
207 "description", SIPE_PURPLE_PLUGIN_DESCRIPTION,
208 "authors", authors,
209 "website", PACKAGE_URL,
210 "abi-version", PURPLE_ABI_VERSION,
211 "flags", PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD,
212 NULL);
214 g_strfreev(authors);
216 return info;
219 static PurpleProtocol *sipe_protocol = NULL;
221 static gboolean
222 plugin_load(PurplePlugin *plugin, GError **error)
224 sipe_protocol_register_type(plugin);
226 sipe_protocol = purple_protocols_add(SIPE_TYPE_PROTOCOL, error);
227 if (!sipe_protocol) {
228 return FALSE;
231 if (!sipe_purple_plugin_load(plugin)) {
232 return FALSE;
235 return TRUE;
238 static gboolean
239 plugin_unload(PurplePlugin *plugin, GError **error)
241 sipe_purple_plugin_unload(plugin);
243 if (!purple_protocols_remove(sipe_protocol, error)) {
244 return FALSE;
247 return TRUE;
250 PURPLE_PLUGIN_INIT(sipe, plugin_query, plugin_load, plugin_unload);
253 Local Variables:
254 mode: c
255 c-file-style: "bsd"
256 indent-tabs-mode: t
257 tab-width: 8
258 End: