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