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