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.
46 #include "oscarcommon.h"
49 static int aim_ssi_addmoddel(OscarData
*od
);
51 static void aim_ssi_item_free(struct aim_ssi_item
*item
)
54 aim_tlvlist_free(item
->data
);
58 static void aim_ssi_item_set_name(struct aim_ssi_itemlist
*list
, struct aim_ssi_item
*item
, const char *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
);
69 item
->name
= g_strdup(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
);
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.
86 aim_ssi_type_to_string(guint16 type
)
93 static const struct TypeStringPair type_strings
[] = {
96 { 0x0002, "Permit/Visible" },
97 { 0x0003, "Deny/Invisible" },
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" },
111 for (i
= 0; i
< G_N_ELEMENTS(type_strings
); i
++) {
112 if (type_strings
[i
].type
== type
) {
113 return type_strings
[i
].string
;
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.
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.
143 aim_ssi_itemlist_rebuildgroup(struct aim_ssi_itemlist
*list
, const char *name
)
146 struct aim_ssi_item
*cur
, *group
;
149 if (!(group
= aim_ssi_itemlist_finditem(list
, name
, NULL
, AIM_SSI_TYPE_GROUP
)))
152 /* Find the length for the new additional data */
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))
159 for (cur
=list
->data
; cur
; cur
=cur
->next
)
160 if ((cur
->gid
== group
->gid
) && (cur
->type
== AIM_SSI_TYPE_BUDDY
))
164 /* Build the new TLV list */
168 newdata
= g_new(guint8
, newlen
);
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
);
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
);
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
)
200 struct aim_ssi_item
*cur
, *new;
202 new = g_new0(struct aim_ssi_item
, 1);
204 /* Set the group ID# and buddy ID# */
207 if (type
== AIM_SSI_TYPE_GROUP
) {
208 if ((new->gid
== 0xFFFF) && name
) {
212 for (cur
= list
->data
; cur
!= NULL
; cur
= cur
->next
)
213 if ((cur
->type
== AIM_SSI_TYPE_GROUP
) && (cur
->gid
== new->gid
)) {
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) {
229 for (cur
= list
->data
; cur
!= NULL
; cur
= cur
->next
)
230 if (cur
->bid
== new->bid
|| cur
->gid
== new->bid
) {
237 if (new->bid
== 0xFFFF) {
241 for (cur
= list
->data
; cur
!= NULL
; cur
= cur
->next
)
242 if (cur
->bid
== new->bid
&& cur
->gid
== new->gid
) {
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? */
264 if ((new->gid
< list
->data
->gid
) || ((new->gid
== list
->data
->gid
) && (new->bid
< list
->data
->bid
))) {
265 new->next
= list
->data
;
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
;
274 new->next
= list
->data
;
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
)
292 if (!(list
->data
) || !del
)
295 /* Remove the item from the list */
296 if (list
->data
== del
) {
297 list
->data
= list
->data
->next
;
299 struct aim_ssi_item
*cur
;
300 for (cur
=list
->data
; (cur
->next
&& (cur
->next
!=del
)); cur
=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
);
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
)
329 if (cur1
->data
&& !cur2
->data
)
332 if (!cur1
->data
&& cur2
->data
)
335 if ((cur1
->data
&& cur2
->data
) && (aim_tlvlist_cmp(cur1
->data
, cur2
->data
)))
338 if (cur1
->name
&& !cur2
->name
)
341 if (!cur1
->name
&& cur2
->name
)
344 if (cur1
->name
&& cur2
->name
&& oscar_util_name_compare(cur1
->name
, cur2
->name
))
347 if (cur1
->gid
!= cur2
->gid
)
350 if (cur1
->bid
!= cur2
->bid
)
353 if (cur1
->type
!= cur2
->type
)
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
)
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
;
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
)))
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
))
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
)
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
)
449 if (!(cur
= aim_ssi_itemlist_exists(list
, bn
)))
451 if (!(curg
= aim_ssi_itemlist_find(list
, cur
->gid
, 0x0000)))
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
);
466 aim_tlv_t
*tlv
= aim_tlv_gettlv(cur
->data
, 0x00ca, 1);
467 if (tlv
&& tlv
->value
)
468 return aimutil_get8(tlv
->value
);
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
);
484 aim_tlv_t
*tlv
= aim_tlv_gettlv(cur
->data
, 0x00c9, 1);
485 if (tlv
&& tlv
->length
)
486 return aimutil_get32(tlv
->value
);
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
);
505 return aim_ssi_getalias_from_item(item
);
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
);
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
);
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
);
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
);
552 if (aim_tlv_gettlv(cur
->data
, 0x0066, 1))
559 * If there are changes, then create temporary items and
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;
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.
581 /* If we're waiting for an ack, we shouldn't do anything else */
582 if (od
->ssi
.waiting_for_ack
)
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.
593 debugstr
= g_string_new("");
596 if (!od
->ssi
.pending
) {
597 for (cur1
=od
->ssi
.official
.data
; cur1
&& (n
< 15); cur1
=cur1
->next
) {
598 if (!aim_ssi_itemlist_find(&od
->ssi
.local
, cur1
->gid
, cur1
->bid
)) {
600 new = g_new(struct aim_ssi_tmp
, 1);
601 new->action
= SNAC_SUBTYPE_FEEDBAG_DEL
;
606 if (od
->ssi
.pending
) {
607 for (cur
=od
->ssi
.pending
; cur
->next
; cur
=cur
->next
);
610 od
->ssi
.pending
= new;
612 aim_ssi_item_debug_append(debugstr
, "Deleting item ", cur1
);
618 if (!od
->ssi
.pending
) {
619 for (cur1
=od
->ssi
.local
.data
; cur1
&& (n
< 15); cur1
=cur1
->next
) {
620 if (!aim_ssi_itemlist_find(&od
->ssi
.official
, cur1
->gid
, cur1
->bid
)) {
622 new = g_new(struct aim_ssi_tmp
, 1);
623 new->action
= SNAC_SUBTYPE_FEEDBAG_ADD
;
628 if (od
->ssi
.pending
) {
629 for (cur
=od
->ssi
.pending
; cur
->next
; cur
=cur
->next
);
632 od
->ssi
.pending
= new;
634 aim_ssi_item_debug_append(debugstr
, "Adding item ", cur1
);
640 if (!od
->ssi
.pending
) {
641 for (cur1
=od
->ssi
.local
.data
; cur1
&& (n
< 15); cur1
=cur1
->next
) {
642 cur2
= aim_ssi_itemlist_find(&od
->ssi
.official
, cur1
->gid
, cur1
->bid
);
643 if (cur2
&& (aim_ssi_itemlist_cmp(cur1
, cur2
))) {
645 new = g_new(struct aim_ssi_tmp
, 1);
646 new->action
= SNAC_SUBTYPE_FEEDBAG_MOD
;
651 if (od
->ssi
.pending
) {
652 for (cur
=od
->ssi
.pending
; cur
->next
; cur
=cur
->next
);
655 od
->ssi
.pending
= new;
657 aim_ssi_item_debug_append(debugstr
, "Modifying item ", cur1
);
661 if (debugstr
->len
> 0) {
662 purple_debug_info("oscar", "%s", debugstr
->str
);
663 if (purple_debug_is_verbose()) {
664 PurpleAccount
*account
= purple_connection_get_account(od
->gc
);
665 g_string_truncate(debugstr
, 0);
666 for (cur1
= od
->ssi
.local
.data
; cur1
; cur1
= cur1
->next
) {
667 aim_ssi_item_debug_append(debugstr
, "\t", cur1
);
669 purple_debug_misc("oscar", "Dumping item list of account %s:\n%s",
670 purple_account_get_username(account
), debugstr
->str
);
673 g_string_free(debugstr
, TRUE
);
675 /* We're out of stuff to do, so tell the AIM servers we're done and exit */
676 if (!od
->ssi
.pending
) {
677 if (od
->ssi
.in_transaction
) {
679 od
->ssi
.in_transaction
= FALSE
;
684 /* If this is the first in a series of add/mod/del
685 * requests then send the "begin transaction" message. */
686 if (!od
->ssi
.in_transaction
)
688 aim_ssi_modbegin(od
);
689 od
->ssi
.in_transaction
= TRUE
;
692 /* Make sure we don't send anything else between now
693 * and when we receive the ack for the following operation */
694 od
->ssi
.waiting_for_ack
= TRUE
;
696 /* Now go mail off our data and wait 4 to 6 weeks */
697 return aim_ssi_addmoddel(od
);;
703 * This doesn't remove it from the server, that's different.
705 * @param od The oscar odion.
706 * @return Return 0 if no errors, otherwise return the error number.
709 aim_ssi_freelist(OscarData
*od
)
711 struct aim_ssi_item
*cur
, *del
;
712 struct aim_ssi_tmp
*curtmp
, *deltmp
;
714 cur
= od
->ssi
.official
.data
;
718 aim_ssi_item_free(del
);
721 cur
= od
->ssi
.local
.data
;
725 aim_ssi_item_free(del
);
728 curtmp
= od
->ssi
.pending
;
731 curtmp
= curtmp
->next
;
735 od
->ssi
.numitems
= 0;
736 od
->ssi
.official
.data
= NULL
;
737 od
->ssi
.local
.data
= NULL
;
738 od
->ssi
.pending
= NULL
;
739 od
->ssi
.timestamp
= (time_t)0;
743 * Look up the given TLV type in the item's data. If the value of
744 * the TLV is not a valid UTF-8 string then use purple_utf8_salvage()
745 * to replace invalid bytes with question marks.
747 static void cleanlist_ensure_utf8_data(struct aim_ssi_item
*item
, guint16 tlvtype
)
750 gchar
*value
, *salvaged
;
752 tlv
= aim_tlv_gettlv(item
->data
, tlvtype
, 1);
753 if (tlv
&& tlv
->length
&& !g_utf8_validate((const gchar
*)tlv
->value
, tlv
->length
, NULL
)) {
754 purple_debug_warning("oscar", "cleanlist found invalid UTF-8 "
755 "for 0x%04hx field of 0x%04hx item with name %s. "
756 "Attempting to repair.\n",
757 tlvtype
, item
->type
, item
->name
? item
->name
: "(null)");
758 value
= g_strndup((const gchar
*)tlv
->value
, tlv
->length
);
759 salvaged
= purple_utf8_salvage(value
);
762 aim_tlvlist_replace_str(&item
->data
, tlvtype
, salvaged
);
764 aim_tlvlist_remove(&item
->data
, tlvtype
);
770 * This "cleans" the ssi list. It does things like:
771 * - Makes sure all buddies, permits, and denies have names
772 * - Makes sure all buddies are in a group that exist
773 * - Makes sure strings are valid UTF-8
775 * @param od The oscar odion.
776 * @return Return 0 if no errors, otherwise return the error number.
778 static int aim_ssi_cleanlist(OscarData
*od
)
780 struct aim_ssi_item
*cur
, *next
;
785 /* Delete any buddies, permits, or denies with empty names. */
786 /* If there are any buddies directly in the master group, add them to a real group. */
787 /* DESTROY any buddies that are directly in the master group. */
788 /* Do the same for buddies that are in a non-existant group. */
789 /* This will kind of mess up if you hit the item limit, but this function isn't too critical */
790 cur
= od
->ssi
.local
.data
;
794 if (cur
->type
== AIM_SSI_TYPE_BUDDY
)
795 aim_ssi_delbuddy(od
, NULL
, NULL
);
796 else if (cur
->type
== AIM_SSI_TYPE_PERMIT
|| cur
->type
== AIM_SSI_TYPE_DENY
|| cur
->type
== AIM_SSI_TYPE_ICQDENY
)
797 aim_ssi_del_from_private_list(od
, NULL
, cur
->type
);
798 } else if ((cur
->type
== AIM_SSI_TYPE_BUDDY
) && ((cur
->gid
== 0x0000) || (!aim_ssi_itemlist_find(&od
->ssi
.local
, cur
->gid
, 0x0000)))) {
799 char *alias
= aim_ssi_getalias(&od
->ssi
.local
, NULL
, cur
->name
);
800 aim_ssi_addbuddy(od
, cur
->name
, PURPLE_BLIST_DEFAULT_GROUP_NAME
,
801 NULL
, alias
, NULL
, NULL
, FALSE
);
802 aim_ssi_delbuddy(od
, cur
->name
, NULL
);
808 cur
= od
->ssi
.local
.data
;
810 if ((cur
->type
== AIM_SSI_TYPE_BUDDY
) || (cur
->type
== AIM_SSI_TYPE_PERMIT
) || (cur
->type
== AIM_SSI_TYPE_DENY
))
812 struct aim_ssi_item
*cur2
, *next2
;
814 /* Make sure there aren't any duplicate permits or denies, or
815 duplicate buddies within a group */
819 if (cur
->type
== cur2
->type
820 && cur
->gid
== cur2
->gid
823 && !oscar_util_name_compare(cur
->name
, cur2
->name
))
825 aim_ssi_itemlist_del(&od
->ssi
.local
, cur2
);
830 /* Make sure alias is valid UTF-8 */
831 cleanlist_ensure_utf8_data(cur
, 0x0131);
833 /* Make sure comment is valid UTF-8 */
834 cleanlist_ensure_utf8_data(cur
, 0x013c);
839 /* If we've made any changes then sync our list with the server's */
840 return aim_ssi_sync(od
);
844 * Add a buddy to the list.
846 * @param od The oscar odion.
847 * @param name The name of the item.
848 * @param group The group of the item.
849 * @param data A TLV list to use as the additional data for this item.
850 * @param alias The alias/nickname of the item, or NULL.
851 * @param comment The buddy comment for the item, or NULL.
852 * @param smsnum The locally assigned SMS number, or NULL.
853 * @return Return 0 if no errors, otherwise return the error number.
855 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
)
857 struct aim_ssi_item
*parent
;
859 if (!od
|| !name
|| !group
)
862 /* Find the parent */
863 if (!(parent
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, group
, NULL
, AIM_SSI_TYPE_GROUP
))) {
864 /* Find the parent's parent (the master group) */
865 if (aim_ssi_itemlist_find(&od
->ssi
.local
, 0x0000, 0x0000) == NULL
)
866 aim_ssi_itemlist_add(&od
->ssi
.local
, NULL
, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP
, NULL
);
869 parent
= aim_ssi_itemlist_add(&od
->ssi
.local
, group
, 0xFFFF, 0x0000, AIM_SSI_TYPE_GROUP
, NULL
);
871 /* Modify the parent's parent (the master group) */
872 aim_ssi_itemlist_rebuildgroup(&od
->ssi
.local
, NULL
);
875 /* Create a TLV list for the new buddy */
877 aim_tlvlist_add_noval(&data
, 0x0066);
879 aim_tlvlist_add_str(&data
, 0x0131, alias
);
881 aim_tlvlist_add_str(&data
, 0x013a, smsnum
);
883 aim_tlvlist_add_str(&data
, 0x013c, comment
);
885 /* Add that bad boy */
886 aim_ssi_itemlist_add(&od
->ssi
.local
, name
, parent
->gid
, 0xFFFF, AIM_SSI_TYPE_BUDDY
, data
);
887 aim_tlvlist_free(data
);
889 /* Modify the parent group */
890 aim_ssi_itemlist_rebuildgroup(&od
->ssi
.local
, group
);
892 /* Sync our local list with the server list */
893 return aim_ssi_sync(od
);
897 aim_ssi_add_to_private_list(OscarData
*od
, const char* name
, guint16 list_type
)
899 if (!od
|| !name
|| !od
->ssi
.received_data
)
902 if (aim_ssi_itemlist_find(&od
->ssi
.local
, 0x0000, 0x0000) == NULL
)
903 aim_ssi_itemlist_add(&od
->ssi
.local
, NULL
, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP
, NULL
);
905 aim_ssi_itemlist_add(&od
->ssi
.local
, name
, 0x0000, 0xFFFF, list_type
, NULL
);
906 return aim_ssi_sync(od
);
910 aim_ssi_del_from_private_list(OscarData
* od
, const char* name
, guint16 list_type
)
912 struct aim_ssi_item
*del
;
917 if (!(del
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, name
, list_type
)))
920 aim_ssi_itemlist_del(&od
->ssi
.local
, del
);
921 return aim_ssi_sync(od
);
925 * Deletes a buddy from the list.
927 * @param od The oscar odion.
928 * @param name The name of the item, or NULL.
929 * @param group The group of the item, or NULL.
930 * @return Return 0 if no errors, otherwise return the error number.
932 int aim_ssi_delbuddy(OscarData
*od
, const char *name
, const char *group
)
934 struct aim_ssi_item
*del
;
940 if (!(del
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, group
, name
, AIM_SSI_TYPE_BUDDY
)))
943 /* Remove the item from the list */
944 aim_ssi_itemlist_del(&od
->ssi
.local
, del
);
946 /* Modify the parent group */
947 aim_ssi_itemlist_rebuildgroup(&od
->ssi
.local
, group
);
949 /* Sync our local list with the server list */
950 return aim_ssi_sync(od
);
954 * Deletes a group from the list.
956 * @param od The oscar odion.
957 * @param group The name of the group.
958 * @return Return 0 if no errors, otherwise return the error number.
960 int aim_ssi_delgroup(OscarData
*od
, const char *group
)
962 struct aim_ssi_item
*del
;
969 if (!(del
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, group
, NULL
, AIM_SSI_TYPE_GROUP
)))
972 /* Don't delete the group if it's not empty */
973 tlv
= aim_tlv_gettlv(del
->data
, 0x00c8, 1);
974 if (tlv
&& tlv
->length
> 0)
977 /* Remove the item from the list */
978 aim_ssi_itemlist_del(&od
->ssi
.local
, del
);
980 /* Modify the parent group */
981 aim_ssi_itemlist_rebuildgroup(&od
->ssi
.local
, NULL
);
983 /* Sync our local list with the server list */
984 return aim_ssi_sync(od
);
988 * Move a buddy from one group to another group. This basically just deletes the
989 * buddy and re-adds it.
991 * @param od The oscar odion.
992 * @param oldgn The group that the buddy is currently in.
993 * @param newgn The group that the buddy should be moved in to.
994 * @param bn The name of the buddy to be moved.
995 * @return Return 0 if no errors, otherwise return the error number.
997 int aim_ssi_movebuddy(OscarData
*od
, const char *oldgn
, const char *newgn
, const char *bn
)
999 struct aim_ssi_item
*buddy
;
1002 /* Find the buddy */
1003 buddy
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, oldgn
, bn
, AIM_SSI_TYPE_BUDDY
);
1007 /* Make a copy of the buddy's TLV list */
1008 data
= aim_tlvlist_copy(buddy
->data
);
1010 /* Delete the old item */
1011 aim_ssi_delbuddy(od
, bn
, oldgn
);
1013 /* Add the new item using the EXACT SAME TLV list */
1014 aim_ssi_addbuddy(od
, bn
, newgn
, data
, NULL
, NULL
, NULL
, FALSE
);
1020 * Change the alias stored on the server for a given buddy.
1022 * @param od The oscar odion.
1023 * @param gn The group that the buddy is currently in.
1024 * @param bn The name of the buddy.
1025 * @param alias The new alias for the buddy, or NULL if you want to remove
1026 * a buddy's comment.
1027 * @return Return 0 if no errors, otherwise return the error number.
1029 int aim_ssi_aliasbuddy(OscarData
*od
, const char *gn
, const char *bn
, const char *alias
)
1031 struct aim_ssi_item
*tmp
;
1033 if (!od
|| !gn
|| !bn
)
1036 if (!(tmp
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, gn
, bn
, AIM_SSI_TYPE_BUDDY
)))
1039 /* Either add or remove the 0x0131 TLV from the TLV chain */
1040 if (alias
&& *alias
)
1041 aim_tlvlist_replace_str(&tmp
->data
, 0x0131, alias
);
1043 aim_tlvlist_remove(&tmp
->data
, 0x0131);
1045 /* Sync our local list with the server list */
1046 return aim_ssi_sync(od
);
1050 * Change the comment stored on the server for a given buddy.
1052 * @param od The oscar odion.
1053 * @param gn The group that the buddy is currently in.
1054 * @param bn The name of the buddy.
1055 * @param alias The new comment for the buddy, or NULL if you want to remove
1056 * a buddy's comment.
1057 * @return Return 0 if no errors, otherwise return the error number.
1059 int aim_ssi_editcomment(OscarData
*od
, const char *gn
, const char *bn
, const char *comment
)
1061 struct aim_ssi_item
*tmp
;
1063 if (!od
|| !gn
|| !bn
)
1066 if (!(tmp
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, gn
, bn
, AIM_SSI_TYPE_BUDDY
)))
1069 /* Either add or remove the 0x0131 TLV from the TLV chain */
1070 if (comment
&& *comment
)
1071 aim_tlvlist_replace_str(&tmp
->data
, 0x013c, comment
);
1073 aim_tlvlist_remove(&tmp
->data
, 0x013c);
1075 /* Sync our local list with the server list */
1076 return aim_ssi_sync(od
);
1082 * @param od The oscar odion.
1083 * @param oldgn The old group name.
1084 * @param newgn The new group name.
1085 * @return Return 0 if no errors, otherwise return the error number.
1087 int aim_ssi_rename_group(OscarData
*od
, const char *oldgn
, const char *newgn
)
1089 struct aim_ssi_item
*group
;
1091 if (!od
|| !oldgn
|| !newgn
)
1094 if (!(group
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, oldgn
, NULL
, AIM_SSI_TYPE_GROUP
)))
1097 aim_ssi_item_set_name(&od
->ssi
.local
, group
, newgn
);
1099 /* Sync our local list with the server list */
1100 return aim_ssi_sync(od
);
1104 * Stores your permit/deny setting on the server, and starts using it.
1106 * @param od The oscar odion.
1107 * @param permdeny Your permit/deny setting. For ICQ accounts, it actually affects your visibility
1108 * and has nothing to do with blocking. Can be one of the following:
1109 * 1 - Allow all users
1110 * 2 - Block all users
1111 * 3 - Allow only the users below
1112 * 4 - Block only the users below
1113 * 5 - Allow only users on my buddy list
1114 * @return Return 0 if no errors, otherwise return the error number.
1116 int aim_ssi_setpermdeny(OscarData
*od
, guint8 permdeny
)
1118 struct aim_ssi_item
*tmp
;
1120 if (!od
|| !od
->ssi
.received_data
)
1123 /* Find the PDINFO item, or add it if it does not exist */
1124 if (!(tmp
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, NULL
, AIM_SSI_TYPE_PDINFO
))) {
1125 /* Make sure the master group exists */
1126 if (aim_ssi_itemlist_find(&od
->ssi
.local
, 0x0000, 0x0000) == NULL
)
1127 aim_ssi_itemlist_add(&od
->ssi
.local
, NULL
, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP
, NULL
);
1129 tmp
= aim_ssi_itemlist_add(&od
->ssi
.local
, NULL
, 0x0000, 0xFFFF, AIM_SSI_TYPE_PDINFO
, NULL
);
1132 /* Need to add the 0x00ca TLV to the TLV chain */
1133 aim_tlvlist_replace_8(&tmp
->data
, 0x00ca, permdeny
);
1135 /* Sync our local list with the server list */
1136 return aim_ssi_sync(od
);
1140 * Set buddy icon information
1142 * @param od The oscar odion.
1143 * @param iconcsum The MD5 checksum of the icon you are using.
1144 * @param iconcsumlen Length of the MD5 checksum given above. Should be 0x10 bytes.
1145 * @return Return 0 if no errors, otherwise return the error number.
1147 int aim_ssi_seticon(OscarData
*od
, const guint8
*iconsum
, guint8 iconsumlen
)
1149 struct aim_ssi_item
*tmp
;
1152 if (!od
|| !iconsum
|| !iconsumlen
|| !od
->ssi
.received_data
)
1155 /* Find the ICONINFO item, or add it if it does not exist */
1156 if (!(tmp
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, "1", AIM_SSI_TYPE_ICONINFO
))) {
1157 /* Make sure the master group exists */
1158 if (aim_ssi_itemlist_find(&od
->ssi
.local
, 0x0000, 0x0000) == NULL
)
1159 aim_ssi_itemlist_add(&od
->ssi
.local
, NULL
, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP
, NULL
);
1161 tmp
= aim_ssi_itemlist_add(&od
->ssi
.local
, "1", 0x0000, 0xFFFF, AIM_SSI_TYPE_ICONINFO
, NULL
);
1164 /* Need to add the 0x00d5 TLV to the TLV chain */
1165 csumdata
= (guint8
*)g_malloc((iconsumlen
+2)*sizeof(guint8
));
1166 (void)aimutil_put8(&csumdata
[0], 0x00);
1167 (void)aimutil_put8(&csumdata
[1], iconsumlen
);
1168 memcpy(&csumdata
[2], iconsum
, iconsumlen
);
1169 aim_tlvlist_replace_raw(&tmp
->data
, 0x00d5, (iconsumlen
+2) * sizeof(guint8
), csumdata
);
1172 /* Need to add the 0x0131 TLV to the TLV chain, used to cache the icon */
1173 aim_tlvlist_replace_noval(&tmp
->data
, 0x0131);
1175 /* Sync our local list with the server list */
1181 * Remove a reference to a server stored buddy icon. This will make your
1182 * icon stop showing up to other people.
1184 * Really this function just sets the icon to a dummy value. It's weird...
1185 * but I think the dummy value basically means "I don't have an icon!"
1187 * @param od The oscar session.
1188 * @return Return 0 if no errors, otherwise return the error number.
1190 int aim_ssi_delicon(OscarData
*od
)
1192 const guint8 csumdata
[] = {0x02, 0x01, 0xd2, 0x04, 0x72};
1194 return aim_ssi_seticon(od
, csumdata
, 5);
1198 * Stores your setting for various SSI settings. Whether you
1199 * should show up as idle or not, etc.
1201 * @param od The oscar odion.
1202 * @param presence A bitmask of the first 32 entries [0-31] from
1203 * http://dev.aol.com/aim/oscar/#FEEDBAG__BUDDY_PREFS
1204 * 0x00000002 - Hide "eBuddy group" (whatever that is)
1205 * 0x00000400 - Allow others to see your idle time
1206 * 0x00020000 - Don't show Recent Buddies
1207 * @return Return 0 if no errors, otherwise return the error number.
1209 int aim_ssi_setpresence(OscarData
*od
, guint32 presence
) {
1210 struct aim_ssi_item
*tmp
;
1212 if (!od
|| !od
->ssi
.received_data
)
1215 /* Find the PRESENCEPREFS item, or add it if it does not exist */
1216 if (!(tmp
= aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, NULL
, AIM_SSI_TYPE_PRESENCEPREFS
))) {
1217 /* Make sure the master group exists */
1218 if (aim_ssi_itemlist_find(&od
->ssi
.local
, 0x0000, 0x0000) == NULL
)
1219 aim_ssi_itemlist_add(&od
->ssi
.local
, NULL
, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP
, NULL
);
1221 tmp
= aim_ssi_itemlist_add(&od
->ssi
.local
, NULL
, 0x0000, 0xFFFF, AIM_SSI_TYPE_PRESENCEPREFS
, NULL
);
1224 /* Need to add the x00c9 TLV to the TLV chain */
1225 aim_tlvlist_replace_32(&tmp
->data
, 0x00c9, presence
);
1227 /* Sync our local list with the server list */
1228 return aim_ssi_sync(od
);
1232 * Subtype 0x0002 - Request SSI Rights.
1234 int aim_ssi_reqrights(OscarData
*od
)
1236 FlapConnection
*conn
;
1238 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)))
1241 aim_genericreq_n_snacid(od
, conn
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_REQRIGHTS
);
1247 * Subtype 0x0003 - SSI Rights Information.
1249 static int parserights(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1252 aim_rxcallback_t userfunc
;
1258 /* This SNAC is made up of a bunch of TLVs */
1259 tlvlist
= aim_tlvlist_read(bs
);
1261 /* TLV 0x0004 contains the maximum number of each item */
1262 if (!(tlv
= aim_tlv_gettlv(tlvlist
, 0x0004, 1))) {
1263 aim_tlvlist_free(tlvlist
);
1267 byte_stream_init(&bstream
, tlv
->value
, tlv
->length
);
1269 maxitems
= (guint16
*)g_malloc((tlv
->length
/2)*sizeof(guint16
));
1271 for (i
=0; i
<(tlv
->length
/2); i
++)
1272 maxitems
[i
] = byte_stream_get16(&bstream
);
1274 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1275 ret
= userfunc(od
, conn
, frame
, tlv
->length
/2, maxitems
);
1277 aim_tlvlist_free(tlvlist
);
1284 * Subtype 0x0004 - Request SSI Data when you don't have a timestamp and
1288 int aim_ssi_reqdata(OscarData
*od
)
1290 FlapConnection
*conn
;
1292 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)))
1295 /* Free any current data, just in case */
1296 aim_ssi_freelist(od
);
1298 aim_genericreq_n_snacid(od
, conn
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_REQDATA
);
1304 * Subtype 0x0006 - SSI Data.
1306 static int parsedata(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1309 aim_rxcallback_t userfunc
;
1310 guint8 fmtver
; /* guess */
1311 guint16 namelen
, gid
, bid
, type
;
1314 GString
*debugstr
= g_string_new("");
1316 fmtver
= byte_stream_get8(bs
); /* Version of ssi data. Should be 0x00 */
1317 od
->ssi
.numitems
+= byte_stream_get16(bs
); /* # of items in this SSI SNAC */
1319 /* Read in the list */
1320 while (byte_stream_bytes_left(bs
) > 4) { /* last four bytes are timestamp */
1321 if ((namelen
= byte_stream_get16(bs
)))
1322 name
= byte_stream_getstr(bs
, namelen
);
1325 gid
= byte_stream_get16(bs
);
1326 bid
= byte_stream_get16(bs
);
1327 type
= byte_stream_get16(bs
);
1328 data
= aim_tlvlist_readlen(bs
, byte_stream_get16(bs
));
1329 aim_ssi_item_debug_append(debugstr
, "\t", aim_ssi_itemlist_add(&od
->ssi
.official
, name
, gid
, bid
, type
, data
));
1331 aim_tlvlist_free(data
);
1333 purple_debug_misc("oscar", "Reading items from tlvlist for account %s:\n%s",
1334 purple_account_get_username(purple_connection_get_account(od
->gc
)), debugstr
->str
);
1335 g_string_free(debugstr
, TRUE
);
1337 /* Read in the timestamp */
1338 od
->ssi
.timestamp
= byte_stream_get32(bs
);
1340 if (!(snac
->flags
& 0x0001)) {
1341 /* Make a copy of the list */
1342 struct aim_ssi_item
*cur
;
1343 for (cur
=od
->ssi
.official
.data
; cur
; cur
=cur
->next
)
1344 aim_ssi_itemlist_add(&od
->ssi
.local
, cur
->name
, cur
->gid
, cur
->bid
, cur
->type
, cur
->data
);
1346 /* Clean the buddy list */
1347 aim_ssi_cleanlist(od
);
1349 od
->ssi
.received_data
= TRUE
;
1351 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1352 ret
= userfunc(od
, conn
, frame
, fmtver
, od
->ssi
.numitems
, od
->ssi
.timestamp
);
1359 * Subtype 0x0007 - SSI Activate Data.
1361 * Should be sent after receiving 13/6 or 13/f to tell the server you
1362 * are ready to begin using the list. It will promptly give you the
1363 * presence information for everyone in your list and put your permit/deny
1364 * settings into effect.
1367 int aim_ssi_enable(OscarData
*od
)
1369 FlapConnection
*conn
;
1371 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)))
1374 aim_genericreq_n(od
, conn
, SNAC_FAMILY_FEEDBAG
, 0x0007);
1380 * Subtype 0x0008/0x0009/0x000a - SSI Add/Mod/Del Item(s).
1382 * Sends the SNAC to add, modify, or delete items from the server-stored
1383 * information. These 3 SNACs all have an identical structure. The only
1384 * difference is the subtype that is set for the SNAC.
1387 static int aim_ssi_addmoddel(OscarData
*od
)
1389 FlapConnection
*conn
;
1391 aim_snacid_t snacid
;
1393 struct aim_ssi_tmp
*cur
;
1395 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)) || !od
->ssi
.pending
|| !od
->ssi
.pending
->item
)
1398 /* Calculate total SNAC size */
1400 for (cur
=od
->ssi
.pending
; cur
; cur
=cur
->next
) {
1401 bslen
+= 10; /* For length, GID, BID, type, and length */
1402 if (cur
->item
->name
)
1403 bslen
+= strlen(cur
->item
->name
);
1404 if (cur
->item
->data
)
1405 bslen
+= aim_tlvlist_size(cur
->item
->data
);
1408 byte_stream_new(&bs
, bslen
);
1410 for (cur
=od
->ssi
.pending
; cur
; cur
=cur
->next
) {
1411 byte_stream_put16(&bs
, cur
->item
->name
? strlen(cur
->item
->name
) : 0);
1412 if (cur
->item
->name
)
1413 byte_stream_putstr(&bs
, cur
->item
->name
);
1414 byte_stream_put16(&bs
, cur
->item
->gid
);
1415 byte_stream_put16(&bs
, cur
->item
->bid
);
1416 byte_stream_put16(&bs
, cur
->item
->type
);
1417 byte_stream_put16(&bs
, cur
->item
->data
? aim_tlvlist_size(cur
->item
->data
) : 0);
1418 if (cur
->item
->data
)
1419 aim_tlvlist_write(&bs
, &cur
->item
->data
);
1422 snacid
= aim_cachesnac(od
, SNAC_FAMILY_FEEDBAG
, od
->ssi
.pending
->action
, 0x0000, NULL
, 0);
1423 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_FEEDBAG
, od
->ssi
.pending
->action
, snacid
, &bs
);
1425 byte_stream_destroy(&bs
);
1431 * Subtype 0x0008 - Incoming SSI add.
1433 * Sent by the server, for example, when someone is added to
1434 * your "Recent Buddies" group.
1436 static int parseadd(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1439 aim_rxcallback_t userfunc
;
1441 guint16 len
, gid
, bid
, type
;
1444 while (byte_stream_bytes_left(bs
)) {
1445 if ((len
= byte_stream_get16(bs
)))
1446 name
= byte_stream_getstr(bs
, len
);
1449 gid
= byte_stream_get16(bs
);
1450 bid
= byte_stream_get16(bs
);
1451 type
= byte_stream_get16(bs
);
1452 if ((len
= byte_stream_get16(bs
)))
1453 data
= aim_tlvlist_readlen(bs
, len
);
1457 aim_ssi_itemlist_add(&od
->ssi
.local
, name
, gid
, bid
, type
, data
);
1458 aim_ssi_itemlist_add(&od
->ssi
.official
, name
, gid
, bid
, type
, data
);
1459 aim_tlvlist_free(data
);
1461 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1462 ret
= userfunc(od
, conn
, frame
, snac
->subtype
, type
, name
);
1471 * Subtype 0x0009 - Incoming SSI mod.
1473 static int parsemod(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1476 aim_rxcallback_t userfunc
;
1478 guint16 len
, gid
, bid
, type
;
1480 struct aim_ssi_item
*item
;
1482 while (byte_stream_bytes_left(bs
)) {
1483 if ((len
= byte_stream_get16(bs
)))
1484 name
= byte_stream_getstr(bs
, len
);
1487 gid
= byte_stream_get16(bs
);
1488 bid
= byte_stream_get16(bs
);
1489 type
= byte_stream_get16(bs
);
1490 if ((len
= byte_stream_get16(bs
)))
1491 data
= aim_tlvlist_readlen(bs
, len
);
1495 /* Replace the 2 local items with the given one */
1496 if ((item
= aim_ssi_itemlist_find(&od
->ssi
.local
, gid
, bid
))) {
1498 aim_ssi_item_set_name(&od
->ssi
.local
, item
, name
);
1499 aim_tlvlist_free(item
->data
);
1500 item
->data
= aim_tlvlist_copy(data
);
1503 if ((item
= aim_ssi_itemlist_find(&od
->ssi
.official
, gid
, bid
))) {
1505 aim_ssi_item_set_name(&od
->ssi
.official
, item
, name
);
1506 aim_tlvlist_free(item
->data
);
1507 item
->data
= aim_tlvlist_copy(data
);
1510 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1511 ret
= userfunc(od
, conn
, frame
, snac
->subtype
, type
, name
);
1514 aim_tlvlist_free(data
);
1521 * Subtype 0x000a - Incoming SSI del.
1523 * XXX - It would probably be good for the client to actually do something when it gets this.
1525 static int parsedel(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1528 aim_rxcallback_t userfunc
;
1530 struct aim_ssi_item
*del
;
1532 while (byte_stream_bytes_left(bs
)) {
1533 byte_stream_advance(bs
, byte_stream_get16(bs
));
1534 gid
= byte_stream_get16(bs
);
1535 bid
= byte_stream_get16(bs
);
1536 byte_stream_get16(bs
);
1537 byte_stream_advance(bs
, byte_stream_get16(bs
));
1539 if ((del
= aim_ssi_itemlist_find(&od
->ssi
.local
, gid
, bid
)))
1540 aim_ssi_itemlist_del(&od
->ssi
.local
, del
);
1541 if ((del
= aim_ssi_itemlist_find(&od
->ssi
.official
, gid
, bid
)))
1542 aim_ssi_itemlist_del(&od
->ssi
.official
, del
);
1544 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1545 ret
= userfunc(od
, conn
, frame
);
1552 * Subtype 0x000e - SSI Add/Mod/Del Ack.
1554 * Response to add, modify, or delete SNAC (sent with aim_ssi_addmoddel).
1557 static int parseack(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1560 aim_rxcallback_t userfunc
;
1561 struct aim_ssi_tmp
*cur
, *del
;
1563 /* Read in the success/failure flags from the ack SNAC */
1564 cur
= od
->ssi
.pending
;
1565 while (cur
&& (byte_stream_bytes_left(bs
)>0)) {
1566 cur
->ack
= byte_stream_get16(bs
);
1571 * If outcome is 0, then add the item to the item list, or replace the other item,
1572 * or remove the old item. If outcome is non-zero, then remove the item from the
1573 * local list, or unmodify it, or add it.
1575 for (cur
=od
->ssi
.pending
; (cur
&& (cur
->ack
!= 0xffff)); cur
=cur
->next
) {
1578 /* Our action was unsuccessful, so change the local list back to how it was */
1579 if (cur
->action
== SNAC_SUBTYPE_FEEDBAG_ADD
) {
1580 /* Remove the item from the local list */
1581 /* Make sure cur->item is still valid memory */
1582 /* TODO: "Still valid memory"? That's bad form. */
1583 if (aim_ssi_itemlist_valid(&od
->ssi
.local
, cur
->item
)) {
1584 cur
->name
= g_strdup(cur
->item
->name
);
1585 aim_ssi_itemlist_del(&od
->ssi
.local
, cur
->item
);
1589 } else if (cur
->action
== SNAC_SUBTYPE_FEEDBAG_MOD
) {
1590 /* Replace the local item with the item from the official list */
1591 if (aim_ssi_itemlist_valid(&od
->ssi
.local
, cur
->item
)) {
1592 struct aim_ssi_item
*cur1
;
1593 if ((cur1
= aim_ssi_itemlist_find(&od
->ssi
.official
, cur
->item
->gid
, cur
->item
->bid
))) {
1594 aim_ssi_item_set_name(&od
->ssi
.official
, cur
->item
, cur1
->name
);
1595 aim_tlvlist_free(cur
->item
->data
);
1596 cur
->item
->data
= aim_tlvlist_copy(cur1
->data
);
1601 } else if (cur
->action
== SNAC_SUBTYPE_FEEDBAG_DEL
) {
1602 /* Add the item back into the local list */
1603 if (aim_ssi_itemlist_valid(&od
->ssi
.official
, cur
->item
)) {
1604 aim_ssi_itemlist_add(&od
->ssi
.local
, cur
->item
->name
, cur
->item
->gid
, cur
->item
->bid
, cur
->item
->type
, cur
->item
->data
);
1610 /* Do the exact opposite */
1611 if (cur
->action
== SNAC_SUBTYPE_FEEDBAG_ADD
) {
1612 /* Add the local item to the official list */
1613 if (aim_ssi_itemlist_valid(&od
->ssi
.local
, cur
->item
)) {
1614 aim_ssi_itemlist_add(&od
->ssi
.official
, cur
->item
->name
, cur
->item
->gid
, cur
->item
->bid
, cur
->item
->type
, cur
->item
->data
);
1618 } else if (cur
->action
== SNAC_SUBTYPE_FEEDBAG_MOD
) {
1619 /* Replace the official item with the item from the local list */
1620 if (aim_ssi_itemlist_valid(&od
->ssi
.local
, cur
->item
)) {
1621 struct aim_ssi_item
*cur1
;
1622 if ((cur1
= aim_ssi_itemlist_find(&od
->ssi
.official
, cur
->item
->gid
, cur
->item
->bid
))) {
1623 aim_ssi_item_set_name(&od
->ssi
.official
, cur1
, cur
->item
->name
);
1624 aim_tlvlist_free(cur1
->data
);
1625 cur1
->data
= aim_tlvlist_copy(cur
->item
->data
);
1630 } else if (cur
->action
== SNAC_SUBTYPE_FEEDBAG_DEL
) {
1631 /* Remove the item from the official list */
1632 if (aim_ssi_itemlist_valid(&od
->ssi
.official
, cur
->item
))
1633 aim_ssi_itemlist_del(&od
->ssi
.official
, cur
->item
);
1638 } /* End if (cur->item) */
1639 } /* End for loop */
1641 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1642 ret
= userfunc(od
, conn
, frame
, od
->ssi
.pending
);
1644 /* Free all aim_ssi_tmp's with an outcome */
1645 cur
= od
->ssi
.pending
;
1646 while (cur
&& (cur
->ack
!= 0xffff)) {
1652 od
->ssi
.pending
= cur
;
1654 /* If we're not waiting for any more acks, then send more SNACs */
1655 if (!od
->ssi
.pending
) {
1656 od
->ssi
.waiting_for_ack
= FALSE
;
1664 * Subtype 0x000f - SSI Data Unchanged.
1666 * Response to aim_ssi_reqifchanged() if the server-side data is not newer than
1667 * posted local stamp/revision.
1670 static int parsedataunchanged(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1673 aim_rxcallback_t userfunc
;
1675 od
->ssi
.received_data
= TRUE
;
1677 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1678 ret
= userfunc(od
, conn
, frame
);
1684 * Subtype 0x0011 - SSI Begin Data Modification.
1686 * Tell the server you're going to start modifying data. This marks
1687 * the beginning of a transaction.
1689 int aim_ssi_modbegin(OscarData
*od
)
1691 FlapConnection
*conn
;
1693 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)))
1696 aim_genericreq_n(od
, conn
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_EDITSTART
);
1702 * Subtype 0x0012 - SSI End Data Modification.
1704 * Tell the server you're finished modifying data. The marks the end
1707 int aim_ssi_modend(OscarData
*od
)
1709 FlapConnection
*conn
;
1711 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)))
1714 aim_genericreq_n(od
, conn
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_EDITSTOP
);
1720 * Subtype 0x0015 - Receive an authorization grant
1722 static int receiveauthgrant(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1725 aim_rxcallback_t userfunc
;
1727 char *bn
, *msg
, *tmpstr
;
1729 /* Read buddy name */
1730 tmp
= byte_stream_get8(bs
);
1732 purple_debug_warning("oscar", "Dropping auth grant SNAC "
1733 "because username was empty\n");
1736 bn
= byte_stream_getstr(bs
, tmp
);
1737 if (!g_utf8_validate(bn
, -1, NULL
)) {
1738 purple_debug_warning("oscar", "Dropping auth grant SNAC "
1739 "because the username was not valid UTF-8\n");
1745 tmp
= byte_stream_get16(bs
);
1747 msg
= byte_stream_getstr(bs
, tmp
);
1748 if (!g_utf8_validate(msg
, -1, NULL
)) {
1749 /* Ugh, msg isn't UTF8. Let's salvage. */
1750 purple_debug_warning("oscar", "Got non-UTF8 message in auth "
1751 "grant from %s\n", bn
);
1752 tmpstr
= purple_utf8_salvage(msg
);
1760 tmp
= byte_stream_get16(bs
);
1762 purple_debug_warning("oscar", "unknown field missing");
1764 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1765 ret
= userfunc(od
, conn
, frame
, bn
, msg
);
1774 * Subtype 0x0018 - Send authorization request
1776 * Sends a request for authorization to the given contact. The request will either be
1777 * granted, denied, or dropped.
1780 int aim_ssi_sendauthrequest(OscarData
*od
, const char *bn
, const char *msg
)
1782 FlapConnection
*conn
;
1784 aim_snacid_t snacid
;
1786 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)) || !bn
)
1789 byte_stream_new(&bs
, 1+strlen(bn
) + 2+(msg
? strlen(msg
)+1 : 0) + 2);
1792 byte_stream_put8(&bs
, strlen(bn
));
1793 byte_stream_putstr(&bs
, bn
);
1795 /* Message (null terminated) */
1796 byte_stream_put16(&bs
, msg
? strlen(msg
) : 0);
1798 byte_stream_putstr(&bs
, msg
);
1799 byte_stream_put8(&bs
, 0x00);
1803 byte_stream_put16(&bs
, 0x0000);
1805 snacid
= aim_cachesnac(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ
, 0x0000, NULL
, 0);
1806 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ
, snacid
, &bs
);
1808 byte_stream_destroy(&bs
);
1814 * Subtype 0x0019 - Receive an authorization request
1816 static int receiveauthrequest(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1819 aim_rxcallback_t userfunc
;
1821 char *bn
, *msg
, *tmpstr
;
1823 /* Read buddy name */
1824 tmp
= byte_stream_get8(bs
);
1826 purple_debug_warning("oscar", "Dropping auth request SNAC "
1827 "because username was empty\n");
1830 bn
= byte_stream_getstr(bs
, tmp
);
1831 if (!g_utf8_validate(bn
, -1, NULL
)) {
1832 purple_debug_warning("oscar", "Dropping auth request SNAC "
1833 "because the username was not valid UTF-8\n");
1839 tmp
= byte_stream_get16(bs
);
1841 msg
= byte_stream_getstr(bs
, tmp
);
1842 if (!g_utf8_validate(msg
, -1, NULL
)) {
1843 /* Ugh, msg isn't UTF8. Let's salvage. */
1844 purple_debug_warning("oscar", "Got non-UTF8 message in auth "
1845 "request from %s\n", bn
);
1846 tmpstr
= purple_utf8_salvage(msg
);
1854 tmp
= byte_stream_get16(bs
);
1856 purple_debug_warning("oscar", "unknown field missing");
1858 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1859 ret
= userfunc(od
, conn
, frame
, bn
, msg
);
1868 * Subtype 0x001a - Send authorization reply
1870 * Sends a reply to a request for authorization. The reply can either
1871 * grant authorization or deny authorization.
1873 * if reply=0x00 then deny
1874 * if reply=0x01 then grant
1877 int aim_ssi_sendauthreply(OscarData
*od
, const char *bn
, guint8 reply
, const char *msg
)
1879 FlapConnection
*conn
;
1881 aim_snacid_t snacid
;
1883 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_FEEDBAG
)) || !bn
)
1886 byte_stream_new(&bs
, 1+strlen(bn
) + 1 + 2+(msg
? (strlen(msg
)+1) : 0) + 2);
1889 byte_stream_put8(&bs
, strlen(bn
));
1890 byte_stream_putstr(&bs
, bn
);
1893 byte_stream_put8(&bs
, reply
);
1895 /* Message (null terminated) */
1896 byte_stream_put16(&bs
, msg
? (strlen(msg
)+1) : 0);
1898 byte_stream_putstr(&bs
, msg
);
1899 byte_stream_put8(&bs
, 0x00);
1903 byte_stream_put16(&bs
, 0x0000);
1905 snacid
= aim_cachesnac(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP
, 0x0000, NULL
, 0);
1906 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP
, snacid
, &bs
);
1908 byte_stream_destroy(&bs
);
1914 * Subtype 0x001b - Receive an authorization reply
1916 * You get this bad boy when other people respond to the authorization
1917 * request that you have previously sent them.
1919 static int receiveauthreply(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1922 aim_rxcallback_t userfunc
;
1925 char *bn
, *msg
, *tmpstr
;
1927 /* Read buddy name */
1928 tmp
= byte_stream_get8(bs
);
1930 purple_debug_warning("oscar", "Dropping auth reply SNAC "
1931 "because username was empty\n");
1934 bn
= byte_stream_getstr(bs
, tmp
);
1935 if (!g_utf8_validate(bn
, -1, NULL
)) {
1936 purple_debug_warning("oscar", "Dropping auth reply SNAC "
1937 "because the username was not valid UTF-8\n");
1943 reply
= byte_stream_get8(bs
);
1946 tmp
= byte_stream_get16(bs
);
1948 msg
= byte_stream_getstr(bs
, tmp
);
1949 if (!g_utf8_validate(msg
, -1, NULL
)) {
1950 /* Ugh, msg isn't UTF8. Let's salvage. */
1951 purple_debug_warning("oscar", "Got non-UTF8 message in auth "
1952 "reply from %s\n", bn
);
1953 tmpstr
= purple_utf8_salvage(msg
);
1961 tmp
= byte_stream_get16(bs
);
1963 purple_debug_warning("oscar", "unknown field missing");
1965 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
1966 ret
= userfunc(od
, conn
, frame
, bn
, reply
, msg
);
1975 * Subtype 0x001c - Receive a message telling you someone added you to their list.
1977 static int receiveadded(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
1980 aim_rxcallback_t userfunc
;
1984 /* Read buddy name */
1985 tmp
= byte_stream_get8(bs
);
1987 purple_debug_warning("oscar", "Dropping 'you were added' SNAC "
1988 "because username was empty\n");
1991 bn
= byte_stream_getstr(bs
, tmp
);
1992 if (!g_utf8_validate(bn
, -1, NULL
)) {
1993 purple_debug_warning("oscar", "Dropping 'you were added' SNAC "
1994 "because the username was not valid UTF-8\n");
1999 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
2000 ret
= userfunc(od
, conn
, frame
, bn
);
2008 * If we're on ICQ, then AIM_SSI_TYPE_DENY is used for the "permanently invisible" list.
2009 * AIM_SSI_TYPE_ICQDENY is used for blocking users instead.
2012 aim_ssi_getdenyentrytype(OscarData
* od
)
2014 return od
->icq
? AIM_SSI_TYPE_ICQDENY
: AIM_SSI_TYPE_DENY
;
2018 snachandler(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
2020 if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_RIGHTSINFO
)
2021 return parserights(od
, conn
, mod
, frame
, snac
, bs
);
2022 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_LIST
)
2023 return parsedata(od
, conn
, mod
, frame
, snac
, bs
);
2024 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_ADD
)
2025 return parseadd(od
, conn
, mod
, frame
, snac
, bs
);
2026 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_MOD
)
2027 return parsemod(od
, conn
, mod
, frame
, snac
, bs
);
2028 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_DEL
)
2029 return parsedel(od
, conn
, mod
, frame
, snac
, bs
);
2030 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_SRVACK
)
2031 return parseack(od
, conn
, mod
, frame
, snac
, bs
);
2032 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_NOLIST
)
2033 return parsedataunchanged(od
, conn
, mod
, frame
, snac
, bs
);
2034 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_RECVAUTH
)
2035 return receiveauthgrant(od
, conn
, mod
, frame
, snac
, bs
);
2036 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_RECVAUTHREQ
)
2037 return receiveauthrequest(od
, conn
, mod
, frame
, snac
, bs
);
2038 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_RECVAUTHREP
)
2039 return receiveauthreply(od
, conn
, mod
, frame
, snac
, bs
);
2040 else if (snac
->subtype
== SNAC_SUBTYPE_FEEDBAG_ADDED
)
2041 return receiveadded(od
, conn
, mod
, frame
, snac
, bs
);
2047 ssi_shutdown(OscarData
*od
, aim_module_t
*mod
)
2049 aim_ssi_freelist(od
);
2053 ssi_modfirst(OscarData
*od
, aim_module_t
*mod
)
2055 mod
->family
= SNAC_FAMILY_FEEDBAG
;
2056 mod
->version
= 0x0004;
2057 mod
->toolid
= 0x0110;
2058 mod
->toolversion
= 0x0629;
2060 strncpy(mod
->name
, "feedbag", sizeof(mod
->name
));
2061 mod
->snachandler
= snachandler
;
2062 mod
->shutdown
= ssi_shutdown
;