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
|
5504
|
681 /* Check if there are empty groups and delete them */
|
4333
|
682 cur = sess->ssi.local;
|
|
683 while (cur) {
|
|
684 next = cur->next;
|
5504
|
685 if (cur->type == AIM_SSI_TYPE_GROUP) {
|
4243
|
686 aim_tlv_t *tlv = aim_gettlv(cur->data, 0x00c8, 1);
|
5503
|
687 if (!tlv || !tlv->length)
|
4243
|
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.
|
5842
|
1026 * @param iconcsumlen Length of the MD5 checksum given above. Should be 0x10 bytes.
|
4889
|
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 if (!(csumdata = (fu8_t *)malloc((iconsumlen+2)*sizeof(fu8_t))))
|
|
1039 return -ENOMEM;
|
|
1040 csumdata[0] = 0x00;
|
|
1041 csumdata[1] = 0x10;
|
|
1042 memcpy(&csumdata[2], iconsum, iconsumlen);
|
5842
|
1043
|
|
1044
|
|
1045 /* Need to add the x00d5 TLV to the TLV chain */
|
|
1046 aim_addtlvtochain_raw(&data, 0x00d5, (iconsumlen+2) * sizeof(fu8_t), csumdata);
|
4889
|
1047
|
5842
|
1048 /* This TLV is added to cache the icon. */
|
4889
|
1049 aim_addtlvtochain_noval(&data, 0x0131);
|
|
1050
|
|
1051
|
|
1052 if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, "0", AIM_SSI_TYPE_ICONINFO))) {
|
|
1053 aim_freetlvchain(&tmp->data);
|
|
1054 tmp->data = data;
|
|
1055 } else {
|
5842
|
1056 tmp = aim_ssi_itemlist_add(&sess->ssi.local, "1", 0x0000, 0x51F4, AIM_SSI_TYPE_ICONINFO, data);
|
4889
|
1057 aim_freetlvchain(&data);
|
|
1058 }
|
|
1059
|
|
1060 /* Sync our local list with the server list */
|
|
1061 aim_ssi_sync(sess);
|
5842
|
1062 free(csumdata);
|
2991
|
1063 return 0;
|
|
1064 }
|
|
1065
|
3210
|
1066 /**
|
3109
|
1067 * Stores your setting for whether you should show up as idle or not.
|
3210
|
1068 *
|
|
1069 * @param sess The oscar session.
|
|
1070 * @param presence I think it's a bitmask, but I only know what one of the bits is:
|
|
1071 * 0x00000400 - Allow others to see your idle time
|
|
1072 * @return Return 0 if no errors, otherwise return the error number.
|
3109
|
1073 */
|
4889
|
1074 faim_export int aim_ssi_setpresence(aim_session_t *sess, fu32_t presence) {
|
4230
|
1075 struct aim_ssi_item *tmp;
|
|
1076 aim_tlvlist_t *data = NULL;
|
3109
|
1077
|
4889
|
1078 if (!sess)
|
3109
|
1079 return -EINVAL;
|
|
1080
|
4230
|
1081 /* Need to add the x00c9 TLV to the TLV chain */
|
|
1082 aim_addtlvtochain32(&data, 0x00c9, presence);
|
3109
|
1083
|
4230
|
1084 if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS))) {
|
|
1085 aim_freetlvchain(&tmp->data);
|
|
1086 tmp->data = data;
|
3109
|
1087 } else {
|
4230
|
1088 tmp = aim_ssi_itemlist_add(&sess->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PRESENCEPREFS, data);
|
4236
|
1089 aim_freetlvchain(&data);
|
3109
|
1090 }
|
|
1091
|
4230
|
1092 /* Sync our local list with the server list */
|
4889
|
1093 aim_ssi_sync(sess);
|
3109
|
1094
|
|
1095 return 0;
|
|
1096 }
|
|
1097
|
|
1098 /*
|
4230
|
1099 * Subtype 0x0002 - Request SSI Rights.
|
2672
|
1100 */
|
4889
|
1101 faim_export int aim_ssi_reqrights(aim_session_t *sess)
|
2672
|
1102 {
|
4889
|
1103 aim_conn_t *conn;
|
|
1104
|
|
1105 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)))
|
|
1106 return -EINVAL;
|
|
1107
|
3017
|
1108 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_REQRIGHTS);
|
2672
|
1109 }
|
|
1110
|
|
1111 /*
|
4230
|
1112 * Subtype 0x0003 - SSI Rights Information.
|
2672
|
1113 */
|
|
1114 static int parserights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1115 {
|
4230
|
1116 int ret = 0, i;
|
2672
|
1117 aim_rxcallback_t userfunc;
|
4230
|
1118 aim_tlvlist_t *tlvlist;
|
|
1119 aim_tlv_t *tlv;
|
|
1120 aim_bstream_t bstream;
|
|
1121 fu16_t *maxitems;
|
|
1122
|
|
1123 /* This SNAC is made up of a bunch of TLVs */
|
|
1124 tlvlist = aim_readtlvchain(bs);
|
|
1125
|
|
1126 /* TLV 0x0004 contains the maximum number of each item */
|
|
1127 if (!(tlv = aim_gettlv(tlvlist, 0x0004, 1))) {
|
|
1128 aim_freetlvchain(&tlvlist);
|
|
1129 return 0;
|
|
1130 }
|
|
1131
|
|
1132 aim_bstream_init(&bstream, tlv->value, tlv->length);
|
|
1133
|
|
1134 if (!(maxitems = (fu16_t *)malloc((tlv->length/2)*sizeof(fu16_t)))) {
|
|
1135 aim_freetlvchain(&tlvlist);
|
|
1136 return 0;
|
|
1137 }
|
|
1138
|
|
1139 for (i=0; i<(tlv->length/2); i++)
|
|
1140 maxitems[i] = aimbs_get16(&bstream);
|
2672
|
1141
|
|
1142 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
4230
|
1143 ret = userfunc(sess, rx, tlv->length/2, maxitems);
|
|
1144
|
|
1145 aim_freetlvchain(&tlvlist);
|
|
1146 free(maxitems);
|
2672
|
1147
|
|
1148 return ret;
|
|
1149 }
|
|
1150
|
|
1151 /*
|
4230
|
1152 * Subtype 0x0004 - Request SSI Data.
|
4243
|
1153 * XXX - If you don't have a timestamp and revision number?
|
4230
|
1154 *
|
|
1155 * Note that the client should never increment the revision, only the server.
|
|
1156 *
|
|
1157 */
|
|
1158
|
|
1159
|
|
1160 /*
|
|
1161 * Subtype 0x0005 - Request SSI Data.
|
|
1162 * XXX - If you have a timestamp and revision number?
|
2672
|
1163 *
|
|
1164 * The data will only be sent if it is newer than the posted local
|
|
1165 * timestamp and revision.
|
|
1166 *
|
|
1167 * Note that the client should never increment the revision, only the server.
|
|
1168 *
|
|
1169 */
|
4889
|
1170 faim_export int aim_ssi_reqdata(aim_session_t *sess, time_t timestamp, fu16_t numitems)
|
2672
|
1171 {
|
4889
|
1172 aim_conn_t *conn;
|
2672
|
1173 aim_frame_t *fr;
|
|
1174 aim_snacid_t snacid;
|
|
1175
|
4889
|
1176 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)))
|
2672
|
1177 return -EINVAL;
|
|
1178
|
|
1179 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+2)))
|
|
1180 return -ENOMEM;
|
|
1181
|
3017
|
1182 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_REQLIST, 0x0000, NULL, 0);
|
2672
|
1183
|
3017
|
1184 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_REQLIST, 0x0000, snacid);
|
4282
|
1185 aimbs_put32(&fr->data, timestamp);
|
|
1186 aimbs_put16(&fr->data, numitems);
|
2672
|
1187
|
|
1188 aim_tx_enqueue(sess, fr);
|
|
1189
|
4230
|
1190 /* Free any current data, just in case */
|
|
1191 aim_ssi_freelist(sess);
|
|
1192
|
2672
|
1193 return 0;
|
|
1194 }
|
|
1195
|
|
1196 /*
|
4230
|
1197 * Subtype 0x0006 - SSI Data.
|
2672
|
1198 */
|
|
1199 static int parsedata(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1200 {
|
|
1201 int ret = 0;
|
|
1202 aim_rxcallback_t userfunc;
|
|
1203 fu8_t fmtver; /* guess */
|
4282
|
1204 fu16_t namelen, gid, bid, type;
|
4236
|
1205 char *name;
|
|
1206 aim_tlvlist_t *data;
|
2672
|
1207
|
2991
|
1208 fmtver = aimbs_get8(bs); /* Version of ssi data. Should be 0x00 */
|
4282
|
1209 sess->ssi.numitems += aimbs_get16(bs); /* # of items in this SSI SNAC */
|
2672
|
1210
|
4230
|
1211 /* Read in the list */
|
|
1212 while (aim_bstream_empty(bs) > 4) { /* last four bytes are timestamp */
|
2672
|
1213 if ((namelen = aimbs_get16(bs)))
|
4236
|
1214 name = aimbs_getstr(bs, namelen);
|
4230
|
1215 else
|
4236
|
1216 name = NULL;
|
|
1217 gid = aimbs_get16(bs);
|
|
1218 bid = aimbs_get16(bs);
|
|
1219 type = aimbs_get16(bs);
|
|
1220 data = aim_readtlvchain_len(bs, aimbs_get16(bs));
|
|
1221 aim_ssi_itemlist_add(&sess->ssi.official, name, gid, bid, type, data);
|
|
1222 free(name);
|
|
1223 aim_freetlvchain(&data);
|
2672
|
1224 }
|
|
1225
|
4230
|
1226 /* Read in the timestamp */
|
4282
|
1227 sess->ssi.timestamp = aimbs_get32(bs);
|
2672
|
1228
|
4317
|
1229 if (!(snac->flags & 0x0001)) {
|
4230
|
1230 /* Make a copy of the list */
|
4236
|
1231 struct aim_ssi_item *cur;
|
|
1232 for (cur=sess->ssi.official; cur; cur=cur->next)
|
|
1233 aim_ssi_itemlist_add(&sess->ssi.local, cur->name, cur->gid, cur->bid, cur->type, cur->data);
|
4230
|
1234
|
|
1235 sess->ssi.received_data = 1;
|
|
1236
|
|
1237 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1238 ret = userfunc(sess, rx, fmtver, sess->ssi.numitems, sess->ssi.official, sess->ssi.timestamp);
|
|
1239 }
|
2672
|
1240
|
|
1241 return ret;
|
|
1242 }
|
|
1243
|
|
1244 /*
|
4230
|
1245 * Subtype 0x0007 - SSI Activate Data.
|
2672
|
1246 *
|
|
1247 * Should be sent after receiving 13/6 or 13/f to tell the server you
|
|
1248 * are ready to begin using the list. It will promptly give you the
|
|
1249 * presence information for everyone in your list and put your permit/deny
|
|
1250 * settings into effect.
|
|
1251 *
|
|
1252 */
|
4642
|
1253 faim_export int aim_ssi_enable(aim_session_t *sess)
|
2672
|
1254 {
|
4642
|
1255 aim_conn_t *conn;
|
|
1256
|
|
1257 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)))
|
|
1258 return -EINVAL;
|
|
1259
|
3017
|
1260 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, 0x0007);
|
2672
|
1261 }
|
|
1262
|
|
1263 /*
|
4230
|
1264 * Subtype 0x0008/0x0009/0x000a - SSI Add/Mod/Del Item(s).
|
2991
|
1265 *
|
3017
|
1266 * Sends the SNAC to add, modify, or delete an item from the server-stored
|
|
1267 * information. These 3 SNACs all have an identical structure. The only
|
|
1268 * difference is the subtype that is set for the SNAC.
|
2991
|
1269 *
|
|
1270 */
|
4889
|
1271 faim_export int aim_ssi_addmoddel(aim_session_t *sess)
|
2991
|
1272 {
|
4889
|
1273 aim_conn_t *conn;
|
2991
|
1274 aim_frame_t *fr;
|
|
1275 aim_snacid_t snacid;
|
4230
|
1276 int snaclen;
|
|
1277 struct aim_ssi_tmp *cur;
|
2991
|
1278
|
4889
|
1279 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)) || !sess->ssi.pending || !sess->ssi.pending->item)
|
2991
|
1280 return -EINVAL;
|
|
1281
|
4230
|
1282 /* Calculate total SNAC size */
|
2991
|
1283 snaclen = 10; /* For family, subtype, flags, and SNAC ID */
|
4230
|
1284 for (cur=sess->ssi.pending; cur; cur=cur->next) {
|
2991
|
1285 snaclen += 10; /* For length, GID, BID, type, and length */
|
4230
|
1286 if (cur->item->name)
|
|
1287 snaclen += strlen(cur->item->name);
|
|
1288 if (cur->item->data)
|
|
1289 snaclen += aim_sizetlvchain(&cur->item->data);
|
2991
|
1290 }
|
|
1291
|
|
1292 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, snaclen)))
|
|
1293 return -ENOMEM;
|
|
1294
|
4230
|
1295 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, sess->ssi.pending->action, 0x0000, NULL, 0);
|
|
1296 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, sess->ssi.pending->action, 0x0000, snacid);
|
2991
|
1297
|
4230
|
1298 for (cur=sess->ssi.pending; cur; cur=cur->next) {
|
|
1299 aimbs_put16(&fr->data, cur->item->name ? strlen(cur->item->name) : 0);
|
|
1300 if (cur->item->name)
|
|
1301 aimbs_putraw(&fr->data, cur->item->name, strlen(cur->item->name));
|
|
1302 aimbs_put16(&fr->data, cur->item->gid);
|
|
1303 aimbs_put16(&fr->data, cur->item->bid);
|
|
1304 aimbs_put16(&fr->data, cur->item->type);
|
|
1305 aimbs_put16(&fr->data, cur->item->data ? aim_sizetlvchain(&cur->item->data) : 0);
|
|
1306 if (cur->item->data)
|
|
1307 aim_writetlvchain(&fr->data, &cur->item->data);
|
2991
|
1308 }
|
|
1309
|
4230
|
1310 aim_tx_enqueue(sess, fr);
|
2991
|
1311
|
|
1312 return 0;
|
|
1313 }
|
|
1314
|
|
1315 /*
|
4230
|
1316 * Subtype 0x0008 - Incoming SSI add.
|
|
1317 *
|
|
1318 * XXX - It would probably be good for the client to actually do something when it gets this.
|
|
1319 */
|
|
1320 static int parseadd(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1321 {
|
|
1322 int ret = 0;
|
|
1323 aim_rxcallback_t userfunc;
|
|
1324 char *name;
|
|
1325 fu16_t len, gid, bid, type;
|
|
1326 aim_tlvlist_t *data;
|
|
1327
|
|
1328 while (aim_bstream_empty(bs)) {
|
|
1329 if ((len = aimbs_get16(bs)))
|
|
1330 name = aimbs_getstr(bs, len);
|
|
1331 else
|
|
1332 name = NULL;
|
|
1333 gid = aimbs_get16(bs);
|
|
1334 bid = aimbs_get16(bs);
|
|
1335 type = aimbs_get16(bs);
|
|
1336 if ((len = aimbs_get16(bs)))
|
|
1337 data = aim_readtlvchain_len(bs, len);
|
|
1338 else
|
|
1339 data = NULL;
|
|
1340
|
|
1341 aim_ssi_itemlist_add(&sess->ssi.local, name, gid, bid, type, data);
|
4236
|
1342 aim_ssi_itemlist_add(&sess->ssi.official, name, gid, bid, type, data);
|
|
1343 free(name);
|
|
1344 aim_freetlvchain(&data);
|
4230
|
1345
|
|
1346 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1347 ret = userfunc(sess, rx);
|
|
1348
|
|
1349 free(name);
|
|
1350 }
|
|
1351
|
|
1352 return ret;
|
|
1353 }
|
|
1354
|
|
1355 /*
|
|
1356 * Subtype 0x0009 - Incoming SSI mod.
|
|
1357 *
|
|
1358 * XXX - It would probably be good for the client to actually do something when it gets this.
|
|
1359 */
|
|
1360 static int parsemod(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1361 {
|
|
1362 int ret = 0;
|
|
1363 aim_rxcallback_t userfunc;
|
|
1364 char *name;
|
|
1365 fu16_t len, gid, bid, type;
|
|
1366 aim_tlvlist_t *data;
|
|
1367 struct aim_ssi_item *item;
|
|
1368
|
|
1369 while (aim_bstream_empty(bs)) {
|
|
1370 if ((len = aimbs_get16(bs)))
|
|
1371 name = aimbs_getstr(bs, len);
|
|
1372 else
|
|
1373 name = NULL;
|
|
1374 gid = aimbs_get16(bs);
|
|
1375 bid = aimbs_get16(bs);
|
|
1376 type = aimbs_get16(bs);
|
|
1377 if ((len = aimbs_get16(bs)))
|
|
1378 data = aim_readtlvchain_len(bs, len);
|
|
1379 else
|
|
1380 data = NULL;
|
|
1381
|
|
1382 /* Replace the 2 local items with the given one */
|
|
1383 if ((item = aim_ssi_itemlist_find(sess->ssi.local, gid, bid))) {
|
|
1384 item->type = type;
|
|
1385 free(item->name);
|
|
1386 if (name) {
|
|
1387 item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
|
|
1388 strcpy(item->name, name);
|
|
1389 } else
|
|
1390 item->name = NULL;
|
|
1391 aim_freetlvchain(&item->data);
|
4234
|
1392 item->data = aim_tlvlist_copy(data);
|
4230
|
1393 }
|
|
1394
|
|
1395 if ((item = aim_ssi_itemlist_find(sess->ssi.official, gid, bid))) {
|
|
1396 item->type = type;
|
|
1397 free(item->name);
|
|
1398 if (name) {
|
|
1399 item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
|
|
1400 strcpy(item->name, name);
|
|
1401 } else
|
|
1402 item->name = NULL;
|
|
1403 aim_freetlvchain(&item->data);
|
4234
|
1404 item->data = aim_tlvlist_copy(data);
|
4230
|
1405 }
|
|
1406
|
|
1407 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1408 ret = userfunc(sess, rx);
|
|
1409
|
4236
|
1410 free(name);
|
4234
|
1411 aim_freetlvchain(&data);
|
4230
|
1412 }
|
|
1413
|
|
1414 return ret;
|
|
1415 }
|
|
1416
|
|
1417 /*
|
|
1418 * Subtype 0x000a - Incoming SSI del.
|
|
1419 *
|
|
1420 * XXX - It would probably be good for the client to actually do something when it gets this.
|
|
1421 */
|
|
1422 static int parsedel(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1423 {
|
|
1424 int ret = 0;
|
|
1425 aim_rxcallback_t userfunc;
|
|
1426 fu16_t gid, bid;
|
|
1427 struct aim_ssi_item *del;
|
|
1428
|
|
1429 while (aim_bstream_empty(bs)) {
|
|
1430 aim_bstream_advance(bs, aimbs_get16(bs));
|
|
1431 gid = aimbs_get16(bs);
|
|
1432 bid = aimbs_get16(bs);
|
|
1433 aimbs_get16(bs);
|
|
1434 aim_bstream_advance(bs, aimbs_get16(bs));
|
|
1435
|
4358
|
1436 if ((del = aim_ssi_itemlist_find(sess->ssi.local, gid, bid)))
|
|
1437 aim_ssi_itemlist_del(&sess->ssi.local, del);
|
|
1438 if ((del = aim_ssi_itemlist_find(sess->ssi.official, gid, bid)))
|
|
1439 aim_ssi_itemlist_del(&sess->ssi.official, del);
|
4230
|
1440
|
|
1441 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1442 ret = userfunc(sess, rx);
|
|
1443 }
|
|
1444
|
|
1445 return ret;
|
|
1446 }
|
|
1447
|
|
1448 /*
|
|
1449 * Subtype 0x000e - SSI Add/Mod/Del Ack.
|
2991
|
1450 *
|
3017
|
1451 * Response to add, modify, or delete SNAC (sent with aim_ssi_addmoddel).
|
2991
|
1452 *
|
|
1453 */
|
|
1454 static int parseack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1455 {
|
|
1456 int ret = 0;
|
|
1457 aim_rxcallback_t userfunc;
|
4230
|
1458 struct aim_ssi_tmp *cur, *del;
|
2991
|
1459
|
4230
|
1460 /* Read in the success/failure flags from the ack SNAC */
|
|
1461 cur = sess->ssi.pending;
|
|
1462 while (cur && (aim_bstream_empty(bs)>0)) {
|
|
1463 cur->ack = aimbs_get16(bs);
|
|
1464 cur = cur->next;
|
|
1465 }
|
|
1466
|
|
1467 /*
|
|
1468 * If outcome is 0, then add the item to the item list, or replace the other item,
|
|
1469 * or remove the old item. If outcome is non-zero, then remove the item from the
|
|
1470 * local list, or unmodify it, or add it.
|
|
1471 */
|
|
1472 for (cur=sess->ssi.pending; (cur && (cur->ack != 0xffff)); cur=cur->next) {
|
|
1473 if (cur->item) {
|
|
1474 if (cur->ack) {
|
|
1475 /* Our action was unsuccessful, so change the local list back to how it was */
|
|
1476 if (cur->action == AIM_CB_SSI_ADD) {
|
4791
|
1477 /* Remove the item from the local list */
|
|
1478 /* Make sure cur->item is still valid memory */
|
4789
|
1479 if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {
|
|
1480 if (cur->item->name) {
|
|
1481 cur->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
|
|
1482 strcpy(cur->name, cur->item->name);
|
|
1483 }
|
|
1484 aim_ssi_itemlist_del(&sess->ssi.local, cur->item);
|
4230
|
1485 }
|
|
1486 cur->item = NULL;
|
|
1487
|
|
1488 } else if (cur->action == AIM_CB_SSI_MOD) {
|
4292
|
1489 /* Replace the local item with the item from the official list */
|
4789
|
1490 if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {
|
|
1491 struct aim_ssi_item *cur1;
|
|
1492 if ((cur1 = aim_ssi_itemlist_find(sess->ssi.official, cur->item->gid, cur->item->bid))) {
|
|
1493 free(cur->item->name);
|
|
1494 if (cur1->name) {
|
|
1495 cur->item->name = (char *)malloc((strlen(cur1->name)+1)*sizeof(char));
|
|
1496 strcpy(cur->item->name, cur1->name);
|
|
1497 } else
|
|
1498 cur->item->name = NULL;
|
|
1499 aim_freetlvchain(&cur->item->data);
|
|
1500 cur->item->data = aim_tlvlist_copy(cur1->data);
|
|
1501 }
|
|
1502 } else
|
|
1503 cur->item = NULL;
|
4230
|
1504
|
|
1505 } else if (cur->action == AIM_CB_SSI_DEL) {
|
4236
|
1506 /* Add the item back into the local list */
|
4791
|
1507 if (aim_ssi_itemlist_valid(sess->ssi.official, cur->item)) {
|
4789
|
1508 aim_ssi_itemlist_add(&sess->ssi.local, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
|
|
1509 } else
|
|
1510 cur->item = NULL;
|
4230
|
1511 }
|
|
1512
|
|
1513 } else {
|
|
1514 /* Do the exact opposite */
|
|
1515 if (cur->action == AIM_CB_SSI_ADD) {
|
4791
|
1516 /* Add the local item to the official list */
|
|
1517 if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {
|
|
1518 aim_ssi_itemlist_add(&sess->ssi.official, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
|
|
1519 } else
|
|
1520 cur->item = NULL;
|
4230
|
1521
|
|
1522 } else if (cur->action == AIM_CB_SSI_MOD) {
|
4292
|
1523 /* Replace the official item with the item from the local list */
|
4791
|
1524 if (aim_ssi_itemlist_valid(sess->ssi.local, cur->item)) {
|
|
1525 struct aim_ssi_item *cur1;
|
|
1526 if ((cur1 = aim_ssi_itemlist_find(sess->ssi.official, cur->item->gid, cur->item->bid))) {
|
|
1527 free(cur1->name);
|
|
1528 if (cur->item->name) {
|
|
1529 cur1->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
|
|
1530 strcpy(cur1->name, cur->item->name);
|
|
1531 } else
|
|
1532 cur1->name = NULL;
|
|
1533 aim_freetlvchain(&cur1->data);
|
|
1534 cur1->data = aim_tlvlist_copy(cur->item->data);
|
|
1535 }
|
|
1536 } else
|
|
1537 cur->item = NULL;
|
4230
|
1538
|
|
1539 } else if (cur->action == AIM_CB_SSI_DEL) {
|
4292
|
1540 /* Remove the item from the official list */
|
4791
|
1541 if (aim_ssi_itemlist_valid(sess->ssi.official, cur->item))
|
|
1542 aim_ssi_itemlist_del(&sess->ssi.official, cur->item);
|
4230
|
1543 cur->item = NULL;
|
|
1544 }
|
|
1545
|
|
1546 }
|
|
1547 } /* End if (cur->item) */
|
|
1548 } /* End for loop */
|
2991
|
1549
|
|
1550 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
4230
|
1551 ret = userfunc(sess, rx, sess->ssi.pending);
|
|
1552
|
|
1553 /* Free all aim_ssi_tmp's with an outcome */
|
|
1554 cur = sess->ssi.pending;
|
|
1555 while (cur && (cur->ack != 0xffff)) {
|
|
1556 del = cur;
|
|
1557 cur = cur->next;
|
|
1558 free(del->name);
|
|
1559 free(del);
|
|
1560 }
|
|
1561 sess->ssi.pending = cur;
|
|
1562
|
|
1563 /* If we're not waiting for any more acks, then send more SNACs */
|
|
1564 if (!sess->ssi.pending) {
|
|
1565 sess->ssi.pending = NULL;
|
|
1566 sess->ssi.waiting_for_ack = 0;
|
4889
|
1567 aim_ssi_sync(sess);
|
4230
|
1568 }
|
2991
|
1569
|
|
1570 return ret;
|
|
1571 }
|
|
1572
|
|
1573 /*
|
4230
|
1574 * Subtype 0x000f - SSI Data Unchanged.
|
2672
|
1575 *
|
|
1576 * Response to aim_ssi_reqdata() if the server-side data is not newer than
|
|
1577 * posted local stamp/revision.
|
|
1578 *
|
|
1579 */
|
|
1580 static int parsedataunchanged(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1581 {
|
|
1582 int ret = 0;
|
|
1583 aim_rxcallback_t userfunc;
|
|
1584
|
2991
|
1585 sess->ssi.received_data = 1;
|
|
1586
|
2672
|
1587 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1588 ret = userfunc(sess, rx);
|
|
1589
|
|
1590 return ret;
|
|
1591 }
|
|
1592
|
4230
|
1593 /*
|
|
1594 * Subtype 0x0011 - SSI Begin Data Modification.
|
|
1595 *
|
|
1596 * Tells the server you're going to start modifying data.
|
|
1597 *
|
|
1598 */
|
4889
|
1599 faim_export int aim_ssi_modbegin(aim_session_t *sess)
|
4230
|
1600 {
|
4889
|
1601 aim_conn_t *conn;
|
|
1602
|
|
1603 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)))
|
|
1604 return -EINVAL;
|
|
1605
|
4230
|
1606 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_EDITSTART);
|
|
1607 }
|
|
1608
|
|
1609 /*
|
|
1610 * Subtype 0x0012 - SSI End Data Modification.
|
|
1611 *
|
|
1612 * Tells the server you're finished modifying data.
|
|
1613 *
|
|
1614 */
|
4889
|
1615 faim_export int aim_ssi_modend(aim_session_t *sess)
|
4230
|
1616 {
|
4889
|
1617 aim_conn_t *conn;
|
|
1618
|
|
1619 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)))
|
|
1620 return -EINVAL;
|
|
1621
|
4230
|
1622 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_EDITSTOP);
|
|
1623 }
|
|
1624
|
|
1625 /*
|
|
1626 * Subtype 0x0014 - Grant authorization
|
|
1627 *
|
|
1628 * Authorizes a contact so they can add you to their contact list.
|
|
1629 *
|
|
1630 */
|
4889
|
1631 faim_export int aim_ssi_sendauth(aim_session_t *sess, char *sn, char *msg)
|
4230
|
1632 {
|
4889
|
1633 aim_conn_t *conn;
|
4230
|
1634 aim_frame_t *fr;
|
|
1635 aim_snacid_t snacid;
|
|
1636
|
4889
|
1637 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)) || !sn)
|
4230
|
1638 return -EINVAL;
|
|
1639
|
|
1640 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
|
|
1641 return -ENOMEM;
|
|
1642
|
|
1643 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTH, 0x0000, NULL, 0);
|
|
1644 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTH, 0x0000, snacid);
|
|
1645
|
|
1646 /* Screen name */
|
|
1647 aimbs_put8(&fr->data, strlen(sn));
|
|
1648 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1649
|
|
1650 /* Message (null terminated) */
|
|
1651 aimbs_put16(&fr->data, msg ? strlen(msg) : 0);
|
|
1652 if (msg) {
|
|
1653 aimbs_putraw(&fr->data, msg, strlen(msg));
|
|
1654 aimbs_put8(&fr->data, 0x00);
|
|
1655 }
|
|
1656
|
|
1657 /* Unknown */
|
|
1658 aimbs_put16(&fr->data, 0x0000);
|
|
1659
|
|
1660 aim_tx_enqueue(sess, fr);
|
|
1661
|
|
1662 return 0;
|
|
1663 }
|
|
1664
|
|
1665 /*
|
|
1666 * Subtype 0x0015 - Receive an authorization grant
|
|
1667 */
|
|
1668 static int receiveauthgrant(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1669 {
|
|
1670 int ret = 0;
|
|
1671 aim_rxcallback_t userfunc;
|
|
1672 fu16_t tmp;
|
|
1673 char *sn, *msg;
|
|
1674
|
|
1675 /* Read screen name */
|
|
1676 if ((tmp = aimbs_get8(bs)))
|
|
1677 sn = aimbs_getstr(bs, tmp);
|
|
1678 else
|
|
1679 sn = NULL;
|
|
1680
|
|
1681 /* Read message (null terminated) */
|
|
1682 if ((tmp = aimbs_get16(bs)))
|
|
1683 msg = aimbs_getstr(bs, tmp);
|
|
1684 else
|
|
1685 msg = NULL;
|
|
1686
|
|
1687 /* Unknown */
|
|
1688 tmp = aimbs_get16(bs);
|
|
1689
|
|
1690 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1691 ret = userfunc(sess, rx, sn, msg);
|
|
1692
|
|
1693 free(sn);
|
|
1694 free(msg);
|
|
1695
|
|
1696 return ret;
|
|
1697 }
|
|
1698
|
|
1699 /*
|
|
1700 * Subtype 0x0018 - Send authorization request
|
|
1701 *
|
|
1702 * Sends a request for authorization to the given contact. The request will either be
|
|
1703 * granted, denied, or dropped.
|
|
1704 *
|
|
1705 */
|
4889
|
1706 faim_export int aim_ssi_sendauthrequest(aim_session_t *sess, char *sn, char *msg)
|
4230
|
1707 {
|
4889
|
1708 aim_conn_t *conn;
|
4230
|
1709 aim_frame_t *fr;
|
|
1710 aim_snacid_t snacid;
|
|
1711
|
4889
|
1712 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)) || !sn)
|
4230
|
1713 return -EINVAL;
|
|
1714
|
|
1715 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
|
|
1716 return -ENOMEM;
|
|
1717
|
|
1718 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREQ, 0x0000, NULL, 0);
|
|
1719 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREQ, 0x0000, snacid);
|
|
1720
|
|
1721 /* Screen name */
|
|
1722 aimbs_put8(&fr->data, strlen(sn));
|
|
1723 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1724
|
|
1725 /* Message (null terminated) */
|
|
1726 aimbs_put16(&fr->data, msg ? strlen(msg) : 0);
|
|
1727 if (msg) {
|
|
1728 aimbs_putraw(&fr->data, msg, strlen(msg));
|
|
1729 aimbs_put8(&fr->data, 0x00);
|
|
1730 }
|
|
1731
|
|
1732 /* Unknown */
|
|
1733 aimbs_put16(&fr->data, 0x0000);
|
|
1734
|
|
1735 aim_tx_enqueue(sess, fr);
|
|
1736
|
|
1737 return 0;
|
|
1738 }
|
|
1739
|
|
1740 /*
|
|
1741 * Subtype 0x0019 - Receive an authorization request
|
|
1742 */
|
|
1743 static int receiveauthrequest(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1744 {
|
|
1745 int ret = 0;
|
|
1746 aim_rxcallback_t userfunc;
|
|
1747 fu16_t tmp;
|
|
1748 char *sn, *msg;
|
|
1749
|
|
1750 /* Read screen name */
|
|
1751 if ((tmp = aimbs_get8(bs)))
|
|
1752 sn = aimbs_getstr(bs, tmp);
|
|
1753 else
|
|
1754 sn = NULL;
|
|
1755
|
|
1756 /* Read message (null terminated) */
|
|
1757 if ((tmp = aimbs_get16(bs)))
|
|
1758 msg = aimbs_getstr(bs, tmp);
|
|
1759 else
|
|
1760 msg = NULL;
|
|
1761
|
|
1762 /* Unknown */
|
|
1763 tmp = aimbs_get16(bs);
|
|
1764
|
|
1765 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1766 ret = userfunc(sess, rx, sn, msg);
|
|
1767
|
|
1768 free(sn);
|
|
1769 free(msg);
|
|
1770
|
|
1771 return ret;
|
|
1772 }
|
|
1773
|
|
1774 /*
|
|
1775 * Subtype 0x001a - Send authorization reply
|
|
1776 *
|
|
1777 * Sends a reply to a request for authorization. The reply can either
|
|
1778 * grant authorization or deny authorization.
|
|
1779 *
|
|
1780 * if reply=0x00 then deny
|
|
1781 * if reply=0x01 then grant
|
|
1782 *
|
|
1783 */
|
4889
|
1784 faim_export int aim_ssi_sendauthreply(aim_session_t *sess, char *sn, fu8_t reply, char *msg)
|
4230
|
1785 {
|
4889
|
1786 aim_conn_t *conn;
|
4230
|
1787 aim_frame_t *fr;
|
|
1788 aim_snacid_t snacid;
|
|
1789
|
4889
|
1790 if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_SSI)) || !sn)
|
4230
|
1791 return -EINVAL;
|
|
1792
|
|
1793 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 1 + 2+(msg ? strlen(msg)+1 : 0) + 2)))
|
|
1794 return -ENOMEM;
|
|
1795
|
|
1796 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREP, 0x0000, NULL, 0);
|
|
1797 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREP, 0x0000, snacid);
|
|
1798
|
|
1799 /* Screen name */
|
|
1800 aimbs_put8(&fr->data, strlen(sn));
|
|
1801 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1802
|
|
1803 /* Grant or deny */
|
|
1804 aimbs_put8(&fr->data, reply);
|
|
1805
|
|
1806 /* Message (null terminated) */
|
|
1807 aimbs_put16(&fr->data, msg ? (strlen(msg)+1) : 0);
|
|
1808 if (msg) {
|
|
1809 aimbs_putraw(&fr->data, msg, strlen(msg));
|
|
1810 aimbs_put8(&fr->data, 0x00);
|
|
1811 }
|
|
1812
|
|
1813 /* Unknown */
|
|
1814 aimbs_put16(&fr->data, 0x0000);
|
|
1815
|
|
1816 aim_tx_enqueue(sess, fr);
|
|
1817
|
|
1818 return 0;
|
|
1819 }
|
|
1820
|
|
1821 /*
|
|
1822 * Subtype 0x001b - Receive an authorization reply
|
|
1823 * You get this bad boy when other people respond to the authorization
|
|
1824 * request that you have previously sent them.
|
|
1825 */
|
|
1826 static int receiveauthreply(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1827 {
|
|
1828 int ret = 0;
|
|
1829 aim_rxcallback_t userfunc;
|
|
1830 fu16_t tmp;
|
|
1831 fu8_t reply;
|
|
1832 char *sn, *msg;
|
|
1833
|
|
1834 /* Read screen name */
|
|
1835 if ((tmp = aimbs_get8(bs)))
|
|
1836 sn = aimbs_getstr(bs, tmp);
|
|
1837 else
|
|
1838 sn = NULL;
|
|
1839
|
|
1840 /* Read reply */
|
|
1841 reply = aimbs_get8(bs);
|
|
1842
|
|
1843 /* Read message (null terminated) */
|
|
1844 if ((tmp = aimbs_get16(bs)))
|
|
1845 msg = aimbs_getstr(bs, tmp);
|
|
1846 else
|
|
1847 msg = NULL;
|
|
1848
|
|
1849 /* Unknown */
|
|
1850 tmp = aimbs_get16(bs);
|
|
1851
|
|
1852 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1853 ret = userfunc(sess, rx, sn, reply, msg);
|
|
1854
|
|
1855 free(sn);
|
|
1856 free(msg);
|
|
1857
|
|
1858 return ret;
|
|
1859 }
|
|
1860
|
|
1861 /*
|
|
1862 * Subtype 0x001c - Receive a message telling you someone added you to their list.
|
|
1863 */
|
|
1864 static int receiveadded(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1865 {
|
|
1866 int ret = 0;
|
|
1867 aim_rxcallback_t userfunc;
|
|
1868 fu16_t tmp;
|
|
1869 char *sn;
|
|
1870
|
|
1871 /* Read screen name */
|
|
1872 if ((tmp = aimbs_get8(bs)))
|
|
1873 sn = aimbs_getstr(bs, tmp);
|
|
1874 else
|
|
1875 sn = NULL;
|
|
1876
|
|
1877 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1878 ret = userfunc(sess, rx, sn);
|
|
1879
|
|
1880 free(sn);
|
|
1881
|
|
1882 return ret;
|
|
1883 }
|
|
1884
|
2672
|
1885 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1886 {
|
|
1887
|
3017
|
1888 if (snac->subtype == AIM_CB_SSI_RIGHTSINFO)
|
2672
|
1889 return parserights(sess, mod, rx, snac, bs);
|
3017
|
1890 else if (snac->subtype == AIM_CB_SSI_LIST)
|
2672
|
1891 return parsedata(sess, mod, rx, snac, bs);
|
4230
|
1892 else if (snac->subtype == AIM_CB_SSI_ADD)
|
|
1893 return parseadd(sess, mod, rx, snac, bs);
|
|
1894 else if (snac->subtype == AIM_CB_SSI_MOD)
|
|
1895 return parsemod(sess, mod, rx, snac, bs);
|
|
1896 else if (snac->subtype == AIM_CB_SSI_DEL)
|
|
1897 return parsedel(sess, mod, rx, snac, bs);
|
2991
|
1898 else if (snac->subtype == AIM_CB_SSI_SRVACK)
|
|
1899 return parseack(sess, mod, rx, snac, bs);
|
3017
|
1900 else if (snac->subtype == AIM_CB_SSI_NOLIST)
|
2672
|
1901 return parsedataunchanged(sess, mod, rx, snac, bs);
|
4230
|
1902 else if (snac->subtype == AIM_CB_SSI_RECVAUTH)
|
|
1903 return receiveauthgrant(sess, mod, rx, snac, bs);
|
|
1904 else if (snac->subtype == AIM_CB_SSI_RECVAUTHREQ)
|
|
1905 return receiveauthrequest(sess, mod, rx, snac, bs);
|
|
1906 else if (snac->subtype == AIM_CB_SSI_RECVAUTHREP)
|
|
1907 return receiveauthreply(sess, mod, rx, snac, bs);
|
|
1908 else if (snac->subtype == AIM_CB_SSI_ADDED)
|
|
1909 return receiveadded(sess, mod, rx, snac, bs);
|
2672
|
1910
|
|
1911 return 0;
|
|
1912 }
|
|
1913
|
2991
|
1914 static void ssi_shutdown(aim_session_t *sess, aim_module_t *mod)
|
|
1915 {
|
|
1916 aim_ssi_freelist(sess);
|
|
1917
|
|
1918 return;
|
|
1919 }
|
|
1920
|
2672
|
1921 faim_internal int ssi_modfirst(aim_session_t *sess, aim_module_t *mod)
|
|
1922 {
|
|
1923
|
3017
|
1924 mod->family = AIM_CB_FAM_SSI;
|
4230
|
1925 mod->version = 0x0004;
|
2672
|
1926 mod->toolid = 0x0110;
|
4071
|
1927 mod->toolversion = 0x0629;
|
2672
|
1928 mod->flags = 0;
|
|
1929 strncpy(mod->name, "ssi", sizeof(mod->name));
|
|
1930 mod->snachandler = snachandler;
|
2991
|
1931 mod->shutdown = ssi_shutdown;
|
2672
|
1932
|
|
1933 return 0;
|
|
1934 }
|