src/protocols/oscar/ssi.c

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

mercurial