mark PurpleImageClass as private
[pidgin-git.git] / libpurple / protocols / oscar / family_feedbag.c
blob0c5623f973e12b13f266446c485a720a0b7a923a
1 /*
2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Family 0x0013 - Server-Side/Stored Information.
24 * Deals with storing certain types of information, such as a user's buddy
25 * list, permit/deny list, and permit/deny preferences, on the server, so
26 * that they can be accessed from any client.
28 * We keep 2 copies of SSI data:
29 * 1) An exact copy of what is stored on the AIM servers.
30 * 2) A local copy that we make changes to, and then send diffs
31 * between this and the exact copy to keep them in sync.
33 * All the "aim_ssi_itemlist_bleh" functions near the top just modify the list
34 * that is given to them (i.e. they don't send SNACs).
36 * The SNAC sending and receiving functions are lower down in the file, and
37 * they're simpler. They are in the order of the subtypes they deal with,
38 * starting with the request rights function (subtype 0x0002), then parse
39 * rights (subtype 0x0003), then--well, you get the idea.
41 * This is entirely too complicated.
42 * You don't know the half of it.
45 #include "oscar.h"
46 #include "oscarcommon.h"
47 #include "debug.h"
49 static int aim_ssi_addmoddel(OscarData *od);
51 static void aim_ssi_item_free(struct aim_ssi_item *item)
53 g_free(item->name);
54 aim_tlvlist_free(item->data);
55 g_free(item);
58 static void aim_ssi_item_set_name(struct aim_ssi_itemlist *list, struct aim_ssi_item *item, const char *name)
60 gchar key[3000];
62 if (item->name) {
63 /* Remove old name from hash table */
64 snprintf(key, sizeof(key), "%hx%s", item->type, oscar_normalize(NULL, item->name));
65 g_hash_table_remove(list->idx_all_named_items, key);
68 g_free(item->name);
69 item->name = g_strdup(name);
71 if (name) {
72 /* Add new name to hash table */
73 snprintf(key, sizeof(key), "%hx%s", item->type, oscar_normalize(NULL, item->name));
74 g_hash_table_insert(list->idx_all_named_items, g_strdup(key), item);
78 /**
79 * List types based on http://dev.aol.com/aim/oscar/#FEEDBAG (archive.org)
80 * and http://iserverd.khstu.ru/oscar/ssi_item.html
82 * @param type The type of a list item as integer number, as provided by an aim_ssi_item struct.
83 * @return Returns the name of the item type as a character string.
85 static const gchar*
86 aim_ssi_type_to_string(guint16 type)
88 struct TypeStringPair
90 guint16 type;
91 const gchar *string;
93 static const struct TypeStringPair type_strings[] = {
94 { 0x0000, "Buddy" },
95 { 0x0001, "Group" },
96 { 0x0002, "Permit/Visible" },
97 { 0x0003, "Deny/Invisible" },
98 { 0x0004, "PDInfo" },
99 { 0x0005, "PresencePrefs" },
100 { 0x0006, "Non-Buddy Info" },
101 { 0x0009, "ClientPrefs" },
102 { 0x000e, "ICQDeny/Ignore" },
103 { 0x0014, "Buddy Icon" },
104 { 0x0015, "Recent Buddies" },
105 { 0x0019, "Non-Buddy" },
106 { 0x001d, "Vanity Info" },
107 { 0x0020, "ICQ-MDir" },
108 { 0x0029, "Facebook" },
110 size_t i;
111 for (i = 0; i < G_N_ELEMENTS(type_strings); i++) {
112 if (type_strings[i].type == type) {
113 return type_strings[i].string;
116 return "unknown";
119 /** For debug log output: Appends a line containing information about a given list item to a string.
121 * @param str String to which the line will be appended.
122 * @param prefix A string which will be prepended to the line.
123 * @param item List item from which information is extracted.
125 static void
126 aim_ssi_item_debug_append(GString *str, char *prefix, struct aim_ssi_item *item)
128 g_string_append_printf(str,
129 "%s gid=0x%04hx, bid=0x%04hx, list_type=0x%04hx [%s], name=%s.\n",
130 prefix, item->gid, item->bid, item->type, aim_ssi_type_to_string(item->type),
131 item->name ? item->name : "(null)");
135 * Locally rebuild the 0x00c8 TLV in the additional data of the given group.
137 * @param list A pointer to a pointer to the current list of items.
138 * @param name A null terminated string containing the group name, or NULL
139 * if you want to modify the master group.
140 * @return Return a pointer to the modified item.
142 static void
143 aim_ssi_itemlist_rebuildgroup(struct aim_ssi_itemlist *list, const char *name)
145 int newlen;
146 struct aim_ssi_item *cur, *group;
148 /* Find the group */
149 if (!(group = aim_ssi_itemlist_finditem(list, name, NULL, AIM_SSI_TYPE_GROUP)))
150 return;
152 /* Find the length for the new additional data */
153 newlen = 0;
154 if (group->gid == 0x0000) {
155 for (cur=list->data; cur; cur=cur->next)
156 if ((cur->type == AIM_SSI_TYPE_GROUP) && (cur->gid != 0x0000))
157 newlen += 2;
158 } else {
159 for (cur=list->data; cur; cur=cur->next)
160 if ((cur->gid == group->gid) && (cur->type == AIM_SSI_TYPE_BUDDY))
161 newlen += 2;
164 /* Build the new TLV list */
165 if (newlen > 0) {
166 guint8 *newdata;
168 newdata = g_new(guint8, newlen);
169 newlen = 0;
170 if (group->gid == 0x0000) {
171 for (cur=list->data; cur; cur=cur->next)
172 if ((cur->type == AIM_SSI_TYPE_GROUP) && (cur->gid != 0x0000))
173 newlen += aimutil_put16(newdata+newlen, cur->gid);
174 } else {
175 for (cur=list->data; cur; cur=cur->next)
176 if ((cur->gid == group->gid) && (cur->type == AIM_SSI_TYPE_BUDDY))
177 newlen += aimutil_put16(newdata+newlen, cur->bid);
179 aim_tlvlist_replace_raw(&group->data, 0x00c8, newlen, newdata);
181 g_free(newdata);
186 * Locally add a new item to the given item list.
188 * @param list A pointer to a pointer to the current list of items.
189 * @param name A null terminated string of the name of the new item, or NULL if the
190 * item should have no name.
191 * @param gid The group ID# you want the new item to have, or 0xFFFF if we should pick something.
192 * @param bid The buddy ID# you want the new item to have, or 0xFFFF if we should pick something.
193 * @param type The type of the item, 0x0000 for a contact, 0x0001 for a group, etc.
194 * @param data The additional data for the new item.
195 * @return A pointer to the newly created item.
197 static struct aim_ssi_item *aim_ssi_itemlist_add(struct aim_ssi_itemlist *list, const char *name, guint16 gid, guint16 bid, guint16 type, GSList *data)
199 gboolean exists;
200 struct aim_ssi_item *cur, *new;
202 new = g_new0(struct aim_ssi_item, 1);
204 /* Set the group ID# and buddy ID# */
205 new->gid = gid;
206 new->bid = bid;
207 if (type == AIM_SSI_TYPE_GROUP) {
208 if ((new->gid == 0xFFFF) && name) {
209 do {
210 new->gid += 0x0001;
211 exists = FALSE;
212 for (cur = list->data; cur != NULL; cur = cur->next)
213 if ((cur->type == AIM_SSI_TYPE_GROUP) && (cur->gid == new->gid)) {
214 exists = TRUE;
215 break;
217 } while (exists);
219 } else if (new->gid == 0x0000) {
221 * This is weird, but apparently items in the root group can't
222 * have a buddy ID equal to any group ID. You'll get error
223 * 0x0003 when trying to add, which is "item already exists"
225 if (new->bid == 0xFFFF) {
226 do {
227 new->bid += 0x0001;
228 exists = FALSE;
229 for (cur = list->data; cur != NULL; cur = cur->next)
230 if (cur->bid == new->bid || cur->gid == new->bid) {
231 exists = TRUE;
232 break;
234 } while (exists);
236 } else {
237 if (new->bid == 0xFFFF) {
238 do {
239 new->bid += 0x0001;
240 exists = FALSE;
241 for (cur = list->data; cur != NULL; cur = cur->next)
242 if (cur->bid == new->bid && cur->gid == new->gid) {
243 exists = TRUE;
244 break;
246 } while (exists);
250 /* Set the type */
251 new->type = type;
253 /* Add it to the gid+bid hashtable */
254 g_hash_table_insert(list->idx_gid_bid, GINT_TO_POINTER((new->gid << 16) + new->bid), new);
256 /* Set the name - do this *AFTER* setting the type because type is used for the key */
257 aim_ssi_item_set_name(list, new, name);
259 /* Set the TLV list */
260 new->data = aim_tlvlist_copy(data);
262 /* Add the item to the list in the correct numerical position. Fancy, eh? */
263 if (list->data) {
264 if ((new->gid < list->data->gid) || ((new->gid == list->data->gid) && (new->bid < list->data->bid))) {
265 new->next = list->data;
266 list->data = new;
267 } else {
268 struct aim_ssi_item *prev;
269 for ((prev=list->data, cur=list->data->next); (cur && ((new->gid > cur->gid) || ((new->gid == cur->gid) && (new->bid > cur->bid)))); prev=cur, cur=cur->next);
270 new->next = prev->next;
271 prev->next = new;
273 } else {
274 new->next = list->data;
275 list->data = new;
278 return new;
282 * Locally delete an item from the given item list.
284 * @param list A pointer to a pointer to the current list of items.
285 * @param del A pointer to the item you want to remove from the list.
286 * @return Return 0 if no errors, otherwise return the error number.
288 static int aim_ssi_itemlist_del(struct aim_ssi_itemlist *list, struct aim_ssi_item *del)
290 gchar key[3000];
292 if (!(list->data) || !del)
293 return -EINVAL;
295 /* Remove the item from the list */
296 if (list->data == del) {
297 list->data = list->data->next;
298 } else {
299 struct aim_ssi_item *cur;
300 for (cur=list->data; (cur->next && (cur->next!=del)); cur=cur->next);
301 if (cur->next)
302 cur->next = del->next;
305 /* Remove from the hashtables */
306 g_hash_table_remove(list->idx_gid_bid, GINT_TO_POINTER((del->gid << 16) + del->bid));
308 snprintf(key, sizeof(key), "%hx%s", del->type, oscar_normalize(NULL, del->name));
309 g_hash_table_remove(list->idx_all_named_items, key);
311 /* Free the removed item */
312 aim_ssi_item_free(del);
314 return 0;
318 * Compare two items to see if they have the same data.
320 * @param cur1 A pointer to a pointer to the first item.
321 * @param cur2 A pointer to a pointer to the second item.
322 * @return Return 0 if no differences, or a number if there are differences.
324 static int aim_ssi_itemlist_cmp(struct aim_ssi_item *cur1, struct aim_ssi_item *cur2)
326 if (!cur1 || !cur2)
327 return 1;
329 if (cur1->data && !cur2->data)
330 return 2;
332 if (!cur1->data && cur2->data)
333 return 3;
335 if ((cur1->data && cur2->data) && (aim_tlvlist_cmp(cur1->data, cur2->data)))
336 return 4;
338 if (cur1->name && !cur2->name)
339 return 5;
341 if (!cur1->name && cur2->name)
342 return 6;
344 if (cur1->name && cur2->name && oscar_util_name_compare(cur1->name, cur2->name))
345 return 7;
347 if (cur1->gid != cur2->gid)
348 return 8;
350 if (cur1->bid != cur2->bid)
351 return 9;
353 if (cur1->type != cur2->type)
354 return 10;
356 return 0;
359 static gboolean aim_ssi_itemlist_valid(struct aim_ssi_itemlist *list, struct aim_ssi_item *item)
361 struct aim_ssi_item *cur;
362 for (cur=list->data; cur; cur=cur->next)
363 if (cur == item)
364 return TRUE;
365 return FALSE;
369 * Locally find an item given a group ID# and a buddy ID#.
371 * @param list A pointer to the current list of items.
372 * @param gid The group ID# of the desired item.
373 * @param bid The buddy ID# of the desired item.
374 * @return Return a pointer to the item if found, else return NULL;
376 struct aim_ssi_item *aim_ssi_itemlist_find(struct aim_ssi_itemlist *list, guint16 gid, guint16 bid)
378 guint32 id_key = (gid << 16) + bid;
379 return g_hash_table_lookup(list->idx_gid_bid, GINT_TO_POINTER(id_key));
383 * Locally find an item given a group name, buddy name, and type. If group name
384 * and buddy name are null, then just return the first item of the given type.
386 * @param list A pointer to the current list of items.
387 * @param gn The group name of the desired item.
388 * @param bn The buddy name of the desired item.
389 * @param type The type of the desired item.
390 * @return Return a pointer to the item if found, else return NULL.
392 struct aim_ssi_item *aim_ssi_itemlist_finditem(struct aim_ssi_itemlist *list, const char *gn, const char *bn, guint16 type)
394 struct aim_ssi_item *cur;
395 gchar key[3000];
397 if (!list->data)
398 return NULL;
400 if (gn && bn) { /* For finding buddies in groups */
401 g_return_val_if_fail(type == AIM_SSI_TYPE_BUDDY, NULL);
402 for (cur=list->data; cur; cur=cur->next)
403 if ((cur->type == type) && (cur->name) && !(oscar_util_name_compare(cur->name, bn))) {
404 struct aim_ssi_item *curg;
405 for (curg=list->data; curg; curg=curg->next)
406 if ((curg->type == AIM_SSI_TYPE_GROUP) && (curg->gid == cur->gid) && (curg->name) && !(oscar_util_name_compare(curg->name, gn)))
407 return cur;
410 } else if (gn || bn) { /* For finding groups, permits, denies and ignores */
411 snprintf(key, sizeof(key), "%hx%s", type, oscar_normalize(NULL, gn ? gn : bn));
412 return g_hash_table_lookup(list->idx_all_named_items, key);
414 /* For stuff without names--permit deny setting, visibility mask, etc. */
415 } else for (cur=list->data; cur; cur=cur->next) {
416 if ((cur->type == type) && (!cur->name))
417 return cur;
420 return NULL;
424 * Check if the given buddy exists in any group in the buddy list.
426 * @param list A pointer to the current list of items.
427 * @param bn The group name of the desired item.
428 * @return Return a pointer to the name of the item if found, else return NULL;
430 struct aim_ssi_item *aim_ssi_itemlist_exists(struct aim_ssi_itemlist *list, const char *bn)
432 if (!bn)
433 return NULL;
434 return aim_ssi_itemlist_finditem(list, NULL, bn, AIM_SSI_TYPE_BUDDY);
438 * Locally find the parent item of the given buddy name.
440 * @param list A pointer to the current list of items.
441 * @param bn The buddy name of the desired item.
442 * @return Return a pointer to the name of the item if found, else return NULL;
444 char *aim_ssi_itemlist_findparentname(struct aim_ssi_itemlist *list, const char *bn)
446 struct aim_ssi_item *cur, *curg;
447 if (!list->data || !bn)
448 return NULL;
449 if (!(cur = aim_ssi_itemlist_exists(list, bn)))
450 return NULL;
451 if (!(curg = aim_ssi_itemlist_find(list, cur->gid, 0x0000)))
452 return NULL;
453 return curg->name;
457 * Locally find the permit/deny setting item, and return the setting.
459 * @param list A pointer to the current list of items.
460 * @return Return the current SSI permit deny setting, or 0 if no setting was found.
462 int aim_ssi_getpermdeny(struct aim_ssi_itemlist *list)
464 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PDINFO);
465 if (cur) {
466 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x00ca, 1);
467 if (tlv && tlv->value)
468 return aimutil_get8(tlv->value);
470 return 0;
474 * Locally find the presence flag item, and return the setting. The returned setting is a
475 * bitmask of the preferences. See the AIM_SSI_PRESENCE_FLAG_* #defines in oscar.h.
477 * @param list A pointer to the current list of items.
478 * @return Return the current set of preferences.
480 guint32 aim_ssi_getpresence(struct aim_ssi_itemlist *list)
482 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS);
483 if (cur) {
484 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x00c9, 1);
485 if (tlv && tlv->length)
486 return aimutil_get32(tlv->value);
488 return 0xFFFFFFFF;
492 * Locally find the alias of the given buddy.
494 * @param list A pointer to the current list of items.
495 * @param gn The group of the buddy.
496 * @param bn The name of the buddy.
497 * @return A pointer to a NULL terminated string that is the buddy's
498 * alias, or NULL if the buddy has no alias. You should free
499 * this returned value!
501 char *aim_ssi_getalias(struct aim_ssi_itemlist *list, const char *gn, const char *bn)
503 struct aim_ssi_item *item = aim_ssi_itemlist_finditem(list, gn, bn, AIM_SSI_TYPE_BUDDY);
504 if (item) {
505 return aim_ssi_getalias_from_item(item);
507 return NULL;
510 char *aim_ssi_getalias_from_item(struct aim_ssi_item *item)
512 aim_tlv_t *tlv = aim_tlv_gettlv(item->data, 0x0131, 1);
513 if (tlv && tlv->length)
514 return g_strndup((const gchar *)tlv->value, tlv->length);
515 return NULL;
519 * Locally find the comment of the given buddy.
521 * @param list A pointer to the current list of items.
522 * @param gn The group of the buddy.
523 * @param bn The name of the buddy.
524 * @return A pointer to a NULL terminated string that is the buddy's
525 * comment, or NULL if the buddy has no comment. You should free
526 * this returned value!
528 char *aim_ssi_getcomment(struct aim_ssi_itemlist *list, const char *gn, const char *bn)
530 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, bn, AIM_SSI_TYPE_BUDDY);
531 if (cur) {
532 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x013c, 1);
533 if (tlv && tlv->length) {
534 return g_strndup((const gchar *)tlv->value, tlv->length);
537 return NULL;
541 * Locally find if you are waiting for authorization for a buddy.
543 * @param list A pointer to the current list of items.
544 * @param gn The group of the buddy.
545 * @param bn The name of the buddy.
546 * @return 1 if you are waiting for authorization; 0 if you are not
548 gboolean aim_ssi_waitingforauth(struct aim_ssi_itemlist *list, const char *gn, const char *bn)
550 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, bn, AIM_SSI_TYPE_BUDDY);
551 if (cur) {
552 if (aim_tlv_gettlv(cur->data, 0x0066, 1))
553 return TRUE;
555 return FALSE;
559 * If there are changes, then create temporary items and
560 * call addmoddel.
562 * @param od The oscar session.
563 * @return Return 0 if no errors, otherwise return the error number.
565 static int aim_ssi_sync(OscarData *od)
567 struct aim_ssi_item *cur1, *cur2;
568 struct aim_ssi_tmp *cur, *new;
569 int n = 0;
570 GString *debugstr = g_string_new("");
573 * The variable "n" is used to limit the number of addmoddel's that
574 * are performed in a single SNAC. It will hopefully keep the size
575 * of the SNAC below the maximum SNAC size.
578 if (!od)
579 return -EINVAL;
581 /* If we're waiting for an ack, we shouldn't do anything else */
582 if (od->ssi.waiting_for_ack)
583 return 0;
586 * Compare the 2 lists and create an aim_ssi_tmp for each difference.
587 * We should only send either additions, modifications, or deletions
588 * before waiting for an acknowledgement. So first do deletions, then
589 * additions, then modifications. Also, both the official and the local
590 * list should be in ascending numerical order for the group ID#s and the
591 * buddy ID#s, which makes things more efficient. I think.
594 /* Deletions */
595 if (!od->ssi.pending) {
596 for (cur1=od->ssi.official.data; cur1 && (n < 15); cur1=cur1->next) {
597 if (!aim_ssi_itemlist_find(&od->ssi.local, cur1->gid, cur1->bid)) {
598 n++;
599 new = g_new(struct aim_ssi_tmp, 1);
600 new->action = SNAC_SUBTYPE_FEEDBAG_DEL;
601 new->ack = 0xffff;
602 new->name = NULL;
603 new->item = cur1;
604 new->next = NULL;
605 if (od->ssi.pending) {
606 for (cur=od->ssi.pending; cur->next; cur=cur->next);
607 cur->next = new;
608 } else {
609 od->ssi.pending = new;
611 aim_ssi_item_debug_append(debugstr, "Deleting item ", cur1);
616 /* Additions */
617 if (!od->ssi.pending) {
618 for (cur1=od->ssi.local.data; cur1 && (n < 15); cur1=cur1->next) {
619 if (!aim_ssi_itemlist_find(&od->ssi.official, cur1->gid, cur1->bid)) {
620 n++;
621 new = g_new(struct aim_ssi_tmp, 1);
622 new->action = SNAC_SUBTYPE_FEEDBAG_ADD;
623 new->ack = 0xffff;
624 new->name = NULL;
625 new->item = cur1;
626 new->next = NULL;
627 if (od->ssi.pending) {
628 for (cur=od->ssi.pending; cur->next; cur=cur->next);
629 cur->next = new;
630 } else {
631 od->ssi.pending = new;
633 aim_ssi_item_debug_append(debugstr, "Adding item ", cur1);
638 /* Modifications */
639 if (!od->ssi.pending) {
640 for (cur1=od->ssi.local.data; cur1 && (n < 15); cur1=cur1->next) {
641 cur2 = aim_ssi_itemlist_find(&od->ssi.official, cur1->gid, cur1->bid);
642 if (cur2 && (aim_ssi_itemlist_cmp(cur1, cur2))) {
643 n++;
644 new = g_new(struct aim_ssi_tmp, 1);
645 new->action = SNAC_SUBTYPE_FEEDBAG_MOD;
646 new->ack = 0xffff;
647 new->name = NULL;
648 new->item = cur1;
649 new->next = NULL;
650 if (od->ssi.pending) {
651 for (cur=od->ssi.pending; cur->next; cur=cur->next);
652 cur->next = new;
653 } else {
654 od->ssi.pending = new;
656 aim_ssi_item_debug_append(debugstr, "Modifying item ", cur1);
660 if (debugstr->len > 0) {
661 purple_debug_info("oscar", "%s", debugstr->str);
662 if (purple_debug_is_verbose()) {
663 PurpleAccount *account = purple_connection_get_account(od->gc);
664 g_string_truncate(debugstr, 0);
665 for (cur1 = od->ssi.local.data; cur1; cur1 = cur1->next) {
666 aim_ssi_item_debug_append(debugstr, "\t", cur1);
668 purple_debug_misc("oscar", "Dumping item list of account %s:\n%s",
669 purple_account_get_username(account), debugstr->str);
672 g_string_free(debugstr, TRUE);
674 /* We're out of stuff to do, so tell the AIM servers we're done and exit */
675 if (!od->ssi.pending) {
676 if (od->ssi.in_transaction) {
677 aim_ssi_modend(od);
678 od->ssi.in_transaction = FALSE;
680 return 0;
683 /* If this is the first in a series of add/mod/del
684 * requests then send the "begin transaction" message. */
685 if (!od->ssi.in_transaction)
687 aim_ssi_modbegin(od);
688 od->ssi.in_transaction = TRUE;
691 /* Make sure we don't send anything else between now
692 * and when we receive the ack for the following operation */
693 od->ssi.waiting_for_ack = TRUE;
695 /* Now go mail off our data and wait 4 to 6 weeks */
696 return aim_ssi_addmoddel(od);;
700 * Free all SSI data.
702 * This doesn't remove it from the server, that's different.
704 * @param od The oscar odion.
705 * @return Return 0 if no errors, otherwise return the error number.
707 static void
708 aim_ssi_freelist(OscarData *od)
710 struct aim_ssi_item *cur, *del;
711 struct aim_ssi_tmp *curtmp, *deltmp;
713 cur = od->ssi.official.data;
714 while (cur) {
715 del = cur;
716 cur = cur->next;
717 aim_ssi_item_free(del);
720 cur = od->ssi.local.data;
721 while (cur) {
722 del = cur;
723 cur = cur->next;
724 aim_ssi_item_free(del);
727 curtmp = od->ssi.pending;
728 while (curtmp) {
729 deltmp = curtmp;
730 curtmp = curtmp->next;
731 g_free(deltmp);
734 od->ssi.numitems = 0;
735 od->ssi.official.data = NULL;
736 od->ssi.local.data = NULL;
737 od->ssi.pending = NULL;
738 od->ssi.timestamp = (time_t)0;
742 * Look up the given TLV type in the item's data. If the value of
743 * the TLV is not a valid UTF-8 string then use purple_utf8_salvage()
744 * to replace invalid bytes with question marks.
746 static void cleanlist_ensure_utf8_data(struct aim_ssi_item *item, guint16 tlvtype)
748 aim_tlv_t *tlv;
749 gchar *value, *salvaged;
751 tlv = aim_tlv_gettlv(item->data, tlvtype, 1);
752 if (tlv && tlv->length && !g_utf8_validate((const gchar *)tlv->value, tlv->length, NULL)) {
753 purple_debug_warning("oscar", "cleanlist found invalid UTF-8 "
754 "for 0x%04hx field of 0x%04hx item with name %s. "
755 "Attempting to repair.\n",
756 tlvtype, item->type, item->name ? item->name : "(null)");
757 value = g_strndup((const gchar *)tlv->value, tlv->length);
758 salvaged = purple_utf8_salvage(value);
759 g_free(value);
760 if (*salvaged)
761 aim_tlvlist_replace_str(&item->data, tlvtype, salvaged);
762 else
763 aim_tlvlist_remove(&item->data, tlvtype);
764 g_free(salvaged);
769 * This "cleans" the ssi list. It does things like:
770 * - Makes sure all buddies, permits, and denies have names
771 * - Makes sure all buddies are in a group that exist
772 * - Makes sure strings are valid UTF-8
774 * @param od The oscar odion.
775 * @return Return 0 if no errors, otherwise return the error number.
777 static int aim_ssi_cleanlist(OscarData *od)
779 struct aim_ssi_item *cur, *next;
781 if (!od)
782 return -EINVAL;
784 /* Delete any buddies, permits, or denies with empty names. */
785 /* If there are any buddies directly in the master group, add them to a real group. */
786 /* DESTROY any buddies that are directly in the master group. */
787 /* Do the same for buddies that are in a non-existant group. */
788 /* This will kind of mess up if you hit the item limit, but this function isn't too critical */
789 cur = od->ssi.local.data;
790 while (cur) {
791 next = cur->next;
792 if (!cur->name) {
793 if (cur->type == AIM_SSI_TYPE_BUDDY)
794 aim_ssi_delbuddy(od, NULL, NULL);
795 else if (cur->type == AIM_SSI_TYPE_PERMIT || cur->type == AIM_SSI_TYPE_DENY || cur->type == AIM_SSI_TYPE_ICQDENY)
796 aim_ssi_del_from_private_list(od, NULL, cur->type);
797 } else if ((cur->type == AIM_SSI_TYPE_BUDDY) && ((cur->gid == 0x0000) || (!aim_ssi_itemlist_find(&od->ssi.local, cur->gid, 0x0000)))) {
798 char *alias = aim_ssi_getalias(&od->ssi.local, NULL, cur->name);
799 aim_ssi_addbuddy(od, cur->name, PURPLE_BLIST_DEFAULT_GROUP_NAME,
800 NULL, alias, NULL, NULL, FALSE);
801 aim_ssi_delbuddy(od, cur->name, NULL);
802 g_free(alias);
804 cur = next;
807 cur = od->ssi.local.data;
808 while (cur) {
809 if ((cur->type == AIM_SSI_TYPE_BUDDY) || (cur->type == AIM_SSI_TYPE_PERMIT) || (cur->type == AIM_SSI_TYPE_DENY))
811 struct aim_ssi_item *cur2, *next2;
813 /* Make sure there aren't any duplicate permits or denies, or
814 duplicate buddies within a group */
815 cur2 = cur->next;
816 while (cur2) {
817 next2 = cur2->next;
818 if (cur->type == cur2->type
819 && cur->gid == cur2->gid
820 && cur->name
821 && cur2->name
822 && !oscar_util_name_compare(cur->name, cur2->name))
824 aim_ssi_itemlist_del(&od->ssi.local, cur2);
826 cur2 = next2;
829 /* Make sure alias is valid UTF-8 */
830 cleanlist_ensure_utf8_data(cur, 0x0131);
832 /* Make sure comment is valid UTF-8 */
833 cleanlist_ensure_utf8_data(cur, 0x013c);
835 cur = cur->next;
838 /* If we've made any changes then sync our list with the server's */
839 return aim_ssi_sync(od);
843 * Add a buddy to the list.
845 * @param od The oscar odion.
846 * @param name The name of the item.
847 * @param group The group of the item.
848 * @param data A TLV list to use as the additional data for this item.
849 * @param alias The alias/nickname of the item, or NULL.
850 * @param comment The buddy comment for the item, or NULL.
851 * @param smsnum The locally assigned SMS number, or NULL.
852 * @return Return 0 if no errors, otherwise return the error number.
854 int aim_ssi_addbuddy(OscarData *od, const char *name, const char *group, GSList *data, const char *alias, const char *comment, const char *smsnum, gboolean needauth)
856 struct aim_ssi_item *parent;
858 if (!od || !name || !group)
859 return -EINVAL;
861 /* Find the parent */
862 if (!(parent = aim_ssi_itemlist_finditem(&od->ssi.local, group, NULL, AIM_SSI_TYPE_GROUP))) {
863 /* Find the parent's parent (the master group) */
864 if (aim_ssi_itemlist_find(&od->ssi.local, 0x0000, 0x0000) == NULL)
865 aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP, NULL);
867 /* Add the parent */
868 parent = aim_ssi_itemlist_add(&od->ssi.local, group, 0xFFFF, 0x0000, AIM_SSI_TYPE_GROUP, NULL);
870 /* Modify the parent's parent (the master group) */
871 aim_ssi_itemlist_rebuildgroup(&od->ssi.local, NULL);
874 /* Create a TLV list for the new buddy */
875 if (needauth)
876 aim_tlvlist_add_noval(&data, 0x0066);
877 if (alias != NULL)
878 aim_tlvlist_add_str(&data, 0x0131, alias);
879 if (smsnum != NULL)
880 aim_tlvlist_add_str(&data, 0x013a, smsnum);
881 if (comment != NULL)
882 aim_tlvlist_add_str(&data, 0x013c, comment);
884 /* Add that bad boy */
885 aim_ssi_itemlist_add(&od->ssi.local, name, parent->gid, 0xFFFF, AIM_SSI_TYPE_BUDDY, data);
886 aim_tlvlist_free(data);
888 /* Modify the parent group */
889 aim_ssi_itemlist_rebuildgroup(&od->ssi.local, group);
891 /* Sync our local list with the server list */
892 return aim_ssi_sync(od);
896 aim_ssi_add_to_private_list(OscarData *od, const char* name, guint16 list_type)
898 if (!od || !name || !od->ssi.received_data)
899 return -EINVAL;
901 if (aim_ssi_itemlist_find(&od->ssi.local, 0x0000, 0x0000) == NULL)
902 aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP, NULL);
904 aim_ssi_itemlist_add(&od->ssi.local, name, 0x0000, 0xFFFF, list_type, NULL);
905 return aim_ssi_sync(od);
909 aim_ssi_del_from_private_list(OscarData* od, const char* name, guint16 list_type)
911 struct aim_ssi_item *del;
913 if (!od)
914 return -EINVAL;
916 if (!(del = aim_ssi_itemlist_finditem(&od->ssi.local, NULL, name, list_type)))
917 return -EINVAL;
919 aim_ssi_itemlist_del(&od->ssi.local, del);
920 return aim_ssi_sync(od);
924 * Deletes a buddy from the list.
926 * @param od The oscar odion.
927 * @param name The name of the item, or NULL.
928 * @param group The group of the item, or NULL.
929 * @return Return 0 if no errors, otherwise return the error number.
931 int aim_ssi_delbuddy(OscarData *od, const char *name, const char *group)
933 struct aim_ssi_item *del;
935 if (!od)
936 return -EINVAL;
938 /* Find the buddy */
939 if (!(del = aim_ssi_itemlist_finditem(&od->ssi.local, group, name, AIM_SSI_TYPE_BUDDY)))
940 return -EINVAL;
942 /* Remove the item from the list */
943 aim_ssi_itemlist_del(&od->ssi.local, del);
945 /* Modify the parent group */
946 aim_ssi_itemlist_rebuildgroup(&od->ssi.local, group);
948 /* Sync our local list with the server list */
949 return aim_ssi_sync(od);
953 * Deletes a group from the list.
955 * @param od The oscar odion.
956 * @param group The name of the group.
957 * @return Return 0 if no errors, otherwise return the error number.
959 int aim_ssi_delgroup(OscarData *od, const char *group)
961 struct aim_ssi_item *del;
962 aim_tlv_t *tlv;
964 if (!od)
965 return -EINVAL;
967 /* Find the group */
968 if (!(del = aim_ssi_itemlist_finditem(&od->ssi.local, group, NULL, AIM_SSI_TYPE_GROUP)))
969 return -EINVAL;
971 /* Don't delete the group if it's not empty */
972 tlv = aim_tlv_gettlv(del->data, 0x00c8, 1);
973 if (tlv && tlv->length > 0)
974 return -EINVAL;
976 /* Remove the item from the list */
977 aim_ssi_itemlist_del(&od->ssi.local, del);
979 /* Modify the parent group */
980 aim_ssi_itemlist_rebuildgroup(&od->ssi.local, NULL);
982 /* Sync our local list with the server list */
983 return aim_ssi_sync(od);
987 * Move a buddy from one group to another group. This basically just deletes the
988 * buddy and re-adds it.
990 * @param od The oscar odion.
991 * @param oldgn The group that the buddy is currently in.
992 * @param newgn The group that the buddy should be moved in to.
993 * @param bn The name of the buddy to be moved.
994 * @return Return 0 if no errors, otherwise return the error number.
996 int aim_ssi_movebuddy(OscarData *od, const char *oldgn, const char *newgn, const char *bn)
998 struct aim_ssi_item *buddy;
999 GSList *data;
1001 /* Find the buddy */
1002 buddy = aim_ssi_itemlist_finditem(&od->ssi.local, oldgn, bn, AIM_SSI_TYPE_BUDDY);
1003 if (buddy == NULL)
1004 return -EINVAL;
1006 /* Make a copy of the buddy's TLV list */
1007 data = aim_tlvlist_copy(buddy->data);
1009 /* Delete the old item */
1010 aim_ssi_delbuddy(od, bn, oldgn);
1012 /* Add the new item using the EXACT SAME TLV list */
1013 aim_ssi_addbuddy(od, bn, newgn, data, NULL, NULL, NULL, FALSE);
1015 return 0;
1019 * Change the alias stored on the server for a given buddy.
1021 * @param od The oscar odion.
1022 * @param gn The group that the buddy is currently in.
1023 * @param bn The name of the buddy.
1024 * @param alias The new alias for the buddy, or NULL if you want to remove
1025 * a buddy's comment.
1026 * @return Return 0 if no errors, otherwise return the error number.
1028 int aim_ssi_aliasbuddy(OscarData *od, const char *gn, const char *bn, const char *alias)
1030 struct aim_ssi_item *tmp;
1032 if (!od || !gn || !bn)
1033 return -EINVAL;
1035 if (!(tmp = aim_ssi_itemlist_finditem(&od->ssi.local, gn, bn, AIM_SSI_TYPE_BUDDY)))
1036 return -EINVAL;
1038 /* Either add or remove the 0x0131 TLV from the TLV chain */
1039 if (alias && *alias)
1040 aim_tlvlist_replace_str(&tmp->data, 0x0131, alias);
1041 else
1042 aim_tlvlist_remove(&tmp->data, 0x0131);
1044 /* Sync our local list with the server list */
1045 return aim_ssi_sync(od);
1049 * Change the comment stored on the server for a given buddy.
1051 * @param od The oscar odion.
1052 * @param gn The group that the buddy is currently in.
1053 * @param bn The name of the buddy.
1054 * @param alias The new comment for the buddy, or NULL if you want to remove
1055 * a buddy's comment.
1056 * @return Return 0 if no errors, otherwise return the error number.
1058 int aim_ssi_editcomment(OscarData *od, const char *gn, const char *bn, const char *comment)
1060 struct aim_ssi_item *tmp;
1062 if (!od || !gn || !bn)
1063 return -EINVAL;
1065 if (!(tmp = aim_ssi_itemlist_finditem(&od->ssi.local, gn, bn, AIM_SSI_TYPE_BUDDY)))
1066 return -EINVAL;
1068 /* Either add or remove the 0x0131 TLV from the TLV chain */
1069 if (comment && *comment)
1070 aim_tlvlist_replace_str(&tmp->data, 0x013c, comment);
1071 else
1072 aim_tlvlist_remove(&tmp->data, 0x013c);
1074 /* Sync our local list with the server list */
1075 return aim_ssi_sync(od);
1079 * Rename a group.
1081 * @param od The oscar odion.
1082 * @param oldgn The old group name.
1083 * @param newgn The new group name.
1084 * @return Return 0 if no errors, otherwise return the error number.
1086 int aim_ssi_rename_group(OscarData *od, const char *oldgn, const char *newgn)
1088 struct aim_ssi_item *group;
1090 if (!od || !oldgn || !newgn)
1091 return -EINVAL;
1093 if (!(group = aim_ssi_itemlist_finditem(&od->ssi.local, oldgn, NULL, AIM_SSI_TYPE_GROUP)))
1094 return -EINVAL;
1096 aim_ssi_item_set_name(&od->ssi.local, group, newgn);
1098 /* Sync our local list with the server list */
1099 return aim_ssi_sync(od);
1103 * Stores your permit/deny setting on the server, and starts using it.
1105 * @param od The oscar odion.
1106 * @param permdeny Your permit/deny setting. For ICQ accounts, it actually affects your visibility
1107 * and has nothing to do with blocking. Can be one of the following:
1108 * 1 - Allow all users
1109 * 2 - Block all users
1110 * 3 - Allow only the users below
1111 * 4 - Block only the users below
1112 * 5 - Allow only users on my buddy list
1113 * @return Return 0 if no errors, otherwise return the error number.
1115 int aim_ssi_setpermdeny(OscarData *od, guint8 permdeny)
1117 struct aim_ssi_item *tmp;
1119 if (!od || !od->ssi.received_data)
1120 return -EINVAL;
1122 /* Find the PDINFO item, or add it if it does not exist */
1123 if (!(tmp = aim_ssi_itemlist_finditem(&od->ssi.local, NULL, NULL, AIM_SSI_TYPE_PDINFO))) {
1124 /* Make sure the master group exists */
1125 if (aim_ssi_itemlist_find(&od->ssi.local, 0x0000, 0x0000) == NULL)
1126 aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP, NULL);
1128 tmp = aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PDINFO, NULL);
1131 /* Need to add the 0x00ca TLV to the TLV chain */
1132 aim_tlvlist_replace_8(&tmp->data, 0x00ca, permdeny);
1134 /* Sync our local list with the server list */
1135 return aim_ssi_sync(od);
1139 * Set buddy icon information
1141 * @param od The oscar odion.
1142 * @param iconcsum The MD5 checksum of the icon you are using.
1143 * @param iconcsumlen Length of the MD5 checksum given above. Should be 0x10 bytes.
1144 * @return Return 0 if no errors, otherwise return the error number.
1146 int aim_ssi_seticon(OscarData *od, const guint8 *iconsum, guint8 iconsumlen)
1148 struct aim_ssi_item *tmp;
1149 guint8 *csumdata;
1151 if (!od || !iconsum || !iconsumlen || !od->ssi.received_data)
1152 return -EINVAL;
1154 /* Find the ICONINFO item, or add it if it does not exist */
1155 if (!(tmp = aim_ssi_itemlist_finditem(&od->ssi.local, NULL, "1", AIM_SSI_TYPE_ICONINFO))) {
1156 /* Make sure the master group exists */
1157 if (aim_ssi_itemlist_find(&od->ssi.local, 0x0000, 0x0000) == NULL)
1158 aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP, NULL);
1160 tmp = aim_ssi_itemlist_add(&od->ssi.local, "1", 0x0000, 0xFFFF, AIM_SSI_TYPE_ICONINFO, NULL);
1163 /* Need to add the 0x00d5 TLV to the TLV chain */
1164 csumdata = (guint8 *)g_malloc((iconsumlen+2)*sizeof(guint8));
1165 (void)aimutil_put8(&csumdata[0], 0x00);
1166 (void)aimutil_put8(&csumdata[1], iconsumlen);
1167 memcpy(&csumdata[2], iconsum, iconsumlen);
1168 aim_tlvlist_replace_raw(&tmp->data, 0x00d5, (iconsumlen+2) * sizeof(guint8), csumdata);
1169 g_free(csumdata);
1171 /* Need to add the 0x0131 TLV to the TLV chain, used to cache the icon */
1172 aim_tlvlist_replace_noval(&tmp->data, 0x0131);
1174 /* Sync our local list with the server list */
1175 aim_ssi_sync(od);
1176 return 0;
1180 * Remove a reference to a server stored buddy icon. This will make your
1181 * icon stop showing up to other people.
1183 * Really this function just sets the icon to a dummy value. It's weird...
1184 * but I think the dummy value basically means "I don't have an icon!"
1186 * @param od The oscar session.
1187 * @return Return 0 if no errors, otherwise return the error number.
1189 int aim_ssi_delicon(OscarData *od)
1191 const guint8 csumdata[] = {0x02, 0x01, 0xd2, 0x04, 0x72};
1193 return aim_ssi_seticon(od, csumdata, 5);
1197 * Stores your setting for various SSI settings. Whether you
1198 * should show up as idle or not, etc.
1200 * @param od The oscar odion.
1201 * @param presence A bitmask of the first 32 entries [0-31] from
1202 * http://dev.aol.com/aim/oscar/#FEEDBAG__BUDDY_PREFS
1203 * 0x00000002 - Hide "eBuddy group" (whatever that is)
1204 * 0x00000400 - Allow others to see your idle time
1205 * 0x00020000 - Don't show Recent Buddies
1206 * @return Return 0 if no errors, otherwise return the error number.
1208 int aim_ssi_setpresence(OscarData *od, guint32 presence) {
1209 struct aim_ssi_item *tmp;
1211 if (!od || !od->ssi.received_data)
1212 return -EINVAL;
1214 /* Find the PRESENCEPREFS item, or add it if it does not exist */
1215 if (!(tmp = aim_ssi_itemlist_finditem(&od->ssi.local, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS))) {
1216 /* Make sure the master group exists */
1217 if (aim_ssi_itemlist_find(&od->ssi.local, 0x0000, 0x0000) == NULL)
1218 aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP, NULL);
1220 tmp = aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PRESENCEPREFS, NULL);
1223 /* Need to add the x00c9 TLV to the TLV chain */
1224 aim_tlvlist_replace_32(&tmp->data, 0x00c9, presence);
1226 /* Sync our local list with the server list */
1227 return aim_ssi_sync(od);
1231 * Subtype 0x0002 - Request SSI Rights.
1233 int aim_ssi_reqrights(OscarData *od)
1235 FlapConnection *conn;
1237 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1238 return -EINVAL;
1240 aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_REQRIGHTS);
1242 return 0;
1246 * Subtype 0x0003 - SSI Rights Information.
1248 static int parserights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1250 int ret = 0, i;
1251 aim_rxcallback_t userfunc;
1252 GSList *tlvlist;
1253 aim_tlv_t *tlv;
1254 ByteStream bstream;
1255 guint16 *maxitems;
1257 /* This SNAC is made up of a bunch of TLVs */
1258 tlvlist = aim_tlvlist_read(bs);
1260 /* TLV 0x0004 contains the maximum number of each item */
1261 if (!(tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
1262 aim_tlvlist_free(tlvlist);
1263 return 0;
1266 byte_stream_init(&bstream, tlv->value, tlv->length);
1268 maxitems = (guint16 *)g_malloc((tlv->length/2)*sizeof(guint16));
1270 for (i=0; i<(tlv->length/2); i++)
1271 maxitems[i] = byte_stream_get16(&bstream);
1273 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1274 ret = userfunc(od, conn, frame, tlv->length/2, maxitems);
1276 aim_tlvlist_free(tlvlist);
1277 g_free(maxitems);
1279 return ret;
1283 * Subtype 0x0004 - Request SSI Data when you don't have a timestamp and
1284 * revision number.
1287 int aim_ssi_reqdata(OscarData *od)
1289 FlapConnection *conn;
1291 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1292 return -EINVAL;
1294 /* Free any current data, just in case */
1295 aim_ssi_freelist(od);
1297 aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_REQDATA);
1299 return 0;
1303 * Subtype 0x0006 - SSI Data.
1305 static int parsedata(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1307 int ret = 0;
1308 aim_rxcallback_t userfunc;
1309 guint8 fmtver; /* guess */
1310 guint16 namelen, gid, bid, type;
1311 char *name;
1312 GSList *data;
1313 GString *debugstr = g_string_new("");
1315 fmtver = byte_stream_get8(bs); /* Version of ssi data. Should be 0x00 */
1316 od->ssi.numitems += byte_stream_get16(bs); /* # of items in this SSI SNAC */
1318 /* Read in the list */
1319 while (byte_stream_bytes_left(bs) > 4) { /* last four bytes are timestamp */
1320 if ((namelen = byte_stream_get16(bs)))
1321 name = byte_stream_getstr(bs, namelen);
1322 else
1323 name = NULL;
1324 gid = byte_stream_get16(bs);
1325 bid = byte_stream_get16(bs);
1326 type = byte_stream_get16(bs);
1327 data = aim_tlvlist_readlen(bs, byte_stream_get16(bs));
1328 aim_ssi_item_debug_append(debugstr, "\t", aim_ssi_itemlist_add(&od->ssi.official, name, gid, bid, type, data));
1329 g_free(name);
1330 aim_tlvlist_free(data);
1332 purple_debug_misc("oscar", "Reading items from tlvlist for account %s:\n%s",
1333 purple_account_get_username(purple_connection_get_account(od->gc)), debugstr->str);
1334 g_string_free(debugstr, TRUE);
1336 /* Read in the timestamp */
1337 od->ssi.timestamp = byte_stream_get32(bs);
1339 if (!(snac->flags & 0x0001)) {
1340 /* Make a copy of the list */
1341 struct aim_ssi_item *cur;
1342 for (cur=od->ssi.official.data; cur; cur=cur->next)
1343 aim_ssi_itemlist_add(&od->ssi.local, cur->name, cur->gid, cur->bid, cur->type, cur->data);
1345 /* Clean the buddy list */
1346 aim_ssi_cleanlist(od);
1348 od->ssi.received_data = TRUE;
1350 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1351 ret = userfunc(od, conn, frame, fmtver, od->ssi.numitems, od->ssi.timestamp);
1354 return ret;
1358 * Subtype 0x0007 - SSI Activate Data.
1360 * Should be sent after receiving 13/6 or 13/f to tell the server you
1361 * are ready to begin using the list. It will promptly give you the
1362 * presence information for everyone in your list and put your permit/deny
1363 * settings into effect.
1366 int aim_ssi_enable(OscarData *od)
1368 FlapConnection *conn;
1370 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1371 return -EINVAL;
1373 aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, 0x0007);
1375 return 0;
1379 * Subtype 0x0008/0x0009/0x000a - SSI Add/Mod/Del Item(s).
1381 * Sends the SNAC to add, modify, or delete items from the server-stored
1382 * information. These 3 SNACs all have an identical structure. The only
1383 * difference is the subtype that is set for the SNAC.
1386 static int aim_ssi_addmoddel(OscarData *od)
1388 FlapConnection *conn;
1389 ByteStream bs;
1390 aim_snacid_t snacid;
1391 int bslen;
1392 struct aim_ssi_tmp *cur;
1394 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !od->ssi.pending || !od->ssi.pending->item)
1395 return -EINVAL;
1397 /* Calculate total SNAC size */
1398 bslen = 0;
1399 for (cur=od->ssi.pending; cur; cur=cur->next) {
1400 bslen += 10; /* For length, GID, BID, type, and length */
1401 if (cur->item->name)
1402 bslen += strlen(cur->item->name);
1403 if (cur->item->data)
1404 bslen += aim_tlvlist_size(cur->item->data);
1407 byte_stream_new(&bs, bslen);
1409 for (cur=od->ssi.pending; cur; cur=cur->next) {
1410 byte_stream_put16(&bs, cur->item->name ? strlen(cur->item->name) : 0);
1411 if (cur->item->name)
1412 byte_stream_putstr(&bs, cur->item->name);
1413 byte_stream_put16(&bs, cur->item->gid);
1414 byte_stream_put16(&bs, cur->item->bid);
1415 byte_stream_put16(&bs, cur->item->type);
1416 byte_stream_put16(&bs, cur->item->data ? aim_tlvlist_size(cur->item->data) : 0);
1417 if (cur->item->data)
1418 aim_tlvlist_write(&bs, &cur->item->data);
1421 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, od->ssi.pending->action, 0x0000, NULL, 0);
1422 flap_connection_send_snac(od, conn, SNAC_FAMILY_FEEDBAG, od->ssi.pending->action, snacid, &bs);
1424 byte_stream_destroy(&bs);
1426 return 0;
1430 * Subtype 0x0008 - Incoming SSI add.
1432 * Sent by the server, for example, when someone is added to
1433 * your "Recent Buddies" group.
1435 static int parseadd(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1437 int ret = 0;
1438 aim_rxcallback_t userfunc;
1439 char *name;
1440 guint16 len, gid, bid, type;
1441 GSList *data;
1443 while (byte_stream_bytes_left(bs)) {
1444 if ((len = byte_stream_get16(bs)))
1445 name = byte_stream_getstr(bs, len);
1446 else
1447 name = NULL;
1448 gid = byte_stream_get16(bs);
1449 bid = byte_stream_get16(bs);
1450 type = byte_stream_get16(bs);
1451 if ((len = byte_stream_get16(bs)))
1452 data = aim_tlvlist_readlen(bs, len);
1453 else
1454 data = NULL;
1456 aim_ssi_itemlist_add(&od->ssi.local, name, gid, bid, type, data);
1457 aim_ssi_itemlist_add(&od->ssi.official, name, gid, bid, type, data);
1458 aim_tlvlist_free(data);
1460 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1461 ret = userfunc(od, conn, frame, snac->subtype, type, name);
1463 g_free(name);
1466 return ret;
1470 * Subtype 0x0009 - Incoming SSI mod.
1472 static int parsemod(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1474 int ret = 0;
1475 aim_rxcallback_t userfunc;
1476 char *name;
1477 guint16 len, gid, bid, type;
1478 GSList *data;
1479 struct aim_ssi_item *item;
1481 while (byte_stream_bytes_left(bs)) {
1482 if ((len = byte_stream_get16(bs)))
1483 name = byte_stream_getstr(bs, len);
1484 else
1485 name = NULL;
1486 gid = byte_stream_get16(bs);
1487 bid = byte_stream_get16(bs);
1488 type = byte_stream_get16(bs);
1489 if ((len = byte_stream_get16(bs)))
1490 data = aim_tlvlist_readlen(bs, len);
1491 else
1492 data = NULL;
1494 /* Replace the 2 local items with the given one */
1495 if ((item = aim_ssi_itemlist_find(&od->ssi.local, gid, bid))) {
1496 item->type = type;
1497 aim_ssi_item_set_name(&od->ssi.local, item, name);
1498 aim_tlvlist_free(item->data);
1499 item->data = aim_tlvlist_copy(data);
1502 if ((item = aim_ssi_itemlist_find(&od->ssi.official, gid, bid))) {
1503 item->type = type;
1504 aim_ssi_item_set_name(&od->ssi.official, item, name);
1505 aim_tlvlist_free(item->data);
1506 item->data = aim_tlvlist_copy(data);
1509 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1510 ret = userfunc(od, conn, frame, snac->subtype, type, name);
1512 g_free(name);
1513 aim_tlvlist_free(data);
1516 return ret;
1520 * Subtype 0x000a - Incoming SSI del.
1522 * XXX - It would probably be good for the client to actually do something when it gets this.
1524 static int parsedel(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1526 int ret = 0;
1527 aim_rxcallback_t userfunc;
1528 guint16 gid, bid;
1529 struct aim_ssi_item *del;
1531 while (byte_stream_bytes_left(bs)) {
1532 byte_stream_advance(bs, byte_stream_get16(bs));
1533 gid = byte_stream_get16(bs);
1534 bid = byte_stream_get16(bs);
1535 byte_stream_get16(bs);
1536 byte_stream_advance(bs, byte_stream_get16(bs));
1538 if ((del = aim_ssi_itemlist_find(&od->ssi.local, gid, bid)))
1539 aim_ssi_itemlist_del(&od->ssi.local, del);
1540 if ((del = aim_ssi_itemlist_find(&od->ssi.official, gid, bid)))
1541 aim_ssi_itemlist_del(&od->ssi.official, del);
1543 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1544 ret = userfunc(od, conn, frame);
1547 return ret;
1551 * Subtype 0x000e - SSI Add/Mod/Del Ack.
1553 * Response to add, modify, or delete SNAC (sent with aim_ssi_addmoddel).
1556 static int parseack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1558 int ret = 0;
1559 aim_rxcallback_t userfunc;
1560 struct aim_ssi_tmp *cur, *del;
1562 /* Read in the success/failure flags from the ack SNAC */
1563 cur = od->ssi.pending;
1564 while (cur && (byte_stream_bytes_left(bs)>0)) {
1565 cur->ack = byte_stream_get16(bs);
1566 cur = cur->next;
1570 * If outcome is 0, then add the item to the item list, or replace the other item,
1571 * or remove the old item. If outcome is non-zero, then remove the item from the
1572 * local list, or unmodify it, or add it.
1574 for (cur=od->ssi.pending; (cur && (cur->ack != 0xffff)); cur=cur->next) {
1575 if (cur->item) {
1576 if (cur->ack) {
1577 /* Our action was unsuccessful, so change the local list back to how it was */
1578 if (cur->action == SNAC_SUBTYPE_FEEDBAG_ADD) {
1579 /* Remove the item from the local list */
1580 /* Make sure cur->item is still valid memory */
1581 /* TODO: "Still valid memory"? That's bad form. */
1582 if (aim_ssi_itemlist_valid(&od->ssi.local, cur->item)) {
1583 cur->name = g_strdup(cur->item->name);
1584 aim_ssi_itemlist_del(&od->ssi.local, cur->item);
1586 cur->item = NULL;
1588 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_MOD) {
1589 /* Replace the local item with the item from the official list */
1590 if (aim_ssi_itemlist_valid(&od->ssi.local, cur->item)) {
1591 struct aim_ssi_item *cur1;
1592 if ((cur1 = aim_ssi_itemlist_find(&od->ssi.official, cur->item->gid, cur->item->bid))) {
1593 aim_ssi_item_set_name(&od->ssi.official, cur->item, cur1->name);
1594 aim_tlvlist_free(cur->item->data);
1595 cur->item->data = aim_tlvlist_copy(cur1->data);
1597 } else
1598 cur->item = NULL;
1600 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_DEL) {
1601 /* Add the item back into the local list */
1602 if (aim_ssi_itemlist_valid(&od->ssi.official, cur->item)) {
1603 aim_ssi_itemlist_add(&od->ssi.local, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
1604 } else
1605 cur->item = NULL;
1608 } else {
1609 /* Do the exact opposite */
1610 if (cur->action == SNAC_SUBTYPE_FEEDBAG_ADD) {
1611 /* Add the local item to the official list */
1612 if (aim_ssi_itemlist_valid(&od->ssi.local, cur->item)) {
1613 aim_ssi_itemlist_add(&od->ssi.official, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
1614 } else
1615 cur->item = NULL;
1617 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_MOD) {
1618 /* Replace the official item with the item from the local list */
1619 if (aim_ssi_itemlist_valid(&od->ssi.local, cur->item)) {
1620 struct aim_ssi_item *cur1;
1621 if ((cur1 = aim_ssi_itemlist_find(&od->ssi.official, cur->item->gid, cur->item->bid))) {
1622 aim_ssi_item_set_name(&od->ssi.official, cur1, cur->item->name);
1623 aim_tlvlist_free(cur1->data);
1624 cur1->data = aim_tlvlist_copy(cur->item->data);
1626 } else
1627 cur->item = NULL;
1629 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_DEL) {
1630 /* Remove the item from the official list */
1631 if (aim_ssi_itemlist_valid(&od->ssi.official, cur->item))
1632 aim_ssi_itemlist_del(&od->ssi.official, cur->item);
1633 cur->item = NULL;
1637 } /* End if (cur->item) */
1638 } /* End for loop */
1640 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1641 ret = userfunc(od, conn, frame, od->ssi.pending);
1643 /* Free all aim_ssi_tmp's with an outcome */
1644 cur = od->ssi.pending;
1645 while (cur && (cur->ack != 0xffff)) {
1646 del = cur;
1647 cur = cur->next;
1648 g_free(del->name);
1649 g_free(del);
1651 od->ssi.pending = cur;
1653 /* If we're not waiting for any more acks, then send more SNACs */
1654 if (!od->ssi.pending) {
1655 od->ssi.waiting_for_ack = FALSE;
1656 aim_ssi_sync(od);
1659 return ret;
1663 * Subtype 0x000f - SSI Data Unchanged.
1665 * Response to aim_ssi_reqifchanged() if the server-side data is not newer than
1666 * posted local stamp/revision.
1669 static int parsedataunchanged(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1671 int ret = 0;
1672 aim_rxcallback_t userfunc;
1674 od->ssi.received_data = TRUE;
1676 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1677 ret = userfunc(od, conn, frame);
1679 return ret;
1683 * Subtype 0x0011 - SSI Begin Data Modification.
1685 * Tell the server you're going to start modifying data. This marks
1686 * the beginning of a transaction.
1688 int aim_ssi_modbegin(OscarData *od)
1690 FlapConnection *conn;
1692 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1693 return -EINVAL;
1695 aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_EDITSTART);
1697 return 0;
1701 * Subtype 0x0012 - SSI End Data Modification.
1703 * Tell the server you're finished modifying data. The marks the end
1704 * of a transaction.
1706 int aim_ssi_modend(OscarData *od)
1708 FlapConnection *conn;
1710 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1711 return -EINVAL;
1713 aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_EDITSTOP);
1715 return 0;
1719 * Subtype 0x0015 - Receive an authorization grant
1721 static int receiveauthgrant(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1723 int ret = 0;
1724 aim_rxcallback_t userfunc;
1725 guint16 tmp;
1726 char *bn, *msg, *tmpstr;
1728 /* Read buddy name */
1729 tmp = byte_stream_get8(bs);
1730 if (!tmp) {
1731 purple_debug_warning("oscar", "Dropping auth grant SNAC "
1732 "because username was empty\n");
1733 return 0;
1735 bn = byte_stream_getstr(bs, tmp);
1736 if (!g_utf8_validate(bn, -1, NULL)) {
1737 purple_debug_warning("oscar", "Dropping auth grant SNAC "
1738 "because the username was not valid UTF-8\n");
1739 g_free(bn);
1740 return 0;
1743 /* Read message */
1744 tmp = byte_stream_get16(bs);
1745 if (tmp) {
1746 msg = byte_stream_getstr(bs, tmp);
1747 if (!g_utf8_validate(msg, -1, NULL)) {
1748 /* Ugh, msg isn't UTF8. Let's salvage. */
1749 purple_debug_warning("oscar", "Got non-UTF8 message in auth "
1750 "grant from %s\n", bn);
1751 tmpstr = purple_utf8_salvage(msg);
1752 g_free(msg);
1753 msg = tmpstr;
1755 } else
1756 msg = NULL;
1758 /* Unknown */
1759 tmp = byte_stream_get16(bs);
1760 if (!tmp)
1761 purple_debug_warning("oscar", "unknown field missing");
1763 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1764 ret = userfunc(od, conn, frame, bn, msg);
1766 g_free(bn);
1767 g_free(msg);
1769 return ret;
1773 * Subtype 0x0018 - Send authorization request
1775 * Sends a request for authorization to the given contact. The request will either be
1776 * granted, denied, or dropped.
1779 int aim_ssi_sendauthrequest(OscarData *od, const char *bn, const char *msg)
1781 FlapConnection *conn;
1782 ByteStream bs;
1783 aim_snacid_t snacid;
1785 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !bn)
1786 return -EINVAL;
1788 byte_stream_new(&bs, 1+strlen(bn) + 2+(msg ? strlen(msg)+1 : 0) + 2);
1790 /* Username */
1791 byte_stream_put8(&bs, strlen(bn));
1792 byte_stream_putstr(&bs, bn);
1794 /* Message (null terminated) */
1795 byte_stream_put16(&bs, msg ? strlen(msg) : 0);
1796 if (msg) {
1797 byte_stream_putstr(&bs, msg);
1798 byte_stream_put8(&bs, 0x00);
1801 /* Unknown */
1802 byte_stream_put16(&bs, 0x0000);
1804 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ, 0x0000, NULL, 0);
1805 flap_connection_send_snac(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ, snacid, &bs);
1807 byte_stream_destroy(&bs);
1809 return 0;
1813 * Subtype 0x0019 - Receive an authorization request
1815 static int receiveauthrequest(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1817 int ret = 0;
1818 aim_rxcallback_t userfunc;
1819 guint16 tmp;
1820 char *bn, *msg, *tmpstr;
1822 /* Read buddy name */
1823 tmp = byte_stream_get8(bs);
1824 if (!tmp) {
1825 purple_debug_warning("oscar", "Dropping auth request SNAC "
1826 "because username was empty\n");
1827 return 0;
1829 bn = byte_stream_getstr(bs, tmp);
1830 if (!g_utf8_validate(bn, -1, NULL)) {
1831 purple_debug_warning("oscar", "Dropping auth request SNAC "
1832 "because the username was not valid UTF-8\n");
1833 g_free(bn);
1834 return 0;
1837 /* Read message */
1838 tmp = byte_stream_get16(bs);
1839 if (tmp) {
1840 msg = byte_stream_getstr(bs, tmp);
1841 if (!g_utf8_validate(msg, -1, NULL)) {
1842 /* Ugh, msg isn't UTF8. Let's salvage. */
1843 purple_debug_warning("oscar", "Got non-UTF8 message in auth "
1844 "request from %s\n", bn);
1845 tmpstr = purple_utf8_salvage(msg);
1846 g_free(msg);
1847 msg = tmpstr;
1849 } else
1850 msg = NULL;
1852 /* Unknown */
1853 tmp = byte_stream_get16(bs);
1854 if (!tmp)
1855 purple_debug_warning("oscar", "unknown field missing");
1857 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1858 ret = userfunc(od, conn, frame, bn, msg);
1860 g_free(bn);
1861 g_free(msg);
1863 return ret;
1867 * Subtype 0x001a - Send authorization reply
1869 * Sends a reply to a request for authorization. The reply can either
1870 * grant authorization or deny authorization.
1872 * if reply=0x00 then deny
1873 * if reply=0x01 then grant
1876 int aim_ssi_sendauthreply(OscarData *od, const char *bn, guint8 reply, const char *msg)
1878 FlapConnection *conn;
1879 ByteStream bs;
1880 aim_snacid_t snacid;
1882 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !bn)
1883 return -EINVAL;
1885 byte_stream_new(&bs, 1+strlen(bn) + 1 + 2+(msg ? (strlen(msg)+1) : 0) + 2);
1887 /* Username */
1888 byte_stream_put8(&bs, strlen(bn));
1889 byte_stream_putstr(&bs, bn);
1891 /* Grant or deny */
1892 byte_stream_put8(&bs, reply);
1894 /* Message (null terminated) */
1895 byte_stream_put16(&bs, msg ? (strlen(msg)+1) : 0);
1896 if (msg) {
1897 byte_stream_putstr(&bs, msg);
1898 byte_stream_put8(&bs, 0x00);
1901 /* Unknown */
1902 byte_stream_put16(&bs, 0x0000);
1904 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP, 0x0000, NULL, 0);
1905 flap_connection_send_snac(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP, snacid, &bs);
1907 byte_stream_destroy(&bs);
1909 return 0;
1913 * Subtype 0x001b - Receive an authorization reply
1915 * You get this bad boy when other people respond to the authorization
1916 * request that you have previously sent them.
1918 static int receiveauthreply(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1920 int ret = 0;
1921 aim_rxcallback_t userfunc;
1922 guint16 tmp;
1923 guint8 reply;
1924 char *bn, *msg, *tmpstr;
1926 /* Read buddy name */
1927 tmp = byte_stream_get8(bs);
1928 if (!tmp) {
1929 purple_debug_warning("oscar", "Dropping auth reply SNAC "
1930 "because username was empty\n");
1931 return 0;
1933 bn = byte_stream_getstr(bs, tmp);
1934 if (!g_utf8_validate(bn, -1, NULL)) {
1935 purple_debug_warning("oscar", "Dropping auth reply SNAC "
1936 "because the username was not valid UTF-8\n");
1937 g_free(bn);
1938 return 0;
1941 /* Read reply */
1942 reply = byte_stream_get8(bs);
1944 /* Read message */
1945 tmp = byte_stream_get16(bs);
1946 if (tmp) {
1947 msg = byte_stream_getstr(bs, tmp);
1948 if (!g_utf8_validate(msg, -1, NULL)) {
1949 /* Ugh, msg isn't UTF8. Let's salvage. */
1950 purple_debug_warning("oscar", "Got non-UTF8 message in auth "
1951 "reply from %s\n", bn);
1952 tmpstr = purple_utf8_salvage(msg);
1953 g_free(msg);
1954 msg = tmpstr;
1956 } else
1957 msg = NULL;
1959 /* Unknown */
1960 tmp = byte_stream_get16(bs);
1961 if (!tmp)
1962 purple_debug_warning("oscar", "unknown field missing");
1964 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1965 ret = userfunc(od, conn, frame, bn, reply, msg);
1967 g_free(bn);
1968 g_free(msg);
1970 return ret;
1974 * Subtype 0x001c - Receive a message telling you someone added you to their list.
1976 static int receiveadded(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1978 int ret = 0;
1979 aim_rxcallback_t userfunc;
1980 guint16 tmp;
1981 char *bn;
1983 /* Read buddy name */
1984 tmp = byte_stream_get8(bs);
1985 if (!tmp) {
1986 purple_debug_warning("oscar", "Dropping 'you were added' SNAC "
1987 "because username was empty\n");
1988 return 0;
1990 bn = byte_stream_getstr(bs, tmp);
1991 if (!g_utf8_validate(bn, -1, NULL)) {
1992 purple_debug_warning("oscar", "Dropping 'you were added' SNAC "
1993 "because the username was not valid UTF-8\n");
1994 g_free(bn);
1995 return 0;
1998 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1999 ret = userfunc(od, conn, frame, bn);
2001 g_free(bn);
2003 return ret;
2007 * If we're on ICQ, then AIM_SSI_TYPE_DENY is used for the "permanently invisible" list.
2008 * AIM_SSI_TYPE_ICQDENY is used for blocking users instead.
2010 guint16
2011 aim_ssi_getdenyentrytype(OscarData* od)
2013 return od->icq ? AIM_SSI_TYPE_ICQDENY : AIM_SSI_TYPE_DENY;
2016 static int
2017 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
2019 if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RIGHTSINFO)
2020 return parserights(od, conn, mod, frame, snac, bs);
2021 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_LIST)
2022 return parsedata(od, conn, mod, frame, snac, bs);
2023 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_ADD)
2024 return parseadd(od, conn, mod, frame, snac, bs);
2025 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_MOD)
2026 return parsemod(od, conn, mod, frame, snac, bs);
2027 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_DEL)
2028 return parsedel(od, conn, mod, frame, snac, bs);
2029 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_SRVACK)
2030 return parseack(od, conn, mod, frame, snac, bs);
2031 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_NOLIST)
2032 return parsedataunchanged(od, conn, mod, frame, snac, bs);
2033 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTH)
2034 return receiveauthgrant(od, conn, mod, frame, snac, bs);
2035 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTHREQ)
2036 return receiveauthrequest(od, conn, mod, frame, snac, bs);
2037 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTHREP)
2038 return receiveauthreply(od, conn, mod, frame, snac, bs);
2039 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_ADDED)
2040 return receiveadded(od, conn, mod, frame, snac, bs);
2042 return 0;
2045 static void
2046 ssi_shutdown(OscarData *od, aim_module_t *mod)
2048 aim_ssi_freelist(od);
2052 ssi_modfirst(OscarData *od, aim_module_t *mod)
2054 mod->family = SNAC_FAMILY_FEEDBAG;
2055 mod->version = 0x0004;
2056 mod->toolid = 0x0110;
2057 mod->toolversion = 0x0629;
2058 mod->flags = 0;
2059 strncpy(mod->name, "feedbag", sizeof(mod->name));
2060 mod->snachandler = snachandler;
2061 mod->shutdown = ssi_shutdown;
2063 return 0;