Mercurial > pidgin.yaz
annotate src/prpl.c @ 10361:f57369469684
[gaim-migrate @ 11579]
if (0) this out in HEAD too until i figure out the real limit,
or maybe just handle the errors yahoo sends us.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Mon, 13 Dec 2004 23:03:06 +0000 |
parents | eaec201b2688 |
children | 6feef0a9098a |
rev | line source |
---|---|
981 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
6460
ff4551719cc7
[gaim-migrate @ 6969]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
7 * |
981 | 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. | |
12 * | |
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. | |
17 * | |
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 | |
21 * | |
22 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
23 #include "internal.h" |
5945
2a18e7b5917e
[gaim-migrate @ 6386]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
24 #include "conversation.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
25 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
26 #include "notify.h" |
981 | 27 #include "prpl.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
28 #include "request.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 #include "util.h" |
3738 | 30 |
9949 | 31 /**************************************************************************/ |
32 /** @name Protocol Plugin API */ | |
33 /**************************************************************************/ | |
34 void | |
35 gaim_prpl_got_account_idle(GaimAccount *account, gboolean idle, | |
36 time_t idle_time) | |
37 { | |
38 g_return_if_fail(account != NULL); | |
39 g_return_if_fail(gaim_account_is_connected(account)); | |
40 | |
41 gaim_presence_set_idle(gaim_account_get_presence(account), | |
42 idle, idle_time); | |
43 } | |
44 | |
45 void | |
46 gaim_prpl_got_account_login_time(GaimAccount *account, const char *name, | |
47 time_t login_time) | |
48 { | |
49 GaimPresence *presence; | |
50 | |
51 g_return_if_fail(account != NULL); | |
52 g_return_if_fail(name != NULL && *name != '\0'); | |
53 g_return_if_fail(gaim_account_is_connected(account)); | |
54 | |
55 if (login_time == 0) | |
56 login_time = time(NULL); | |
57 | |
58 presence = gaim_account_get_presence(account); | |
59 | |
10007 | 60 gaim_presence_set_login_time(presence, login_time); |
9949 | 61 } |
62 | |
63 static gboolean | |
64 set_value_from_arg(GaimStatus *status, const char *id, va_list *args) | |
65 { | |
66 GaimValue *value; | |
67 | |
68 value = gaim_status_get_attr_value(status, id); | |
69 | |
70 if (value == NULL) | |
71 { | |
72 gaim_debug_error("prpl", | |
73 "Attempted to set an unknown attribute %s on " | |
74 "status %s\n", | |
75 id, gaim_status_get_id(status)); | |
76 return FALSE; | |
77 } | |
78 | |
79 switch (gaim_value_get_type(value)) | |
80 { | |
81 case GAIM_TYPE_CHAR: | |
82 gaim_value_set_char(value, (char)va_arg(*args, int)); | |
83 break; | |
84 | |
85 case GAIM_TYPE_UCHAR: | |
86 gaim_value_set_uchar(value, | |
87 (unsigned char)va_arg(*args, unsigned int)); | |
88 break; | |
89 | |
90 case GAIM_TYPE_BOOLEAN: | |
91 gaim_value_set_boolean(value, va_arg(*args, gboolean)); | |
92 break; | |
93 | |
94 case GAIM_TYPE_SHORT: | |
95 gaim_value_set_short(value, (short)va_arg(*args, int)); | |
96 break; | |
97 | |
98 case GAIM_TYPE_USHORT: | |
99 gaim_value_set_ushort(value, | |
100 (unsigned short)va_arg(*args, unsigned int)); | |
101 break; | |
102 | |
103 case GAIM_TYPE_INT: | |
104 gaim_value_set_int(value, va_arg(*args, int)); | |
105 break; | |
106 | |
107 case GAIM_TYPE_UINT: | |
108 gaim_value_set_uint(value, va_arg(*args, unsigned int)); | |
109 break; | |
110 | |
111 case GAIM_TYPE_LONG: | |
112 gaim_value_set_long(value, va_arg(*args, long)); | |
113 break; | |
114 | |
115 case GAIM_TYPE_ULONG: | |
116 gaim_value_set_ulong(value, va_arg(*args, unsigned long)); | |
117 break; | |
118 | |
119 case GAIM_TYPE_INT64: | |
120 gaim_value_set_int64(value, va_arg(*args, gint64)); | |
121 break; | |
122 | |
123 case GAIM_TYPE_UINT64: | |
124 gaim_value_set_uint64(value, va_arg(*args, guint64)); | |
125 break; | |
126 | |
127 case GAIM_TYPE_STRING: | |
128 gaim_value_set_string(value, va_arg(*args, char *)); | |
129 break; | |
130 | |
131 case GAIM_TYPE_OBJECT: | |
132 gaim_value_set_object(value, va_arg(*args, void *)); | |
133 break; | |
134 | |
135 case GAIM_TYPE_POINTER: | |
136 gaim_value_set_pointer(value, va_arg(*args, void *)); | |
137 break; | |
138 | |
139 case GAIM_TYPE_ENUM: | |
140 gaim_value_set_enum(value, va_arg(*args, int)); | |
141 break; | |
142 | |
143 case GAIM_TYPE_BOXED: | |
144 gaim_value_set_boxed(value, va_arg(*args, void *)); | |
145 break; | |
146 | |
147 default: | |
148 return FALSE; | |
149 } | |
150 | |
151 return TRUE; | |
152 } | |
153 | |
154 void | |
155 gaim_prpl_got_account_status(GaimAccount *account, const char *status_id, | |
156 const char *attr_id, ...) | |
157 { | |
158 GaimPresence *presence; | |
159 GaimStatus *status; | |
160 | |
161 g_return_if_fail(account != NULL); | |
162 g_return_if_fail(status_id != NULL); | |
163 g_return_if_fail(gaim_account_is_connected(account)); | |
164 | |
165 presence = gaim_account_get_presence(account); | |
166 status = gaim_presence_get_status(presence, status_id); | |
167 | |
168 g_return_if_fail(status != NULL); | |
169 | |
170 if (attr_id != NULL) | |
171 { | |
172 va_list args; | |
173 | |
174 va_start(args, attr_id); | |
175 | |
176 while (attr_id != NULL) | |
177 { | |
178 set_value_from_arg(status, attr_id, &args); | |
179 | |
180 attr_id = va_arg(args, char *); | |
181 } | |
182 | |
183 va_end(args); | |
184 } | |
185 | |
186 gaim_presence_set_status_active(presence, status_id, TRUE); | |
187 } | |
188 | |
189 void | |
190 gaim_prpl_got_account_warning_level(GaimAccount *account, const char *username, | |
191 unsigned int level) | |
192 { | |
193 GaimPresence *presence; | |
194 unsigned int old_level; | |
10007 | 195 gchar *buf; |
9949 | 196 |
197 g_return_if_fail(account != NULL); | |
198 | |
199 presence = gaim_account_get_presence(account); | |
200 | |
201 gaim_signal_emit(gaim_accounts_get_handle(), "account-warned", | |
202 account, username, level); | |
203 | |
204 old_level = gaim_presence_get_warning_level(presence); | |
205 gaim_presence_set_warning_level(presence, level); | |
206 | |
207 if (old_level >= level) | |
208 return; | |
209 | |
10007 | 210 if (username == NULL) |
211 buf = g_strdup_printf(_("%s has just been warned by an anonymous " | |
212 "person.\nYour new warning level is %d%%"), | |
213 gaim_account_get_username(account), | |
214 level); | |
215 else | |
216 buf = g_strdup_printf(_("%s has just been warned by %s.\n" | |
217 "Your new warning level is %d%%"), | |
218 gaim_account_get_username(account), | |
219 username, level); | |
9949 | 220 |
10007 | 221 gaim_notify_info(NULL, NULL, buf, NULL); |
222 | |
223 g_free(buf); | |
9949 | 224 } |
225 | |
226 void | |
227 gaim_prpl_got_user_idle(GaimAccount *account, const char *name, | |
228 gboolean idle, time_t idle_time) | |
229 { | |
230 GaimBuddy *buddy; | |
10007 | 231 GaimPresence *presence; |
9949 | 232 |
233 g_return_if_fail(account != NULL); | |
234 g_return_if_fail(name != NULL); | |
235 g_return_if_fail(gaim_account_is_connected(account)); | |
236 | |
237 if ((buddy = gaim_find_buddy(account, name)) == NULL) | |
238 return; | |
239 | |
10007 | 240 presence = gaim_buddy_get_presence(buddy); |
241 | |
242 gaim_presence_set_idle(presence, idle, idle_time); | |
9949 | 243 } |
244 | |
245 void | |
246 gaim_prpl_got_user_login_time(GaimAccount *account, const char *name, | |
247 time_t login_time) | |
248 { | |
249 GaimBuddy *buddy; | |
250 GaimPresence *presence; | |
251 | |
252 g_return_if_fail(account != NULL); | |
253 g_return_if_fail(name != NULL); | |
254 | |
255 if ((buddy = gaim_find_buddy(account, name)) == NULL) | |
256 return; | |
257 | |
258 if (login_time == 0) | |
259 login_time = time(NULL); | |
260 | |
261 presence = gaim_buddy_get_presence(buddy); | |
262 | |
10006 | 263 gaim_presence_set_login_time(presence, login_time); |
9949 | 264 } |
265 | |
266 void | |
267 gaim_prpl_got_user_status(GaimAccount *account, const char *name, | |
268 const char *status_id, const char *attr_id, ...) | |
269 { | |
270 GaimBuddy *buddy; | |
271 GaimPresence *presence; | |
272 GaimStatus *status; | |
10052 | 273 GaimStatus *old_status; |
9949 | 274 |
275 g_return_if_fail(account != NULL); | |
276 g_return_if_fail(name != NULL); | |
277 g_return_if_fail(status_id != NULL); | |
278 g_return_if_fail(gaim_account_is_connected(account)); | |
279 | |
10052 | 280 buddy = gaim_find_buddy(account, name); |
281 if (buddy == NULL) | |
9949 | 282 return; |
283 | |
284 presence = gaim_buddy_get_presence(buddy); | |
285 status = gaim_presence_get_status(presence, status_id); | |
286 | |
287 g_return_if_fail(status != NULL); | |
288 | |
289 if (attr_id != NULL) | |
290 { | |
291 va_list args; | |
292 | |
293 va_start(args, attr_id); | |
294 | |
295 while (attr_id != NULL) | |
296 { | |
297 set_value_from_arg(status, attr_id, &args); | |
298 | |
299 attr_id = va_arg(args, char *); | |
300 } | |
301 | |
302 va_end(args); | |
303 } | |
304 | |
10052 | 305 old_status = gaim_presence_get_active_status(presence); |
9949 | 306 gaim_presence_set_status_active(presence, status_id, TRUE); |
10052 | 307 gaim_blist_update_buddy_status(buddy, old_status); |
9949 | 308 } |
309 | |
310 void | |
311 gaim_prpl_got_user_warning_level(GaimAccount *account, const char *name, | |
312 unsigned int level) | |
313 { | |
314 GaimBuddy *buddy; | |
10007 | 315 GaimPresence *presence; |
9949 | 316 |
317 g_return_if_fail(account != NULL); | |
318 g_return_if_fail(name != NULL); | |
319 | |
320 if ((buddy = gaim_find_buddy(account, name)) == NULL) | |
321 return; | |
322 | |
10007 | 323 presence = gaim_buddy_get_presence(buddy); |
324 | |
325 gaim_presence_set_warning_level(presence, level); | |
9949 | 326 } |
327 | |
328 void | |
329 gaim_prpl_set_account_status(GaimAccount *account, GaimStatus *status) | |
330 { | |
331 GaimPlugin *prpl; | |
332 GaimPluginProtocolInfo *prpl_info; | |
333 | |
334 g_return_if_fail(account != NULL); | |
335 g_return_if_fail(status != NULL); | |
336 | |
337 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
338 | |
339 if (prpl == NULL) | |
340 return; | |
341 | |
342 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
343 | |
344 if (prpl_info->set_status != NULL) | |
345 prpl_info->set_status(account, status); | |
346 } | |
347 | |
10006 | 348 GList * |
349 gaim_prpl_get_statuses(GaimAccount *account, GaimPresence *presence) | |
350 { | |
351 GaimPlugin *prpl; | |
352 GaimPluginProtocolInfo *prpl_info; | |
353 GList *statuses = NULL; | |
354 GList *l; | |
355 GaimStatus *status; | |
356 | |
357 g_return_val_if_fail(account != NULL, NULL); | |
358 g_return_val_if_fail(presence != NULL, NULL); | |
359 | |
360 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); | |
10046 | 361 |
10006 | 362 if (prpl == NULL) |
363 return NULL; | |
10046 | 364 |
10006 | 365 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
366 if (prpl_info == NULL || prpl_info->status_types == NULL) | |
367 return NULL; | |
368 | |
369 for (l = prpl_info->status_types(account); l != NULL; l = l->next) | |
370 { | |
371 status = gaim_status_new((GaimStatusType *)l->data, presence); | |
372 statuses = g_list_append(statuses, status); | |
373 } | |
374 | |
375 return statuses; | |
376 } | |
377 | |
9949 | 378 |
379 /************************************************************************** | |
380 * Protocol Plugin Subsystem API | |
381 **************************************************************************/ | |
382 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
383 GaimPlugin * |
7956 | 384 gaim_find_prpl(const char *id) |
981 | 385 { |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
386 GList *l; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
387 GaimPlugin *plugin; |
981 | 388 |
10036
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
389 g_return_val_if_fail(id != NULL, NULL); |
0ddc38f8db4a
[gaim-migrate @ 10995]
Luke Schierer <lschiere@pidgin.im>
parents:
10023
diff
changeset
|
390 |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
391 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) { |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
392 plugin = (GaimPlugin *)l->data; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
393 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
394 /* Just In Case (TM) */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
395 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) { |
7956 | 396 if (!strcmp(plugin->info->id, id)) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
397 return plugin; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
398 } |
981 | 399 } |
400 | |
401 return NULL; | |
402 } |