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