comparison libpurple/protocols/oscar/family_feedbag.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /*
2 * Gaim's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
5 *
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.
10 *
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.
15 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /*
22 * Family 0x0013 - Server-Side/Stored Information.
23 *
24 * Relatively new facility that allows certain types of information, such as
25 * a user's buddy list, permit/deny list, and permit/deny preferences, to be
26 * stored on the server, so that they can be accessed from any client.
27 *
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.
32 *
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).
35 *
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.
40 *
41 * This is entirely too complicated.
42 * You don't know the half of it.
43 *
44 */
45
46 #include "oscar.h"
47
48 static int aim_ssi_addmoddel(OscarData *od);
49
50 /**
51 * Locally rebuild the 0x00c8 TLV in the additional data of the given group.
52 *
53 * @param list A pointer to a pointer to the current list of items.
54 * @param name A null terminated string containing the group name, or NULL
55 * if you want to modify the master group.
56 * @return Return a pointer to the modified item.
57 */
58 static struct aim_ssi_item *aim_ssi_itemlist_rebuildgroup(struct aim_ssi_item *list, const char *name)
59 {
60 int newlen;
61 struct aim_ssi_item *cur, *group;
62
63 if (!list)
64 return NULL;
65
66 /* Find the group */
67 if (!(group = aim_ssi_itemlist_finditem(list, name, NULL, AIM_SSI_TYPE_GROUP)))
68 return NULL;
69
70 /* Find the length for the new additional data */
71 newlen = 0;
72 if (group->gid == 0x0000) {
73 for (cur=list; cur; cur=cur->next)
74 if ((cur->type == AIM_SSI_TYPE_GROUP) && (cur->gid != 0x0000))
75 newlen += 2;
76 } else {
77 for (cur=list; cur; cur=cur->next)
78 if ((cur->gid == group->gid) && (cur->type == AIM_SSI_TYPE_BUDDY))
79 newlen += 2;
80 }
81
82 /* Build the new TLV list */
83 if (newlen > 0) {
84 guint8 *newdata;
85
86 newdata = (guint8 *)malloc((newlen)*sizeof(guint8));
87 newlen = 0;
88 if (group->gid == 0x0000) {
89 for (cur=list; cur; cur=cur->next)
90 if ((cur->type == AIM_SSI_TYPE_GROUP) && (cur->gid != 0x0000))
91 newlen += aimutil_put16(newdata+newlen, cur->gid);
92 } else {
93 for (cur=list; cur; cur=cur->next)
94 if ((cur->gid == group->gid) && (cur->type == AIM_SSI_TYPE_BUDDY))
95 newlen += aimutil_put16(newdata+newlen, cur->bid);
96 }
97 aim_tlvlist_replace_raw(&group->data, 0x00c8, newlen, newdata);
98
99 free(newdata);
100 }
101
102 return group;
103 }
104
105 /**
106 * Locally add a new item to the given item list.
107 *
108 * @param list A pointer to a pointer to the current list of items.
109 * @param name A null terminated string of the name of the new item, or NULL if the
110 * item should have no name.
111 * @param gid The group ID# you want the new item to have, or 0xFFFF if we should pick something.
112 * @param bid The buddy ID# you want the new item to have, or 0xFFFF if we should pick something.
113 * @param type The type of the item, 0x0000 for a contact, 0x0001 for a group, etc.
114 * @param data The additional data for the new item.
115 * @return A pointer to the newly created item.
116 */
117 static struct aim_ssi_item *aim_ssi_itemlist_add(struct aim_ssi_item **list, const char *name, guint16 gid, guint16 bid, guint16 type, aim_tlvlist_t *data)
118 {
119 int i;
120 struct aim_ssi_item *cur, *new;
121
122 if (!list)
123 return NULL;
124
125 new = (struct aim_ssi_item *)malloc(sizeof(struct aim_ssi_item));
126
127 /* Set the name */
128 if (name) {
129 new->name = (char *)malloc((strlen(name)+1)*sizeof(char));
130 strcpy(new->name, name);
131 } else
132 new->name = NULL;
133
134 /* Set the group ID# and buddy ID# */
135 new->gid = gid;
136 new->bid = bid;
137 if (type == AIM_SSI_TYPE_GROUP) {
138 if ((new->gid == 0xFFFF) && name) {
139 do {
140 new->gid += 0x0001;
141 for (cur=*list, i=0; ((cur) && (!i)); cur=cur->next)
142 if ((cur->type == AIM_SSI_TYPE_GROUP) && (cur->gid == new->gid))
143 i=1;
144 } while (i);
145 }
146 } else {
147 if (new->bid == 0xFFFF) {
148 do {
149 new->bid += 0x0001;
150 for (cur=*list, i=0; ((cur) && (!i)); cur=cur->next)
151 if ((cur->bid == new->bid) && (cur->gid == new->gid))
152 i=1;
153 } while (i);
154 }
155 }
156
157 /* Set the type */
158 new->type = type;
159
160 /* Set the TLV list */
161 new->data = aim_tlvlist_copy(data);
162
163 /* Add the item to the list in the correct numerical position. Fancy, eh? */
164 if (*list) {
165 if ((new->gid < (*list)->gid) || ((new->gid == (*list)->gid) && (new->bid < (*list)->bid))) {
166 new->next = *list;
167 *list = new;
168 } else {
169 struct aim_ssi_item *prev;
170 for ((prev=*list, cur=(*list)->next); (cur && ((new->gid > cur->gid) || ((new->gid == cur->gid) && (new->bid > cur->bid)))); prev=cur, cur=cur->next);
171 new->next = prev->next;
172 prev->next = new;
173 }
174 } else {
175 new->next = *list;
176 *list = new;
177 }
178
179 return new;
180 }
181
182 /**
183 * Locally delete an item from the given item list.
184 *
185 * @param list A pointer to a pointer to the current list of items.
186 * @param del A pointer to the item you want to remove from the list.
187 * @return Return 0 if no errors, otherwise return the error number.
188 */
189 static int aim_ssi_itemlist_del(struct aim_ssi_item **list, struct aim_ssi_item *del)
190 {
191 if (!list || !(*list) || !del)
192 return -EINVAL;
193
194 /* Remove the item from the list */
195 if (*list == del) {
196 *list = (*list)->next;
197 } else {
198 struct aim_ssi_item *cur;
199 for (cur=*list; (cur->next && (cur->next!=del)); cur=cur->next);
200 if (cur->next)
201 cur->next = del->next;
202 }
203
204 /* Free the removed item */
205 free(del->name);
206 aim_tlvlist_free(&del->data);
207 free(del);
208
209 return 0;
210 }
211
212 /**
213 * Compare two items to see if they have the same data.
214 *
215 * @param cur1 A pointer to a pointer to the first item.
216 * @param cur2 A pointer to a pointer to the second item.
217 * @return Return 0 if no differences, or a number if there are differences.
218 */
219 static int aim_ssi_itemlist_cmp(struct aim_ssi_item *cur1, struct aim_ssi_item *cur2)
220 {
221 if (!cur1 || !cur2)
222 return 1;
223
224 if (cur1->data && !cur2->data)
225 return 2;
226
227 if (!cur1->data && cur2->data)
228 return 3;
229
230 if ((cur1->data && cur2->data) && (aim_tlvlist_cmp(cur1->data, cur2->data)))
231 return 4;
232
233 if (cur1->name && !cur2->name)
234 return 5;
235
236 if (!cur1->name && cur2->name)
237 return 6;
238
239 if (cur1->name && cur2->name && aim_sncmp(cur1->name, cur2->name))
240 return 7;
241
242 if (cur1->gid != cur2->gid)
243 return 8;
244
245 if (cur1->bid != cur2->bid)
246 return 9;
247
248 if (cur1->type != cur2->type)
249 return 10;
250
251 return 0;
252 }
253
254 static int aim_ssi_itemlist_valid(struct aim_ssi_item *list, struct aim_ssi_item *item)
255 {
256 struct aim_ssi_item *cur;
257 for (cur=list; cur; cur=cur->next)
258 if (cur == item)
259 return 1;
260 return 0;
261 }
262
263 /**
264 * Locally find an item given a group ID# and a buddy ID#.
265 *
266 * @param list A pointer to the current list of items.
267 * @param gid The group ID# of the desired item.
268 * @param bid The buddy ID# of the desired item.
269 * @return Return a pointer to the item if found, else return NULL;
270 */
271 struct aim_ssi_item *aim_ssi_itemlist_find(struct aim_ssi_item *list, guint16 gid, guint16 bid)
272 {
273 struct aim_ssi_item *cur;
274 for (cur=list; cur; cur=cur->next)
275 if ((cur->gid == gid) && (cur->bid == bid))
276 return cur;
277 return NULL;
278 }
279
280 /**
281 * Locally find an item given a group name, screen name, and type. If group name
282 * and screen name are null, then just return the first item of the given type.
283 *
284 * @param list A pointer to the current list of items.
285 * @param gn The group name of the desired item.
286 * @param bn The buddy name of the desired item.
287 * @param type The type of the desired item.
288 * @return Return a pointer to the item if found, else return NULL.
289 */
290 struct aim_ssi_item *aim_ssi_itemlist_finditem(struct aim_ssi_item *list, const char *gn, const char *sn, guint16 type)
291 {
292 struct aim_ssi_item *cur;
293 if (!list)
294 return NULL;
295
296 if (gn && sn) { /* For finding buddies in groups */
297 for (cur=list; cur; cur=cur->next)
298 if ((cur->type == type) && (cur->name) && !(aim_sncmp(cur->name, sn))) {
299 struct aim_ssi_item *curg;
300 for (curg=list; curg; curg=curg->next)
301 if ((curg->type == AIM_SSI_TYPE_GROUP) && (curg->gid == cur->gid) && (curg->name) && !(aim_sncmp(curg->name, gn)))
302 return cur;
303 }
304
305 } else if (gn) { /* For finding groups */
306 for (cur=list; cur; cur=cur->next) {
307 if ((cur->type == type) && (cur->bid == 0x0000) && (cur->name) && !(aim_sncmp(cur->name, gn))) {
308 return cur;
309 }
310 }
311
312 } else if (sn) { /* For finding permits, denies, and ignores */
313 for (cur=list; cur; cur=cur->next) {
314 if ((cur->type == type) && (cur->name) && !(aim_sncmp(cur->name, sn))) {
315 return cur;
316 }
317 }
318
319 /* For stuff without names--permit deny setting, visibility mask, etc. */
320 } else for (cur=list; cur; cur=cur->next) {
321 if ((cur->type == type) && (!cur->name))
322 return cur;
323 }
324
325 return NULL;
326 }
327
328 /**
329 * Check if the given buddy exists in any group in the buddy list.
330 *
331 * @param list A pointer to the current list of items.
332 * @param sn The group name of the desired item.
333 * @return Return a pointer to the name of the item if found, else return NULL;
334 */
335 struct aim_ssi_item *aim_ssi_itemlist_exists(struct aim_ssi_item *list, const char *sn)
336 {
337 struct aim_ssi_item *cur;
338 if (!list || !sn)
339 return NULL;
340 for (cur=list; cur; cur=cur->next)
341 if ((cur->type == AIM_SSI_TYPE_BUDDY) && (cur->name) && (!aim_sncmp(cur->name, sn)))
342 return cur;
343 return NULL;
344 }
345
346 /**
347 * Locally find the parent item of the given buddy name.
348 *
349 * @param list A pointer to the current list of items.
350 * @param bn The buddy name of the desired item.
351 * @return Return a pointer to the name of the item if found, else return NULL;
352 */
353 char *aim_ssi_itemlist_findparentname(struct aim_ssi_item *list, const char *sn)
354 {
355 struct aim_ssi_item *cur, *curg;
356 if (!list || !sn)
357 return NULL;
358 if (!(cur = aim_ssi_itemlist_exists(list, sn)))
359 return NULL;
360 if (!(curg = aim_ssi_itemlist_find(list, cur->gid, 0x0000)))
361 return NULL;
362 return curg->name;
363 }
364
365 /**
366 * Locally find the permit/deny setting item, and return the setting.
367 *
368 * @param list A pointer to the current list of items.
369 * @return Return the current SSI permit deny setting, or 0 if no setting was found.
370 */
371 int aim_ssi_getpermdeny(struct aim_ssi_item *list)
372 {
373 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PDINFO);
374 if (cur) {
375 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x00ca, 1);
376 if (tlv && tlv->value)
377 return aimutil_get8(tlv->value);
378 }
379 return 0;
380 }
381
382 /**
383 * Locally find the presence flag item, and return the setting. The returned setting is a
384 * bitmask of the user flags that you are visible to. See the AIM_FLAG_* #defines
385 * in oscar.h
386 *
387 * @param list A pointer to the current list of items.
388 * @return Return the current visibility mask.
389 */
390 guint32 aim_ssi_getpresence(struct aim_ssi_item *list)
391 {
392 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS);
393 if (cur) {
394 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x00c9, 1);
395 if (tlv && tlv->length)
396 return aimutil_get32(tlv->value);
397 }
398 return 0xFFFFFFFF;
399 }
400
401 /**
402 * Locally find the alias of the given buddy.
403 *
404 * @param list A pointer to the current list of items.
405 * @param gn The group of the buddy.
406 * @param sn The name of the buddy.
407 * @return A pointer to a NULL terminated string that is the buddy's
408 * alias, or NULL if the buddy has no alias. You should free
409 * this returned value!
410 */
411 char *aim_ssi_getalias(struct aim_ssi_item *list, const char *gn, const char *sn)
412 {
413 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY);
414 if (cur) {
415 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x0131, 1);
416 if (tlv && tlv->length) {
417 char *alias = (char *)malloc((tlv->length+1)*sizeof(char));
418 strncpy(alias, (char *)tlv->value, tlv->length);
419 alias[tlv->length] = 0;
420 return alias;
421 }
422 }
423 return NULL;
424 }
425
426 /**
427 * Locally find the comment of the given buddy.
428 *
429 * @param list A pointer to the current list of items.
430 * @param gn The group of the buddy.
431 * @param sn The name of the buddy.
432 * @return A pointer to a NULL terminated string that is the buddy's
433 * comment, or NULL if the buddy has no comment. You should free
434 * this returned value!
435 */
436 char *aim_ssi_getcomment(struct aim_ssi_item *list, const char *gn, const char *sn)
437 {
438 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY);
439 if (cur) {
440 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x013c, 1);
441 if (tlv && tlv->length) {
442 char *alias = (char *)malloc((tlv->length+1)*sizeof(char));
443 strncpy(alias, (char *)tlv->value, tlv->length);
444 alias[tlv->length] = 0;
445 return alias;
446 }
447 }
448 return NULL;
449 }
450
451 /**
452 * Locally find if you are waiting for authorization for a buddy.
453 *
454 * @param list A pointer to the current list of items.
455 * @param gn The group of the buddy.
456 * @param sn The name of the buddy.
457 * @return 1 if you are waiting for authorization; 0 if you are not
458 */
459 gboolean aim_ssi_waitingforauth(struct aim_ssi_item *list, const char *gn, const char *sn)
460 {
461 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY);
462 if (cur) {
463 if (aim_tlv_gettlv(cur->data, 0x0066, 1))
464 return TRUE;
465 }
466 return FALSE;
467 }
468
469 /**
470 * If there are changes, then create temporary items and
471 * call addmoddel.
472 *
473 * @param od The oscar session.
474 * @return Return 0 if no errors, otherwise return the error number.
475 */
476 static int aim_ssi_sync(OscarData *od)
477 {
478 struct aim_ssi_item *cur1, *cur2;
479 struct aim_ssi_tmp *cur, *new;
480 int n = 0;
481
482 /*
483 * The variable "n" is used to limit the number of addmoddel's that
484 * are performed in a single SNAC. It will hopefully keep the size
485 * of the SNAC below the maximum SNAC size.
486 */
487
488 if (!od)
489 return -EINVAL;
490
491 /* If we're waiting for an ack, we shouldn't do anything else */
492 if (od->ssi.waiting_for_ack)
493 return 0;
494
495 /*
496 * Compare the 2 lists and create an aim_ssi_tmp for each difference.
497 * We should only send either additions, modifications, or deletions
498 * before waiting for an acknowledgement. So first do deletions, then
499 * additions, then modifications. Also, both the official and the local
500 * list should be in ascending numerical order for the group ID#s and the
501 * buddy ID#s, which makes things more efficient. I think.
502 */
503
504 /* Additions */
505 if (!od->ssi.pending) {
506 for (cur1=od->ssi.local; cur1 && (n < 15); cur1=cur1->next) {
507 if (!aim_ssi_itemlist_find(od->ssi.official, cur1->gid, cur1->bid)) {
508 n++;
509 new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
510 new->action = SNAC_SUBTYPE_FEEDBAG_ADD;
511 new->ack = 0xffff;
512 new->name = NULL;
513 new->item = cur1;
514 new->next = NULL;
515 if (od->ssi.pending) {
516 for (cur=od->ssi.pending; cur->next; cur=cur->next);
517 cur->next = new;
518 } else
519 od->ssi.pending = new;
520 }
521 }
522 }
523
524 /* Deletions */
525 if (!od->ssi.pending) {
526 for (cur1=od->ssi.official; cur1 && (n < 15); cur1=cur1->next) {
527 if (!aim_ssi_itemlist_find(od->ssi.local, cur1->gid, cur1->bid)) {
528 n++;
529 new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
530 new->action = SNAC_SUBTYPE_FEEDBAG_DEL;
531 new->ack = 0xffff;
532 new->name = NULL;
533 new->item = cur1;
534 new->next = NULL;
535 if (od->ssi.pending) {
536 for (cur=od->ssi.pending; cur->next; cur=cur->next);
537 cur->next = new;
538 } else
539 od->ssi.pending = new;
540 }
541 }
542 }
543
544 /* Modifications */
545 if (!od->ssi.pending) {
546 for (cur1=od->ssi.local; cur1 && (n < 15); cur1=cur1->next) {
547 cur2 = aim_ssi_itemlist_find(od->ssi.official, cur1->gid, cur1->bid);
548 if (cur2 && (aim_ssi_itemlist_cmp(cur1, cur2))) {
549 n++;
550 new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
551 new->action = SNAC_SUBTYPE_FEEDBAG_MOD;
552 new->ack = 0xffff;
553 new->name = NULL;
554 new->item = cur1;
555 new->next = NULL;
556 if (od->ssi.pending) {
557 for (cur=od->ssi.pending; cur->next; cur=cur->next);
558 cur->next = new;
559 } else
560 od->ssi.pending = new;
561 }
562 }
563 }
564
565 /* We're out of stuff to do, so tell the AIM servers we're done and exit */
566 if (!od->ssi.pending) {
567 aim_ssi_modend(od);
568 od->ssi.in_transaction = FALSE;
569 return 0;
570 }
571
572 /* If this is the first in a series of add/mod/del
573 * requests then send the "begin transaction" message. */
574 if (!od->ssi.in_transaction)
575 {
576 aim_ssi_modbegin(od);
577 od->ssi.in_transaction = TRUE;
578 }
579
580 /* Make sure we don't send anything else between now
581 * and when we receive the ack for the following operation */
582 od->ssi.waiting_for_ack = TRUE;
583
584 /* Now go mail off our data and wait 4 to 6 weeks */
585 aim_ssi_addmoddel(od);
586
587 return 0;
588 }
589
590 /**
591 * Free all SSI data.
592 *
593 * This doesn't remove it from the server, that's different.
594 *
595 * @param od The oscar odion.
596 * @return Return 0 if no errors, otherwise return the error number.
597 */
598 static int aim_ssi_freelist(OscarData *od)
599 {
600 struct aim_ssi_item *cur, *del;
601 struct aim_ssi_tmp *curtmp, *deltmp;
602
603 cur = od->ssi.official;
604 while (cur) {
605 del = cur;
606 cur = cur->next;
607 free(del->name);
608 aim_tlvlist_free(&del->data);
609 free(del);
610 }
611
612 cur = od->ssi.local;
613 while (cur) {
614 del = cur;
615 cur = cur->next;
616 free(del->name);
617 aim_tlvlist_free(&del->data);
618 free(del);
619 }
620
621 curtmp = od->ssi.pending;
622 while (curtmp) {
623 deltmp = curtmp;
624 curtmp = curtmp->next;
625 free(deltmp);
626 }
627
628 od->ssi.numitems = 0;
629 od->ssi.official = NULL;
630 od->ssi.local = NULL;
631 od->ssi.pending = NULL;
632 od->ssi.timestamp = (time_t)0;
633
634 return 0;
635 }
636
637 /**
638 * Delete all SSI data.
639 *
640 * @param od The oscar odion.
641 * @return Return 0 if no errors, otherwise return the error number.
642 */
643 int aim_ssi_deletelist(OscarData *od)
644 {
645 struct aim_ssi_item *cur, *del;
646
647 if (!od)
648 return -EINVAL;
649
650 /* Free the local list */
651 cur = od->ssi.local;
652 while (cur) {
653 del = cur;
654 cur = cur->next;
655 free(del->name);
656 aim_tlvlist_free(&del->data);
657 free(del);
658 }
659 od->ssi.local = NULL;
660
661 /* Sync our local list with the server list */
662 aim_ssi_sync(od);
663
664 return 0;
665 }
666
667 /**
668 * This "cleans" the ssi list. It does the following:
669 * 1) Makes sure all buddies, permits, and denies have names.
670 * 2) Makes sure that all buddies are in a group that exist.
671 * 3) Deletes any empty groups
672 *
673 * @param od The oscar odion.
674 * @return Return 0 if no errors, otherwise return the error number.
675 */
676 int aim_ssi_cleanlist(OscarData *od)
677 {
678 struct aim_ssi_item *cur, *next;
679
680 if (!od)
681 return -EINVAL;
682
683 /* Delete any buddies, permits, or denies with empty names. */
684 /* If there are any buddies directly in the master group, add them to a real group. */
685 /* DESTROY any buddies that are directly in the master group. */
686 /* Do the same for buddies that are in a non-existant group. */
687 /* This will kind of mess up if you hit the item limit, but this function isn't too critical */
688 cur = od->ssi.local;
689 while (cur) {
690 next = cur->next;
691 if (!cur->name) {
692 if (cur->type == AIM_SSI_TYPE_BUDDY)
693 aim_ssi_delbuddy(od, NULL, NULL);
694 else if (cur->type == AIM_SSI_TYPE_PERMIT)
695 aim_ssi_delpermit(od, NULL);
696 else if (cur->type == AIM_SSI_TYPE_DENY)
697 aim_ssi_deldeny(od, NULL);
698 } else if ((cur->type == AIM_SSI_TYPE_BUDDY) && ((cur->gid == 0x0000) || (!aim_ssi_itemlist_find(od->ssi.local, cur->gid, 0x0000)))) {
699 char *alias = aim_ssi_getalias(od->ssi.local, NULL, cur->name);
700 aim_ssi_addbuddy(od, cur->name, "orphans", alias, NULL, NULL, 0);
701 aim_ssi_delbuddy(od, cur->name, NULL);
702 free(alias);
703 }
704 cur = next;
705 }
706
707 /* Make sure there aren't any duplicate buddies in a group, or duplicate permits or denies */
708 cur = od->ssi.local;
709 while (cur) {
710 if ((cur->type == AIM_SSI_TYPE_BUDDY) || (cur->type == AIM_SSI_TYPE_PERMIT) || (cur->type == AIM_SSI_TYPE_DENY))
711 {
712 struct aim_ssi_item *cur2, *next2;
713 cur2 = cur->next;
714 while (cur2) {
715 next2 = cur2->next;
716 if ((cur->type == cur2->type) && (cur->gid == cur2->gid) && (cur->name != NULL) && (cur2->name != NULL) && (!aim_sncmp(cur->name, cur2->name))) {
717 aim_ssi_itemlist_del(&od->ssi.local, cur2);
718 }
719 cur2 = next2;
720 }
721 }
722 cur = cur->next;
723 }
724
725 /* Check if there are empty groups and delete them */
726 cur = od->ssi.local;
727 while (cur) {
728 next = cur->next;
729 if (cur->type == AIM_SSI_TYPE_GROUP) {
730 aim_tlv_t *tlv = aim_tlv_gettlv(cur->data, 0x00c8, 1);
731 if (!tlv || !tlv->length)
732 aim_ssi_itemlist_del(&od->ssi.local, cur);
733 }
734 cur = next;
735 }
736
737 /* Check if the master group is empty */
738 if ((cur = aim_ssi_itemlist_find(od->ssi.local, 0x0000, 0x0000)) && (!cur->data))
739 aim_ssi_itemlist_del(&od->ssi.local, cur);
740
741 /* If we've made any changes then sync our list with the server's */
742 aim_ssi_sync(od);
743
744 return 0;
745 }
746
747 /**
748 * Add a buddy to the list.
749 *
750 * @param od The oscar odion.
751 * @param name The name of the item.
752 * @param group The group of the item.
753 * @param alias The alias/nickname of the item, or NULL.
754 * @param comment The buddy comment for the item, or NULL.
755 * @param smsnum The locally assigned SMS number, or NULL.
756 * @return Return 0 if no errors, otherwise return the error number.
757 */
758 int aim_ssi_addbuddy(OscarData *od, const char *name, const char *group, const char *alias, const char *comment, const char *smsnum, int needauth)
759 {
760 struct aim_ssi_item *parent;
761 aim_tlvlist_t *data = NULL;
762
763 if (!od || !name || !group)
764 return -EINVAL;
765
766 /* Find the parent */
767 if (!(parent = aim_ssi_itemlist_finditem(od->ssi.local, group, NULL, AIM_SSI_TYPE_GROUP))) {
768 /* Find the parent's parent (the master group) */
769 if (aim_ssi_itemlist_find(od->ssi.local, 0x0000, 0x0000) == NULL)
770 if (aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0x0000, AIM_SSI_TYPE_GROUP, NULL) == NULL)
771 return -ENOMEM;
772 /* Add the parent */
773 if (!(parent = aim_ssi_itemlist_add(&od->ssi.local, group, 0xFFFF, 0x0000, AIM_SSI_TYPE_GROUP, NULL)))
774 return -ENOMEM;
775
776 /* Modify the parent's parent (the master group) */
777 aim_ssi_itemlist_rebuildgroup(od->ssi.local, NULL);
778 }
779
780 /* Create a TLV list for the new buddy */
781 if (needauth)
782 aim_tlvlist_add_noval(&data, 0x0066);
783 if (alias)
784 aim_tlvlist_add_str(&data, 0x0131, alias);
785 if (smsnum)
786 aim_tlvlist_add_str(&data, 0x013a, smsnum);
787 if (comment)
788 aim_tlvlist_add_str(&data, 0x013c, comment);
789
790 /* Add that bad boy */
791 aim_ssi_itemlist_add(&od->ssi.local, name, parent->gid, 0xFFFF, AIM_SSI_TYPE_BUDDY, data);
792 aim_tlvlist_free(&data);
793
794 /* Modify the parent group */
795 aim_ssi_itemlist_rebuildgroup(od->ssi.local, group);
796
797 /* Sync our local list with the server list */
798 aim_ssi_sync(od);
799
800 return 0;
801 }
802
803 /**
804 * Add a permit buddy to the list.
805 *
806 * @param od The oscar odion.
807 * @param name The name of the item..
808 * @return Return 0 if no errors, otherwise return the error number.
809 */
810 int aim_ssi_addpermit(OscarData *od, const char *name)
811 {
812
813 if (!od || !name)
814 return -EINVAL;
815
816 /* Add that bad boy */
817 aim_ssi_itemlist_add(&od->ssi.local, name, 0x0000, 0xFFFF, AIM_SSI_TYPE_PERMIT, NULL);
818
819 /* Sync our local list with the server list */
820 aim_ssi_sync(od);
821
822 return 0;
823 }
824
825 /**
826 * Add a deny buddy to the list.
827 *
828 * @param od The oscar odion.
829 * @param name The name of the item..
830 * @return Return 0 if no errors, otherwise return the error number.
831 */
832 int aim_ssi_adddeny(OscarData *od, const char *name)
833 {
834
835 if (!od || !name)
836 return -EINVAL;
837
838 /* Add that bad boy */
839 aim_ssi_itemlist_add(&od->ssi.local, name, 0x0000, 0xFFFF, AIM_SSI_TYPE_DENY, NULL);
840
841 /* Sync our local list with the server list */
842 aim_ssi_sync(od);
843
844 return 0;
845 }
846
847 /**
848 * Deletes a buddy from the list.
849 *
850 * @param od The oscar odion.
851 * @param name The name of the item, or NULL.
852 * @param group The group of the item, or NULL.
853 * @return Return 0 if no errors, otherwise return the error number.
854 */
855 int aim_ssi_delbuddy(OscarData *od, const char *name, const char *group)
856 {
857 struct aim_ssi_item *del;
858
859 if (!od)
860 return -EINVAL;
861
862 /* Find the buddy */
863 if (!(del = aim_ssi_itemlist_finditem(od->ssi.local, group, name, AIM_SSI_TYPE_BUDDY)))
864 return -EINVAL;
865
866 /* Remove the item from the list */
867 aim_ssi_itemlist_del(&od->ssi.local, del);
868
869 /* Modify the parent group */
870 aim_ssi_itemlist_rebuildgroup(od->ssi.local, group);
871
872 /* Check if we should delete the parent group */
873 if ((del = aim_ssi_itemlist_finditem(od->ssi.local, group, NULL, AIM_SSI_TYPE_GROUP)) && (!del->data)) {
874 aim_ssi_itemlist_del(&od->ssi.local, del);
875
876 /* Modify the parent group */
877 aim_ssi_itemlist_rebuildgroup(od->ssi.local, NULL);
878
879 /* Check if we should delete the parent's parent (the master group) */
880 if ((del = aim_ssi_itemlist_find(od->ssi.local, 0x0000, 0x0000)) && (!del->data)) {
881 aim_ssi_itemlist_del(&od->ssi.local, del);
882 }
883 }
884
885 /* Sync our local list with the server list */
886 aim_ssi_sync(od);
887
888 return 0;
889 }
890
891 /**
892 * Deletes a permit buddy from the list.
893 *
894 * @param od The oscar odion.
895 * @param name The name of the item, or NULL.
896 * @return Return 0 if no errors, otherwise return the error number.
897 */
898 int aim_ssi_delpermit(OscarData *od, const char *name)
899 {
900 struct aim_ssi_item *del;
901
902 if (!od)
903 return -EINVAL;
904
905 /* Find the item */
906 if (!(del = aim_ssi_itemlist_finditem(od->ssi.local, NULL, name, AIM_SSI_TYPE_PERMIT)))
907 return -EINVAL;
908
909 /* Remove the item from the list */
910 aim_ssi_itemlist_del(&od->ssi.local, del);
911
912 /* Sync our local list with the server list */
913 aim_ssi_sync(od);
914
915 return 0;
916 }
917
918 /**
919 * Deletes a deny buddy from the list.
920 *
921 * @param od The oscar odion.
922 * @param name The name of the item, or NULL.
923 * @return Return 0 if no errors, otherwise return the error number.
924 */
925 int aim_ssi_deldeny(OscarData *od, const char *name)
926 {
927 struct aim_ssi_item *del;
928
929 if (!od)
930 return -EINVAL;
931
932 /* Find the item */
933 if (!(del = aim_ssi_itemlist_finditem(od->ssi.local, NULL, name, AIM_SSI_TYPE_DENY)))
934 return -EINVAL;
935
936 /* Remove the item from the list */
937 aim_ssi_itemlist_del(&od->ssi.local, del);
938
939 /* Sync our local list with the server list */
940 aim_ssi_sync(od);
941
942 return 0;
943 }
944
945 /**
946 * Move a buddy from one group to another group. This basically just deletes the
947 * buddy and re-adds it.
948 *
949 * @param od The oscar odion.
950 * @param oldgn The group that the buddy is currently in.
951 * @param newgn The group that the buddy should be moved in to.
952 * @param sn The name of the buddy to be moved.
953 * @return Return 0 if no errors, otherwise return the error number.
954 */
955 int aim_ssi_movebuddy(OscarData *od, const char *oldgn, const char *newgn, const char *sn)
956 {
957 char *alias;
958 gboolean waitingforauth;
959
960 alias = aim_ssi_getalias(od->ssi.local, oldgn, sn);
961 waitingforauth = aim_ssi_waitingforauth(od->ssi.local, oldgn, sn);
962
963 aim_ssi_delbuddy(od, sn, oldgn);
964 aim_ssi_addbuddy(od, sn, newgn, alias, NULL, NULL, waitingforauth);
965
966 free(alias);
967
968 return 0;
969 }
970
971 /**
972 * Change the alias stored on the server for a given buddy.
973 *
974 * @param od The oscar odion.
975 * @param gn The group that the buddy is currently in.
976 * @param sn The screen name of the buddy.
977 * @param alias The new alias for the buddy, or NULL if you want to remove
978 * a buddy's comment.
979 * @return Return 0 if no errors, otherwise return the error number.
980 */
981 int aim_ssi_aliasbuddy(OscarData *od, const char *gn, const char *sn, const char *alias)
982 {
983 struct aim_ssi_item *tmp;
984
985 if (!od || !gn || !sn)
986 return -EINVAL;
987
988 if (!(tmp = aim_ssi_itemlist_finditem(od->ssi.local, gn, sn, AIM_SSI_TYPE_BUDDY)))
989 return -EINVAL;
990
991 /* Either add or remove the 0x0131 TLV from the TLV chain */
992 if ((alias != NULL) && (strlen(alias) > 0))
993 aim_tlvlist_replace_str(&tmp->data, 0x0131, alias);
994 else
995 aim_tlvlist_remove(&tmp->data, 0x0131);
996
997 /* Sync our local list with the server list */
998 aim_ssi_sync(od);
999
1000 return 0;
1001 }
1002
1003 /**
1004 * Change the comment stored on the server for a given buddy.
1005 *
1006 * @param od The oscar odion.
1007 * @param gn The group that the buddy is currently in.
1008 * @param sn The screen name of the buddy.
1009 * @param alias The new comment for the buddy, or NULL if you want to remove
1010 * a buddy's comment.
1011 * @return Return 0 if no errors, otherwise return the error number.
1012 */
1013 int aim_ssi_editcomment(OscarData *od, const char *gn, const char *sn, const char *comment)
1014 {
1015 struct aim_ssi_item *tmp;
1016
1017 if (!od || !gn || !sn)
1018 return -EINVAL;
1019
1020 if (!(tmp = aim_ssi_itemlist_finditem(od->ssi.local, gn, sn, AIM_SSI_TYPE_BUDDY)))
1021 return -EINVAL;
1022
1023 /* Either add or remove the 0x0131 TLV from the TLV chain */
1024 if ((comment != NULL) && (strlen(comment) > 0))
1025 aim_tlvlist_replace_str(&tmp->data, 0x013c, comment);
1026 else
1027 aim_tlvlist_remove(&tmp->data, 0x013c);
1028
1029 /* Sync our local list with the server list */
1030 aim_ssi_sync(od);
1031
1032 return 0;
1033 }
1034
1035 /**
1036 * Rename a group.
1037 *
1038 * @param od The oscar odion.
1039 * @param oldgn The old group name.
1040 * @param newgn The new group name.
1041 * @return Return 0 if no errors, otherwise return the error number.
1042 */
1043 int aim_ssi_rename_group(OscarData *od, const char *oldgn, const char *newgn)
1044 {
1045 struct aim_ssi_item *group;
1046
1047 if (!od || !oldgn || !newgn)
1048 return -EINVAL;
1049
1050 if (!(group = aim_ssi_itemlist_finditem(od->ssi.local, oldgn, NULL, AIM_SSI_TYPE_GROUP)))
1051 return -EINVAL;
1052
1053 free(group->name);
1054 group->name = (char *)malloc((strlen(newgn)+1)*sizeof(char));
1055 strcpy(group->name, newgn);
1056
1057 /* Sync our local list with the server list */
1058 aim_ssi_sync(od);
1059
1060 return 0;
1061 }
1062
1063 /**
1064 * Stores your permit/deny setting on the server, and starts using it.
1065 *
1066 * @param od The oscar odion.
1067 * @param permdeny Your permit/deny setting. Can be one of the following:
1068 * 1 - Allow all users
1069 * 2 - Block all users
1070 * 3 - Allow only the users below
1071 * 4 - Block only the users below
1072 * 5 - Allow only users on my buddy list
1073 * @param vismask A bitmask of the class of users to whom you want to be
1074 * visible. See the AIM_FLAG_BLEH #defines in oscar.h
1075 * @return Return 0 if no errors, otherwise return the error number.
1076 */
1077 int aim_ssi_setpermdeny(OscarData *od, guint8 permdeny, guint32 vismask)
1078 {
1079 struct aim_ssi_item *tmp;
1080
1081 if (!od)
1082 return -EINVAL;
1083
1084 /* Find the PDINFO item, or add it if it does not exist */
1085 if (!(tmp = aim_ssi_itemlist_finditem(od->ssi.local, NULL, NULL, AIM_SSI_TYPE_PDINFO)))
1086 tmp = aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PDINFO, NULL);
1087
1088 /* Need to add the 0x00ca TLV to the TLV chain */
1089 aim_tlvlist_replace_8(&tmp->data, 0x00ca, permdeny);
1090
1091 /* Need to add the 0x00cb TLV to the TLV chain */
1092 aim_tlvlist_replace_32(&tmp->data, 0x00cb, vismask);
1093
1094 /* Sync our local list with the server list */
1095 aim_ssi_sync(od);
1096
1097 return 0;
1098 }
1099
1100 /**
1101 * Set buddy icon information
1102 *
1103 * @param od The oscar odion.
1104 * @param iconcsum The MD5 checksum of the icon you are using.
1105 * @param iconcsumlen Length of the MD5 checksum given above. Should be 0x10 bytes.
1106 * @return Return 0 if no errors, otherwise return the error number.
1107 */
1108 int aim_ssi_seticon(OscarData *od, const guint8 *iconsum, guint16 iconsumlen)
1109 {
1110 struct aim_ssi_item *tmp;
1111 guint8 *csumdata;
1112
1113 if (!od || !iconsum || !iconsumlen)
1114 return -EINVAL;
1115
1116 /* Find the ICONINFO item, or add it if it does not exist */
1117 if (!(tmp = aim_ssi_itemlist_finditem(od->ssi.local, NULL, "1", AIM_SSI_TYPE_ICONINFO))) {
1118 tmp = aim_ssi_itemlist_add(&od->ssi.local, "1", 0x0000, 0xFFFF, AIM_SSI_TYPE_ICONINFO, NULL);
1119 }
1120
1121 /* Need to add the 0x00d5 TLV to the TLV chain */
1122 csumdata = (guint8 *)malloc((iconsumlen+2)*sizeof(guint8));
1123 aimutil_put16(&csumdata[0], iconsumlen);
1124 memcpy(&csumdata[2], iconsum, iconsumlen);
1125 aim_tlvlist_replace_raw(&tmp->data, 0x00d5, (iconsumlen+2) * sizeof(guint8), csumdata);
1126 free(csumdata);
1127
1128 /* Need to add the 0x0131 TLV to the TLV chain, used to cache the icon */
1129 aim_tlvlist_replace_noval(&tmp->data, 0x0131);
1130
1131 /* Sync our local list with the server list */
1132 aim_ssi_sync(od);
1133 return 0;
1134 }
1135
1136 /**
1137 * Remove a reference to a server stored buddy icon. This will make your
1138 * icon stop showing up to other people.
1139 *
1140 * Really this function just sets the icon to a dummy value. It's weird...
1141 * but I think the dummy value basically means "I don't have an icon!"
1142 *
1143 * @param od The oscar session.
1144 * @return Return 0 if no errors, otherwise return the error number.
1145 */
1146 int aim_ssi_delicon(OscarData *od)
1147 {
1148 const guint8 csumdata[] = {0x02, 0x01, 0xd2, 0x04, 0x72};
1149
1150 return aim_ssi_seticon(od, csumdata, 5);
1151 }
1152
1153 /**
1154 * Stores your setting for various SSI settings. Whether you
1155 * should show up as idle or not, etc.
1156 *
1157 * @param od The oscar odion.
1158 * @param presence I think it's a bitmask, but I only know what one of the bits is:
1159 * 0x00000002 - Hide wireless?
1160 * 0x00000400 - Allow others to see your idle time
1161 * @return Return 0 if no errors, otherwise return the error number.
1162 */
1163 int aim_ssi_setpresence(OscarData *od, guint32 presence) {
1164 struct aim_ssi_item *tmp;
1165
1166 if (!od)
1167 return -EINVAL;
1168
1169 /* Find the PRESENCEPREFS item, or add it if it does not exist */
1170 if (!(tmp = aim_ssi_itemlist_finditem(od->ssi.local, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS)))
1171 tmp = aim_ssi_itemlist_add(&od->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PRESENCEPREFS, NULL);
1172
1173 /* Need to add the x00c9 TLV to the TLV chain */
1174 aim_tlvlist_replace_32(&tmp->data, 0x00c9, presence);
1175
1176 /* Sync our local list with the server list */
1177 aim_ssi_sync(od);
1178
1179 return 0;
1180 }
1181
1182 /*
1183 * Subtype 0x0002 - Request SSI Rights.
1184 */
1185 int aim_ssi_reqrights(OscarData *od)
1186 {
1187 FlapConnection *conn;
1188
1189 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1190 return -EINVAL;
1191
1192 aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_REQRIGHTS);
1193
1194 return 0;
1195 }
1196
1197 /*
1198 * Subtype 0x0003 - SSI Rights Information.
1199 */
1200 static int parserights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1201 {
1202 int ret = 0, i;
1203 aim_rxcallback_t userfunc;
1204 aim_tlvlist_t *tlvlist;
1205 aim_tlv_t *tlv;
1206 ByteStream bstream;
1207 guint16 *maxitems;
1208
1209 /* This SNAC is made up of a bunch of TLVs */
1210 tlvlist = aim_tlvlist_read(bs);
1211
1212 /* TLV 0x0004 contains the maximum number of each item */
1213 if (!(tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) {
1214 aim_tlvlist_free(&tlvlist);
1215 return 0;
1216 }
1217
1218 byte_stream_init(&bstream, tlv->value, tlv->length);
1219
1220 maxitems = (guint16 *)malloc((tlv->length/2)*sizeof(guint16));
1221
1222 for (i=0; i<(tlv->length/2); i++)
1223 maxitems[i] = byte_stream_get16(&bstream);
1224
1225 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1226 ret = userfunc(od, conn, frame, tlv->length/2, maxitems);
1227
1228 aim_tlvlist_free(&tlvlist);
1229 free(maxitems);
1230
1231 return ret;
1232 }
1233
1234 /*
1235 * Subtype 0x0004 - Request SSI Data when you don't have a timestamp and
1236 * revision number.
1237 *
1238 */
1239 int aim_ssi_reqdata(OscarData *od)
1240 {
1241 FlapConnection *conn;
1242
1243 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1244 return -EINVAL;
1245
1246 /* Free any current data, just in case */
1247 aim_ssi_freelist(od);
1248
1249 aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_REQDATA);
1250
1251 return 0;
1252 }
1253
1254 /*
1255 * Subtype 0x0005 - Request SSI Data when you have a timestamp and revision
1256 * number.
1257 *
1258 * The data will only be sent if it is newer than the posted local
1259 * timestamp and revision.
1260 *
1261 * Note that the client should never increment the revision, only the server.
1262 *
1263 */
1264 int aim_ssi_reqifchanged(OscarData *od, time_t timestamp, guint16 numitems)
1265 {
1266 FlapConnection *conn;
1267 FlapFrame *frame;
1268 aim_snacid_t snacid;
1269
1270 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1271 return -EINVAL;
1272
1273 frame = flap_frame_new(od, 0x02, 10+4+2);
1274
1275 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_REQIFCHANGED, 0x0000, NULL, 0);
1276
1277 aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_REQIFCHANGED, 0x0000, snacid);
1278 byte_stream_put32(&frame->data, timestamp);
1279 byte_stream_put16(&frame->data, numitems);
1280
1281 flap_connection_send(conn, frame);
1282
1283 /* Free any current data, just in case */
1284 aim_ssi_freelist(od);
1285
1286 return 0;
1287 }
1288
1289 /*
1290 * Subtype 0x0006 - SSI Data.
1291 */
1292 static int parsedata(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1293 {
1294 int ret = 0;
1295 aim_rxcallback_t userfunc;
1296 guint8 fmtver; /* guess */
1297 guint16 namelen, gid, bid, type;
1298 char *name;
1299 aim_tlvlist_t *data;
1300
1301 fmtver = byte_stream_get8(bs); /* Version of ssi data. Should be 0x00 */
1302 od->ssi.numitems += byte_stream_get16(bs); /* # of items in this SSI SNAC */
1303
1304 /* Read in the list */
1305 while (byte_stream_empty(bs) > 4) { /* last four bytes are timestamp */
1306 if ((namelen = byte_stream_get16(bs)))
1307 name = byte_stream_getstr(bs, namelen);
1308 else
1309 name = NULL;
1310 gid = byte_stream_get16(bs);
1311 bid = byte_stream_get16(bs);
1312 type = byte_stream_get16(bs);
1313 data = aim_tlvlist_readlen(bs, byte_stream_get16(bs));
1314 aim_ssi_itemlist_add(&od->ssi.official, name, gid, bid, type, data);
1315 free(name);
1316 aim_tlvlist_free(&data);
1317 }
1318
1319 /* Read in the timestamp */
1320 od->ssi.timestamp = byte_stream_get32(bs);
1321
1322 if (!(snac->flags & 0x0001)) {
1323 /* Make a copy of the list */
1324 struct aim_ssi_item *cur;
1325 for (cur=od->ssi.official; cur; cur=cur->next)
1326 aim_ssi_itemlist_add(&od->ssi.local, cur->name, cur->gid, cur->bid, cur->type, cur->data);
1327
1328 od->ssi.received_data = TRUE;
1329
1330 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1331 ret = userfunc(od, conn, frame, fmtver, od->ssi.numitems, od->ssi.timestamp);
1332 }
1333
1334 return ret;
1335 }
1336
1337 /*
1338 * Subtype 0x0007 - SSI Activate Data.
1339 *
1340 * Should be sent after receiving 13/6 or 13/f to tell the server you
1341 * are ready to begin using the list. It will promptly give you the
1342 * presence information for everyone in your list and put your permit/deny
1343 * settings into effect.
1344 *
1345 */
1346 int aim_ssi_enable(OscarData *od)
1347 {
1348 FlapConnection *conn;
1349
1350 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1351 return -EINVAL;
1352
1353 aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, 0x0007);
1354
1355 return 0;
1356 }
1357
1358 /*
1359 * Subtype 0x0008/0x0009/0x000a - SSI Add/Mod/Del Item(s).
1360 *
1361 * Sends the SNAC to add, modify, or delete items from the server-stored
1362 * information. These 3 SNACs all have an identical structure. The only
1363 * difference is the subtype that is set for the SNAC.
1364 *
1365 */
1366 static int aim_ssi_addmoddel(OscarData *od)
1367 {
1368 FlapConnection *conn;
1369 FlapFrame *frame;
1370 aim_snacid_t snacid;
1371 int snaclen;
1372 struct aim_ssi_tmp *cur;
1373
1374 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !od->ssi.pending || !od->ssi.pending->item)
1375 return -EINVAL;
1376
1377 /* Calculate total SNAC size */
1378 snaclen = 10; /* For family, subtype, flags, and SNAC ID */
1379 for (cur=od->ssi.pending; cur; cur=cur->next) {
1380 snaclen += 10; /* For length, GID, BID, type, and length */
1381 if (cur->item->name)
1382 snaclen += strlen(cur->item->name);
1383 if (cur->item->data)
1384 snaclen += aim_tlvlist_size(&cur->item->data);
1385 }
1386
1387 frame = flap_frame_new(od, 0x02, snaclen);
1388
1389 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, od->ssi.pending->action, 0x0000, NULL, 0);
1390 aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, od->ssi.pending->action, 0x0000, snacid);
1391
1392 for (cur=od->ssi.pending; cur; cur=cur->next) {
1393 byte_stream_put16(&frame->data, cur->item->name ? strlen(cur->item->name) : 0);
1394 if (cur->item->name)
1395 byte_stream_putstr(&frame->data, cur->item->name);
1396 byte_stream_put16(&frame->data, cur->item->gid);
1397 byte_stream_put16(&frame->data, cur->item->bid);
1398 byte_stream_put16(&frame->data, cur->item->type);
1399 byte_stream_put16(&frame->data, cur->item->data ? aim_tlvlist_size(&cur->item->data) : 0);
1400 if (cur->item->data)
1401 aim_tlvlist_write(&frame->data, &cur->item->data);
1402 }
1403
1404 flap_connection_send(conn, frame);
1405
1406 return 0;
1407 }
1408
1409 /*
1410 * Subtype 0x0008 - Incoming SSI add.
1411 *
1412 * Sent by the server, for example, when someone is added to
1413 * your "Recent Buddies" group.
1414 */
1415 static int parseadd(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1416 {
1417 int ret = 0;
1418 aim_rxcallback_t userfunc;
1419 char *name;
1420 guint16 len, gid, bid, type;
1421 aim_tlvlist_t *data;
1422
1423 while (byte_stream_empty(bs)) {
1424 if ((len = byte_stream_get16(bs)))
1425 name = byte_stream_getstr(bs, len);
1426 else
1427 name = NULL;
1428 gid = byte_stream_get16(bs);
1429 bid = byte_stream_get16(bs);
1430 type = byte_stream_get16(bs);
1431 if ((len = byte_stream_get16(bs)))
1432 data = aim_tlvlist_readlen(bs, len);
1433 else
1434 data = NULL;
1435
1436 aim_ssi_itemlist_add(&od->ssi.local, name, gid, bid, type, data);
1437 aim_ssi_itemlist_add(&od->ssi.official, name, gid, bid, type, data);
1438 aim_tlvlist_free(&data);
1439
1440 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1441 ret = userfunc(od, conn, frame, type, name);
1442
1443 free(name);
1444 }
1445
1446 return ret;
1447 }
1448
1449 /*
1450 * Subtype 0x0009 - Incoming SSI mod.
1451 *
1452 * XXX - It would probably be good for the client to actually do something when it gets this.
1453 */
1454 static int parsemod(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1455 {
1456 int ret = 0;
1457 aim_rxcallback_t userfunc;
1458 char *name;
1459 guint16 len, gid, bid, type;
1460 aim_tlvlist_t *data;
1461 struct aim_ssi_item *item;
1462
1463 while (byte_stream_empty(bs)) {
1464 if ((len = byte_stream_get16(bs)))
1465 name = byte_stream_getstr(bs, len);
1466 else
1467 name = NULL;
1468 gid = byte_stream_get16(bs);
1469 bid = byte_stream_get16(bs);
1470 type = byte_stream_get16(bs);
1471 if ((len = byte_stream_get16(bs)))
1472 data = aim_tlvlist_readlen(bs, len);
1473 else
1474 data = NULL;
1475
1476 /* Replace the 2 local items with the given one */
1477 if ((item = aim_ssi_itemlist_find(od->ssi.local, gid, bid))) {
1478 item->type = type;
1479 free(item->name);
1480 if (name) {
1481 item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
1482 strcpy(item->name, name);
1483 } else
1484 item->name = NULL;
1485 aim_tlvlist_free(&item->data);
1486 item->data = aim_tlvlist_copy(data);
1487 }
1488
1489 if ((item = aim_ssi_itemlist_find(od->ssi.official, gid, bid))) {
1490 item->type = type;
1491 free(item->name);
1492 if (name) {
1493 item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
1494 strcpy(item->name, name);
1495 } else
1496 item->name = NULL;
1497 aim_tlvlist_free(&item->data);
1498 item->data = aim_tlvlist_copy(data);
1499 }
1500
1501 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1502 ret = userfunc(od, conn, frame);
1503
1504 free(name);
1505 aim_tlvlist_free(&data);
1506 }
1507
1508 return ret;
1509 }
1510
1511 /*
1512 * Subtype 0x000a - Incoming SSI del.
1513 *
1514 * XXX - It would probably be good for the client to actually do something when it gets this.
1515 */
1516 static int parsedel(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1517 {
1518 int ret = 0;
1519 aim_rxcallback_t userfunc;
1520 guint16 gid, bid;
1521 struct aim_ssi_item *del;
1522
1523 while (byte_stream_empty(bs)) {
1524 byte_stream_advance(bs, byte_stream_get16(bs));
1525 gid = byte_stream_get16(bs);
1526 bid = byte_stream_get16(bs);
1527 byte_stream_get16(bs);
1528 byte_stream_advance(bs, byte_stream_get16(bs));
1529
1530 if ((del = aim_ssi_itemlist_find(od->ssi.local, gid, bid)))
1531 aim_ssi_itemlist_del(&od->ssi.local, del);
1532 if ((del = aim_ssi_itemlist_find(od->ssi.official, gid, bid)))
1533 aim_ssi_itemlist_del(&od->ssi.official, del);
1534
1535 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1536 ret = userfunc(od, conn, frame);
1537 }
1538
1539 return ret;
1540 }
1541
1542 /*
1543 * Subtype 0x000e - SSI Add/Mod/Del Ack.
1544 *
1545 * Response to add, modify, or delete SNAC (sent with aim_ssi_addmoddel).
1546 *
1547 */
1548 static int parseack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1549 {
1550 int ret = 0;
1551 aim_rxcallback_t userfunc;
1552 struct aim_ssi_tmp *cur, *del;
1553
1554 /* Read in the success/failure flags from the ack SNAC */
1555 cur = od->ssi.pending;
1556 while (cur && (byte_stream_empty(bs)>0)) {
1557 cur->ack = byte_stream_get16(bs);
1558 cur = cur->next;
1559 }
1560
1561 /*
1562 * If outcome is 0, then add the item to the item list, or replace the other item,
1563 * or remove the old item. If outcome is non-zero, then remove the item from the
1564 * local list, or unmodify it, or add it.
1565 */
1566 for (cur=od->ssi.pending; (cur && (cur->ack != 0xffff)); cur=cur->next) {
1567 if (cur->item) {
1568 if (cur->ack) {
1569 /* Our action was unsuccessful, so change the local list back to how it was */
1570 if (cur->action == SNAC_SUBTYPE_FEEDBAG_ADD) {
1571 /* Remove the item from the local list */
1572 /* Make sure cur->item is still valid memory */
1573 if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {
1574 if (cur->item->name) {
1575 cur->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
1576 strcpy(cur->name, cur->item->name);
1577 }
1578 aim_ssi_itemlist_del(&od->ssi.local, cur->item);
1579 }
1580 cur->item = NULL;
1581
1582 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_MOD) {
1583 /* Replace the local item with the item from the official list */
1584 if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {
1585 struct aim_ssi_item *cur1;
1586 if ((cur1 = aim_ssi_itemlist_find(od->ssi.official, cur->item->gid, cur->item->bid))) {
1587 free(cur->item->name);
1588 if (cur1->name) {
1589 cur->item->name = (char *)malloc((strlen(cur1->name)+1)*sizeof(char));
1590 strcpy(cur->item->name, cur1->name);
1591 } else
1592 cur->item->name = NULL;
1593 aim_tlvlist_free(&cur->item->data);
1594 cur->item->data = aim_tlvlist_copy(cur1->data);
1595 }
1596 } else
1597 cur->item = NULL;
1598
1599 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_DEL) {
1600 /* Add the item back into the local list */
1601 if (aim_ssi_itemlist_valid(od->ssi.official, cur->item)) {
1602 aim_ssi_itemlist_add(&od->ssi.local, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
1603 } else
1604 cur->item = NULL;
1605 }
1606
1607 } else {
1608 /* Do the exact opposite */
1609 if (cur->action == SNAC_SUBTYPE_FEEDBAG_ADD) {
1610 /* Add the local item to the official list */
1611 if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {
1612 aim_ssi_itemlist_add(&od->ssi.official, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
1613 } else
1614 cur->item = NULL;
1615
1616 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_MOD) {
1617 /* Replace the official item with the item from the local list */
1618 if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {
1619 struct aim_ssi_item *cur1;
1620 if ((cur1 = aim_ssi_itemlist_find(od->ssi.official, cur->item->gid, cur->item->bid))) {
1621 free(cur1->name);
1622 if (cur->item->name) {
1623 cur1->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
1624 strcpy(cur1->name, cur->item->name);
1625 } else
1626 cur1->name = NULL;
1627 aim_tlvlist_free(&cur1->data);
1628 cur1->data = aim_tlvlist_copy(cur->item->data);
1629 }
1630 } else
1631 cur->item = NULL;
1632
1633 } else if (cur->action == SNAC_SUBTYPE_FEEDBAG_DEL) {
1634 /* Remove the item from the official list */
1635 if (aim_ssi_itemlist_valid(od->ssi.official, cur->item))
1636 aim_ssi_itemlist_del(&od->ssi.official, cur->item);
1637 cur->item = NULL;
1638 }
1639
1640 }
1641 } /* End if (cur->item) */
1642 } /* End for loop */
1643
1644 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1645 ret = userfunc(od, conn, frame, od->ssi.pending);
1646
1647 /* Free all aim_ssi_tmp's with an outcome */
1648 cur = od->ssi.pending;
1649 while (cur && (cur->ack != 0xffff)) {
1650 del = cur;
1651 cur = cur->next;
1652 free(del->name);
1653 free(del);
1654 }
1655 od->ssi.pending = cur;
1656
1657 /* If we're not waiting for any more acks, then send more SNACs */
1658 if (!od->ssi.pending) {
1659 od->ssi.waiting_for_ack = FALSE;
1660 aim_ssi_sync(od);
1661 }
1662
1663 return ret;
1664 }
1665
1666 /*
1667 * Subtype 0x000f - SSI Data Unchanged.
1668 *
1669 * Response to aim_ssi_reqifchanged() if the server-side data is not newer than
1670 * posted local stamp/revision.
1671 *
1672 */
1673 static int parsedataunchanged(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1674 {
1675 int ret = 0;
1676 aim_rxcallback_t userfunc;
1677
1678 od->ssi.received_data = TRUE;
1679
1680 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1681 ret = userfunc(od, conn, frame);
1682
1683 return ret;
1684 }
1685
1686 /*
1687 * Subtype 0x0011 - SSI Begin Data Modification.
1688 *
1689 * Tell the server you're going to start modifying data. This marks
1690 * the beginning of a transaction.
1691 */
1692 int aim_ssi_modbegin(OscarData *od)
1693 {
1694 FlapConnection *conn;
1695
1696 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1697 return -EINVAL;
1698
1699 aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_EDITSTART);
1700
1701 return 0;
1702 }
1703
1704 /*
1705 * Subtype 0x0012 - SSI End Data Modification.
1706 *
1707 * Tell the server you're finished modifying data. The marks the end
1708 * of a transaction.
1709 */
1710 int aim_ssi_modend(OscarData *od)
1711 {
1712 FlapConnection *conn;
1713
1714 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)))
1715 return -EINVAL;
1716
1717 aim_genericreq_n(od, conn, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_EDITSTOP);
1718
1719 return 0;
1720 }
1721
1722 /*
1723 * Subtype 0x0014 - Grant authorization
1724 *
1725 * Authorizes a contact so they can add you to their contact list.
1726 *
1727 */
1728 int aim_ssi_sendauth(OscarData *od, char *sn, char *msg)
1729 {
1730 FlapConnection *conn;
1731 FlapFrame *frame;
1732 aim_snacid_t snacid;
1733
1734 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !sn)
1735 return -EINVAL;
1736
1737 frame = flap_frame_new(od, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2);
1738
1739 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTH, 0x0000, NULL, 0);
1740 aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTH, 0x0000, snacid);
1741
1742 /* Screen name */
1743 byte_stream_put8(&frame->data, strlen(sn));
1744 byte_stream_putstr(&frame->data, sn);
1745
1746 /* Message (null terminated) */
1747 byte_stream_put16(&frame->data, msg ? strlen(msg) : 0);
1748 if (msg) {
1749 byte_stream_putstr(&frame->data, msg);
1750 byte_stream_put8(&frame->data, 0x00);
1751 }
1752
1753 /* Unknown */
1754 byte_stream_put16(&frame->data, 0x0000);
1755
1756 flap_connection_send(conn, frame);
1757
1758 return 0;
1759 }
1760
1761 /*
1762 * Subtype 0x0015 - Receive an authorization grant
1763 */
1764 static int receiveauthgrant(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1765 {
1766 int ret = 0;
1767 aim_rxcallback_t userfunc;
1768 guint16 tmp;
1769 char *sn, *msg;
1770
1771 /* Read screen name */
1772 if ((tmp = byte_stream_get8(bs)))
1773 sn = byte_stream_getstr(bs, tmp);
1774 else
1775 sn = NULL;
1776
1777 /* Read message (null terminated) */
1778 if ((tmp = byte_stream_get16(bs)))
1779 msg = byte_stream_getstr(bs, tmp);
1780 else
1781 msg = NULL;
1782
1783 /* Unknown */
1784 tmp = byte_stream_get16(bs);
1785
1786 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1787 ret = userfunc(od, conn, frame, sn, msg);
1788
1789 free(sn);
1790 free(msg);
1791
1792 return ret;
1793 }
1794
1795 /*
1796 * Subtype 0x0018 - Send authorization request
1797 *
1798 * Sends a request for authorization to the given contact. The request will either be
1799 * granted, denied, or dropped.
1800 *
1801 */
1802 int aim_ssi_sendauthrequest(OscarData *od, char *sn, const char *msg)
1803 {
1804 FlapConnection *conn;
1805 FlapFrame *frame;
1806 aim_snacid_t snacid;
1807
1808 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !sn)
1809 return -EINVAL;
1810
1811 frame = flap_frame_new(od, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2);
1812
1813 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ, 0x0000, NULL, 0);
1814 aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREQ, 0x0000, snacid);
1815
1816 /* Screen name */
1817 byte_stream_put8(&frame->data, strlen(sn));
1818 byte_stream_putstr(&frame->data, sn);
1819
1820 /* Message (null terminated) */
1821 byte_stream_put16(&frame->data, msg ? strlen(msg) : 0);
1822 if (msg) {
1823 byte_stream_putstr(&frame->data, msg);
1824 byte_stream_put8(&frame->data, 0x00);
1825 }
1826
1827 /* Unknown */
1828 byte_stream_put16(&frame->data, 0x0000);
1829
1830 flap_connection_send(conn, frame);
1831
1832 return 0;
1833 }
1834
1835 /*
1836 * Subtype 0x0019 - Receive an authorization request
1837 */
1838 static int receiveauthrequest(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1839 {
1840 int ret = 0;
1841 aim_rxcallback_t userfunc;
1842 guint16 tmp;
1843 char *sn, *msg;
1844
1845 /* Read screen name */
1846 if ((tmp = byte_stream_get8(bs)))
1847 sn = byte_stream_getstr(bs, tmp);
1848 else
1849 sn = NULL;
1850
1851 /* Read message (null terminated) */
1852 if ((tmp = byte_stream_get16(bs)))
1853 msg = byte_stream_getstr(bs, tmp);
1854 else
1855 msg = NULL;
1856
1857 /* Unknown */
1858 tmp = byte_stream_get16(bs);
1859
1860 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1861 ret = userfunc(od, conn, frame, sn, msg);
1862
1863 free(sn);
1864 free(msg);
1865
1866 return ret;
1867 }
1868
1869 /*
1870 * Subtype 0x001a - Send authorization reply
1871 *
1872 * Sends a reply to a request for authorization. The reply can either
1873 * grant authorization or deny authorization.
1874 *
1875 * if reply=0x00 then deny
1876 * if reply=0x01 then grant
1877 *
1878 */
1879 int aim_ssi_sendauthreply(OscarData *od, char *sn, guint8 reply, const char *msg)
1880 {
1881 FlapConnection *conn;
1882 FlapFrame *frame;
1883 aim_snacid_t snacid;
1884
1885 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_FEEDBAG)) || !sn)
1886 return -EINVAL;
1887
1888 frame = flap_frame_new(od, 0x02, 10 + 1+strlen(sn) + 1 + 2+(msg ? strlen(msg)+1 : 0) + 2);
1889
1890 snacid = aim_cachesnac(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP, 0x0000, NULL, 0);
1891 aim_putsnac(&frame->data, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_SENDAUTHREP, 0x0000, snacid);
1892
1893 /* Screen name */
1894 byte_stream_put8(&frame->data, strlen(sn));
1895 byte_stream_putstr(&frame->data, sn);
1896
1897 /* Grant or deny */
1898 byte_stream_put8(&frame->data, reply);
1899
1900 /* Message (null terminated) */
1901 byte_stream_put16(&frame->data, msg ? (strlen(msg)+1) : 0);
1902 if (msg) {
1903 byte_stream_putstr(&frame->data, msg);
1904 byte_stream_put8(&frame->data, 0x00);
1905 }
1906
1907 /* Unknown */
1908 byte_stream_put16(&frame->data, 0x0000);
1909
1910 flap_connection_send(conn, frame);
1911
1912 return 0;
1913 }
1914
1915 /*
1916 * Subtype 0x001b - Receive an authorization reply
1917 *
1918 * You get this bad boy when other people respond to the authorization
1919 * request that you have previously sent them.
1920 */
1921 static int receiveauthreply(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1922 {
1923 int ret = 0;
1924 aim_rxcallback_t userfunc;
1925 guint16 tmp;
1926 guint8 reply;
1927 char *sn, *msg;
1928
1929 /* Read screen name */
1930 if ((tmp = byte_stream_get8(bs)))
1931 sn = byte_stream_getstr(bs, tmp);
1932 else
1933 sn = NULL;
1934
1935 /* Read reply */
1936 reply = byte_stream_get8(bs);
1937
1938 /* Read message (null terminated) */
1939 if ((tmp = byte_stream_get16(bs)))
1940 msg = byte_stream_getstr(bs, tmp);
1941 else
1942 msg = NULL;
1943
1944 /* Unknown */
1945 tmp = byte_stream_get16(bs);
1946
1947 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1948 ret = userfunc(od, conn, frame, sn, reply, msg);
1949
1950 free(sn);
1951 free(msg);
1952
1953 return ret;
1954 }
1955
1956 /*
1957 * Subtype 0x001c - Receive a message telling you someone added you to their list.
1958 */
1959 static int receiveadded(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1960 {
1961 int ret = 0;
1962 aim_rxcallback_t userfunc;
1963 guint16 tmp;
1964 char *sn;
1965
1966 /* Read screen name */
1967 if ((tmp = byte_stream_get8(bs)))
1968 sn = byte_stream_getstr(bs, tmp);
1969 else
1970 sn = NULL;
1971
1972 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1973 ret = userfunc(od, conn, frame, sn);
1974
1975 free(sn);
1976
1977 return ret;
1978 }
1979
1980 static int
1981 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
1982 {
1983 if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RIGHTSINFO)
1984 return parserights(od, conn, mod, frame, snac, bs);
1985 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_LIST)
1986 return parsedata(od, conn, mod, frame, snac, bs);
1987 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_ADD)
1988 return parseadd(od, conn, mod, frame, snac, bs);
1989 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_MOD)
1990 return parsemod(od, conn, mod, frame, snac, bs);
1991 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_DEL)
1992 return parsedel(od, conn, mod, frame, snac, bs);
1993 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_SRVACK)
1994 return parseack(od, conn, mod, frame, snac, bs);
1995 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_NOLIST)
1996 return parsedataunchanged(od, conn, mod, frame, snac, bs);
1997 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTH)
1998 return receiveauthgrant(od, conn, mod, frame, snac, bs);
1999 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTHREQ)
2000 return receiveauthrequest(od, conn, mod, frame, snac, bs);
2001 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_RECVAUTHREP)
2002 return receiveauthreply(od, conn, mod, frame, snac, bs);
2003 else if (snac->subtype == SNAC_SUBTYPE_FEEDBAG_ADDED)
2004 return receiveadded(od, conn, mod, frame, snac, bs);
2005
2006 return 0;
2007 }
2008
2009 static void
2010 ssi_shutdown(OscarData *od, aim_module_t *mod)
2011 {
2012 aim_ssi_freelist(od);
2013 }
2014
2015 int
2016 ssi_modfirst(OscarData *od, aim_module_t *mod)
2017 {
2018 mod->family = SNAC_FAMILY_FEEDBAG;
2019 mod->version = 0x0004;
2020 mod->toolid = 0x0110;
2021 mod->toolversion = 0x0629;
2022 mod->flags = 0;
2023 strncpy(mod->name, "feedbag", sizeof(mod->name));
2024 mod->snachandler = snachandler;
2025 mod->shutdown = ssi_shutdown;
2026
2027 return 0;
2028 }