libpurple/purpleprotocolserver.c

changeset 40708
53a26c29d26c
child 40725
447c01698e1c
equal deleted inserted replaced
40707:f84f2b4ef0e5 40708:53a26c29d26c
1 /*
2 * Purple - Internet Messaging Library
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
4 *
5 * Purple is the legal property of its developers, whose names are too numerous
6 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * source distribution.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23 #include "purpleprotocolserver.h"
24
25 /******************************************************************************
26 * GObject Implementation
27 *****************************************************************************/
28 G_DEFINE_INTERFACE(PurpleProtocolServer, purple_protocol_server, G_TYPE_INVALID)
29
30 static void
31 purple_protocol_server_default_init(PurpleProtocolServerInterface *iface) {
32 }
33
34 /******************************************************************************
35 * Public API
36 *****************************************************************************/
37 void
38 purple_protocol_server_register_user(PurpleProtocolServer *protocol_server,
39 PurpleAccount *account)
40 {
41 PurpleProtocolServerInterface *iface = NULL;
42
43 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
44 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
45
46 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
47 if(iface != NULL && iface->register_user != NULL) {
48 iface->register_user(protocol_server, account);
49 }
50 }
51
52 void
53 purple_protocol_server_unregister_user(PurpleProtocolServer *protocol_server,
54 PurpleAccount *account,
55 PurpleAccountUnregistrationCb cb,
56 gpointer data)
57 {
58 PurpleProtocolServerInterface *iface = NULL;
59
60 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
61 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
62
63 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
64 if(iface != NULL && iface->unregister_user != NULL) {
65 iface->unregister_user(protocol_server, account, cb, data);
66 }
67 }
68
69 void
70 purple_protocol_server_set_info(PurpleProtocolServer *protocol_server,
71 PurpleConnection *connection,
72 const gchar *info)
73 {
74 PurpleProtocolServerInterface *iface = NULL;
75
76 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
77 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
78
79 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
80 if(iface != NULL && iface->set_info != NULL) {
81 iface->set_info(protocol_server, connection, info);
82 }
83 }
84
85 void
86 purple_protocol_server_get_info(PurpleProtocolServer *protocol_server,
87 PurpleConnection *connection, const gchar *who)
88 {
89 PurpleProtocolServerInterface *iface = NULL;
90
91 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
92 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
93 g_return_if_fail(who != NULL);
94
95 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
96 if(iface != NULL && iface->get_info != NULL) {
97 iface->get_info(protocol_server, connection, who);
98 }
99 }
100
101 void
102 purple_protocol_server_set_status(PurpleProtocolServer *protocol_server,
103 PurpleAccount *account, PurpleStatus *status)
104 {
105 PurpleProtocolServerInterface *iface = NULL;
106
107 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
108 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
109 g_return_if_fail(PURPLE_IS_STATUS(status));
110
111 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
112 if(iface != NULL && iface->set_status != NULL) {
113 iface->set_status(protocol_server, account, status);
114 }
115 }
116
117 void
118 purple_protocol_server_set_idle(PurpleProtocolServer *protocol_server,
119 PurpleConnection *connection, gint idletime)
120 {
121 PurpleProtocolServerInterface *iface = NULL;
122
123 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
124 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
125
126 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
127 if(iface != NULL && iface->set_idle != NULL) {
128 iface->set_idle(protocol_server, connection, idletime);
129 }
130 }
131
132 void
133 purple_protocol_server_change_passwd(PurpleProtocolServer *protocol_server,
134 PurpleConnection *connection,
135 const gchar *old_pass,
136 const gchar *new_pass)
137 {
138 PurpleProtocolServerInterface *iface = NULL;
139
140 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
141 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
142 g_return_if_fail(old_pass != NULL);
143 g_return_if_fail(new_pass != NULL);
144
145 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
146 if(iface != NULL && iface->change_passwd != NULL) {
147 iface->change_passwd(protocol_server, connection, old_pass, new_pass);
148 }
149 }
150
151 void
152 purple_protocol_server_add_buddy(PurpleProtocolServer *protocol_server,
153 PurpleConnection *connection,
154 PurpleBuddy *buddy, PurpleGroup *group,
155 const gchar *message)
156 {
157 PurpleProtocolServerInterface *iface = NULL;
158
159 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
160 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
161 g_return_if_fail(PURPLE_IS_BUDDY(buddy));
162 g_return_if_fail(PURPLE_IS_GROUP(group));
163
164 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
165 if(iface != NULL && iface->add_buddy != NULL) {
166 iface->add_buddy(protocol_server, connection, buddy, group, message);
167 }
168 }
169
170 void
171 purple_protocol_server_add_buddies(PurpleProtocolServer *protocol_server,
172 PurpleConnection *connection,
173 GList *buddies, GList *groups,
174 const gchar *message)
175 {
176 PurpleProtocolServerInterface *iface = NULL;
177
178 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
179 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
180 g_return_if_fail(g_list_length(buddies) != g_list_length(groups));
181
182 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
183 if(iface != NULL && iface->add_buddies != NULL) {
184 iface->add_buddies(protocol_server, connection, buddies, groups,
185 message);
186 } else {
187 while(buddies != NULL && groups != NULL) {
188 purple_protocol_server_add_buddy(protocol_server, connection,
189 PURPLE_BUDDY(buddies->data),
190 PURPLE_GROUP(groups->data),
191 message);
192
193 buddies = g_list_next(buddies);
194 groups = g_list_next(groups);
195 }
196 }
197 }
198
199 void
200 purple_protocol_server_remove_buddy(PurpleProtocolServer *protocol_server,
201 PurpleConnection *connection,
202 PurpleBuddy *buddy, PurpleGroup *group)
203 {
204 PurpleProtocolServerInterface *iface = NULL;
205
206 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
207 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
208 g_return_if_fail(PURPLE_IS_BUDDY(buddy));
209 g_return_if_fail(PURPLE_IS_GROUP(group));
210
211 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
212 if(iface != NULL && iface->remove_buddy != NULL) {
213 iface->remove_buddy(protocol_server, connection, buddy, group);
214 }
215 }
216
217 void
218 purple_protocol_server_remove_buddies(PurpleProtocolServer *protocol_server,
219 PurpleConnection *connection,
220 GList *buddies, GList *groups)
221 {
222 PurpleProtocolServerInterface *iface = NULL;
223
224 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
225 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
226
227 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
228 if(iface != NULL && iface->remove_buddies != NULL) {
229 iface->remove_buddies(protocol_server, connection, buddies, groups);
230 } else {
231 while(buddies != NULL && groups != NULL) {
232 purple_protocol_server_remove_buddy(protocol_server, connection,
233 PURPLE_BUDDY(buddies->data),
234 PURPLE_GROUP(groups->data));
235
236 buddies = g_list_next(buddies);
237 groups = g_list_next(groups);
238 }
239 }
240 }
241
242 void
243 purple_protocol_server_keepalive(PurpleProtocolServer *protocol_server,
244 PurpleConnection *connection)
245 {
246 PurpleProtocolServerInterface *iface = NULL;
247
248 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
249 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
250
251 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
252 if(iface != NULL && iface->keepalive != NULL) {
253 iface->keepalive(protocol_server, connection);
254 }
255 }
256
257 gint
258 purple_protocol_server_get_keepalive_interval(PurpleProtocolServer *protocol_server)
259 {
260 PurpleProtocolServerInterface *iface = NULL;
261
262 g_return_val_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server), -1);
263
264 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
265 if(iface != NULL && iface->get_keepalive_interval != NULL) {
266 return iface->get_keepalive_interval(protocol_server);
267 }
268
269 return -1;
270 }
271
272 void
273 purple_protocol_server_alias_buddy(PurpleProtocolServer *protocol_server,
274 PurpleConnection *connection,
275 const gchar *who, const gchar *alias)
276 {
277 PurpleProtocolServerInterface *iface = NULL;
278
279 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
280 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
281 g_return_if_fail(who != NULL);
282
283 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
284 if(iface != NULL && iface->alias_buddy != NULL) {
285 iface->alias_buddy(protocol_server, connection, who, alias);
286 }
287 }
288
289 void
290 purple_protocol_server_group_buddy(PurpleProtocolServer *protocol_server,
291 PurpleConnection *connection,
292 const gchar *who, const gchar *old_group,
293 const gchar *new_group)
294 {
295 PurpleProtocolServerInterface *iface = NULL;
296
297 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
298 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
299 g_return_if_fail(who != NULL);
300
301 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
302 if(iface != NULL && iface->group_buddy != NULL) {
303 iface->group_buddy(protocol_server, connection, who, old_group,
304 new_group);
305 }
306 }
307
308 void
309 purple_protocol_server_rename_group(PurpleProtocolServer *protocol_server,
310 PurpleConnection *connection,
311 const gchar *old_name, PurpleGroup *group,
312 GList *moved_buddies)
313 {
314 PurpleProtocolServerInterface *iface = NULL;
315
316 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
317 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
318 g_return_if_fail(PURPLE_IS_GROUP(group));
319
320 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
321 if(iface != NULL && iface->rename_group != NULL) {
322 iface->rename_group(protocol_server, connection, old_name, group,
323 moved_buddies);
324 }
325 }
326
327 void
328 purple_protocol_server_set_buddy_icon(PurpleProtocolServer *protocol_server,
329 PurpleConnection *connection,
330 PurpleImage *img)
331 {
332 PurpleProtocolServerInterface *iface = NULL;
333
334 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
335 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
336 g_return_if_fail(PURPLE_IS_IMAGE(img));
337
338 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
339 if(iface != NULL && iface->set_buddy_icon != NULL) {
340 iface->set_buddy_icon(protocol_server, connection, img);
341 }
342 }
343
344 void
345 purple_protocol_server_remove_group(PurpleProtocolServer *protocol_server,
346 PurpleConnection *connection,
347 PurpleGroup *group)
348 {
349 PurpleProtocolServerInterface *iface = NULL;
350
351 g_return_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server));
352 g_return_if_fail(PURPLE_IS_CONNECTION(connection));
353 g_return_if_fail(PURPLE_IS_GROUP(group));
354
355 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
356 if(iface != NULL && iface->remove_group != NULL) {
357 iface->remove_group(protocol_server, connection, group);
358 }
359 }
360
361 gint
362 purple_protocol_server_send_raw(PurpleProtocolServer *protocol_server,
363 PurpleConnection *connection,
364 const gchar *buf, gint len)
365 {
366 PurpleProtocolServerInterface *iface = NULL;
367
368 g_return_val_if_fail(PURPLE_IS_PROTOCOL_SERVER(protocol_server), -1);
369 g_return_val_if_fail(PURPLE_IS_CONNECTION(connection), -1);
370
371 iface = PURPLE_PROTOCOL_SERVER_GET_IFACE(protocol_server);
372 if(iface != NULL && iface->send_raw != NULL) {
373 return iface->send_raw(protocol_server, connection, buf, len);
374 }
375
376 return -1;
377 }

mercurial