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