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 */
|
4236
|
150 new->data = aim_tlvlist_copy(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 */
|
4238
|
415 faim_export char *aim_ssi_getalias(struct aim_ssi_item *list, const char *gn, const char *sn)
|
4230
|
416 {
|
|
417 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY);
|
|
418 if (cur) {
|
|
419 aim_tlvlist_t *tlvlist = cur->data;
|
|
420 if (tlvlist) {
|
|
421 aim_tlv_t *tlv = aim_gettlv(tlvlist, 0x0131, 1);
|
|
422 if (tlv && tlv->length) {
|
|
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
|
4238
|
462 /* Additions */
|
4230
|
463 if (!sess->ssi.pending) {
|
4238
|
464 for (cur1=sess->ssi.local; cur1; cur1=cur1->next) {
|
|
465 if (!aim_ssi_itemlist_find(sess->ssi.official, cur1->gid, cur1->bid)) {
|
4230
|
466 new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
|
4238
|
467 new->action = AIM_CB_SSI_ADD;
|
4230
|
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
|
4238
|
481 /* Deletions */
|
4230
|
482 if (!sess->ssi.pending) {
|
4238
|
483 for (cur1=sess->ssi.official; cur1; cur1=cur1->next) {
|
|
484 if (!aim_ssi_itemlist_find(sess->ssi.local, cur1->gid, cur1->bid)) {
|
4230
|
485 new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
|
4238
|
486 new->action = AIM_CB_SSI_DEL;
|
4230
|
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);
|
4236
|
696 aim_freetlvchain(&data);
|
4230
|
697
|
|
698 /* Modify the parent group */
|
|
699 aim_ssi_itemlist_rebuildgroup(sess->ssi.local, group);
|
|
700
|
|
701 /* Sync our local list with the server list */
|
|
702 aim_ssi_sync(sess, conn);
|
3210
|
703
|
4230
|
704 return 0;
|
|
705 }
|
3210
|
706
|
4230
|
707 /**
|
|
708 * Add a permit buddy to the list.
|
|
709 *
|
|
710 * @param sess The oscar session.
|
|
711 * @param conn The bos connection for this session.
|
|
712 * @param name The name of the item..
|
|
713 * @return Return 0 if no errors, otherwise return the error number.
|
|
714 */
|
|
715 faim_export int aim_ssi_addpermit(aim_session_t *sess, aim_conn_t *conn, const char *name)
|
|
716 {
|
|
717 if (!sess || !conn || !name)
|
|
718 return -EINVAL;
|
2991
|
719
|
4230
|
720 /* Add that bad boy */
|
|
721 aim_ssi_itemlist_add(&sess->ssi.local, name, 0x0000, 0xFFFF, AIM_SSI_TYPE_PERMIT, NULL);
|
|
722
|
|
723 /* Sync our local list with the server list */
|
|
724 aim_ssi_sync(sess, conn);
|
2991
|
725
|
|
726 return 0;
|
|
727 }
|
|
728
|
3210
|
729 /**
|
4230
|
730 * Add a deny buddy to the list.
|
2991
|
731 *
|
3210
|
732 * @param sess The oscar session.
|
|
733 * @param conn The bos connection for this session.
|
4230
|
734 * @param name The name of the item..
|
3210
|
735 * @return Return 0 if no errors, otherwise return the error number.
|
2991
|
736 */
|
4230
|
737 faim_export int aim_ssi_adddeny(aim_session_t *sess, aim_conn_t *conn, const char *name)
|
2991
|
738 {
|
4230
|
739 if (!sess || !conn || !name)
|
2991
|
740 return -EINVAL;
|
|
741
|
4230
|
742 /* Add that bad boy */
|
|
743 aim_ssi_itemlist_add(&sess->ssi.local, name, 0x0000, 0xFFFF, AIM_SSI_TYPE_DENY, NULL);
|
3017
|
744
|
4230
|
745 /* Sync our local list with the server list */
|
|
746 aim_ssi_sync(sess, conn);
|
2991
|
747
|
|
748 return 0;
|
|
749 }
|
|
750
|
3210
|
751 /**
|
4230
|
752 * Deletes a buddy from the list.
|
3210
|
753 *
|
|
754 * @param sess The oscar session.
|
|
755 * @param conn The bos connection for this session.
|
4230
|
756 * @param name The name of the item, or NULL.
|
|
757 * @param group The group of the item, or NULL.
|
3210
|
758 * @return Return 0 if no errors, otherwise return the error number.
|
|
759 */
|
4230
|
760 faim_export int aim_ssi_delbuddy(aim_session_t *sess, aim_conn_t *conn, const char *name, const char *group)
|
2991
|
761 {
|
4230
|
762 struct aim_ssi_item *del;
|
2991
|
763
|
4230
|
764 if (!sess || !conn || !name || !group)
|
|
765 return -EINVAL;
|
|
766
|
|
767 /* Find the buddy */
|
|
768 if (!(del = aim_ssi_itemlist_finditem(sess->ssi.local, group, name, AIM_SSI_TYPE_BUDDY)))
|
2991
|
769 return -EINVAL;
|
|
770
|
4230
|
771 /* Remove the item from the list */
|
|
772 aim_ssi_itemlist_del(&sess->ssi.local, del);
|
|
773
|
|
774 /* Modify the parent group */
|
|
775 aim_ssi_itemlist_rebuildgroup(sess->ssi.local, group);
|
|
776
|
|
777 /* Check if we should delete the parent group */
|
|
778 if ((del = aim_ssi_itemlist_finditem(sess->ssi.local, group, NULL, AIM_SSI_TYPE_GROUP)) && (!del->data)) {
|
|
779 aim_ssi_itemlist_del(&sess->ssi.local, del);
|
|
780
|
|
781 /* Modify the parent group */
|
|
782 aim_ssi_itemlist_rebuildgroup(sess->ssi.local, NULL);
|
|
783
|
|
784 /* Check if we should delete the parent's parent (the master group) */
|
|
785 if ((del = aim_ssi_itemlist_find(sess->ssi.local, 0x0000, 0x0000)) && (!del->data)) {
|
|
786 aim_ssi_itemlist_del(&sess->ssi.local, del);
|
|
787 }
|
2991
|
788 }
|
|
789
|
4230
|
790 /* Sync our local list with the server list */
|
|
791 aim_ssi_sync(sess, conn);
|
2991
|
792
|
|
793 return 0;
|
|
794 }
|
|
795
|
3210
|
796 /**
|
4230
|
797 * Deletes a permit buddy from the list.
|
3210
|
798 *
|
|
799 * @param sess The oscar session.
|
|
800 * @param conn The bos connection for this session.
|
4230
|
801 * @param name The name of the item, or NULL.
|
3210
|
802 * @return Return 0 if no errors, otherwise return the error number.
|
3017
|
803 */
|
4230
|
804 faim_export int aim_ssi_delpermit(aim_session_t *sess, aim_conn_t *conn, const char *name)
|
2991
|
805 {
|
4230
|
806 struct aim_ssi_item *del;
|
2991
|
807
|
4230
|
808 if (!sess || !conn || !name)
|
|
809 return -EINVAL;
|
|
810
|
|
811 /* Find the item */
|
|
812 if (!(del = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, name, AIM_SSI_TYPE_PERMIT)))
|
2991
|
813 return -EINVAL;
|
|
814
|
4230
|
815 /* Remove the item from the list */
|
|
816 aim_ssi_itemlist_del(&sess->ssi.local, del);
|
2991
|
817
|
4230
|
818 /* Sync our local list with the server list */
|
|
819 aim_ssi_sync(sess, conn);
|
|
820
|
|
821 return 0;
|
|
822 }
|
2991
|
823
|
4230
|
824 /**
|
|
825 * Deletes a deny buddy from the list.
|
|
826 *
|
|
827 * @param sess The oscar session.
|
|
828 * @param conn The bos connection for this session.
|
|
829 * @param name The name of the item, or NULL.
|
|
830 * @return Return 0 if no errors, otherwise return the error number.
|
|
831 */
|
|
832 faim_export int aim_ssi_deldeny(aim_session_t *sess, aim_conn_t *conn, const char *name)
|
|
833 {
|
|
834 struct aim_ssi_item *del;
|
2991
|
835
|
4230
|
836 if (!sess || !conn || !name)
|
|
837 return -EINVAL;
|
2991
|
838
|
4230
|
839 /* Find the item */
|
|
840 if (!(del = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, name, AIM_SSI_TYPE_PERMIT)))
|
|
841 return -EINVAL;
|
|
842
|
|
843 /* Remove the item from the list */
|
|
844 aim_ssi_itemlist_del(&sess->ssi.local, del);
|
|
845
|
|
846 /* Sync our local list with the server list */
|
|
847 aim_ssi_sync(sess, conn);
|
2991
|
848
|
|
849 return 0;
|
|
850 }
|
|
851
|
3210
|
852 /**
|
|
853 * Move a buddy from one group to another group. This basically just deletes the
|
|
854 * buddy and re-adds it.
|
|
855 *
|
|
856 * @param sess The oscar session.
|
|
857 * @param conn The bos connection for this session.
|
|
858 * @param oldgn The group that the buddy is currently in.
|
|
859 * @param newgn The group that the buddy should be moved in to.
|
|
860 * @param sn The name of the buddy to be moved.
|
|
861 * @return Return 0 if no errors, otherwise return the error number.
|
|
862 */
|
3867
|
863 faim_export int aim_ssi_movebuddy(aim_session_t *sess, aim_conn_t *conn, const char *oldgn, const char *newgn, const char *sn)
|
3140
|
864 {
|
4238
|
865 aim_ssi_addbuddy(sess, conn, sn, newgn, aim_ssi_getalias(sess->ssi.local, oldgn, sn), NULL, NULL, 0);
|
4230
|
866 aim_ssi_delbuddy(sess, conn, sn, oldgn);
|
3140
|
867 return 0;
|
|
868 }
|
|
869
|
3210
|
870 /**
|
4230
|
871 * Rename a group.
|
3348
|
872 *
|
|
873 * @param sess The oscar session.
|
|
874 * @param conn The bos connection for this session.
|
|
875 * @param oldgn The old group name.
|
|
876 * @param newgn The new group name.
|
|
877 * @return Return 0 if no errors, otherwise return the error number.
|
|
878 */
|
3867
|
879 faim_export int aim_ssi_rename_group(aim_session_t *sess, aim_conn_t *conn, const char *oldgn, const char *newgn)
|
3348
|
880 {
|
|
881 struct aim_ssi_item *group;
|
|
882
|
|
883 if (!sess || !conn || !oldgn || !newgn)
|
|
884 return -EINVAL;
|
|
885
|
4230
|
886 if (!(group = aim_ssi_itemlist_finditem(sess->ssi.local, oldgn, NULL, AIM_SSI_TYPE_GROUP)))
|
3017
|
887 return -EINVAL;
|
|
888
|
4230
|
889 free(group->name);
|
|
890 group->name = (char *)malloc((strlen(newgn)+1)*sizeof(char));
|
|
891 strcpy(group->name, newgn);
|
2991
|
892
|
4230
|
893 /* Sync our local list with the server list */
|
|
894 aim_ssi_sync(sess, conn);
|
2991
|
895
|
|
896 return 0;
|
|
897 }
|
|
898
|
3210
|
899 /**
|
2991
|
900 * Stores your permit/deny setting on the server, and starts using it.
|
3210
|
901 *
|
|
902 * @param sess The oscar session.
|
|
903 * @param conn The bos connection for this session.
|
|
904 * @param permdeny Your permit/deny setting. Can be one of the following:
|
|
905 * 1 - Allow all users
|
|
906 * 2 - Block all users
|
|
907 * 3 - Allow only the users below
|
|
908 * 4 - Block only the users below
|
|
909 * 5 - Allow only users on my buddy list
|
|
910 * @param vismask A bitmask of the class of users to whom you want to be
|
|
911 * visible. See the AIM_FLAG_BLEH #defines in aim.h
|
|
912 * @return Return 0 if no errors, otherwise return the error number.
|
2991
|
913 */
|
4230
|
914 faim_export int aim_ssi_setpermdeny(aim_session_t *sess, aim_conn_t *conn, fu8_t permdeny, fu32_t vismask)
|
|
915 {
|
|
916 struct aim_ssi_item *tmp;
|
|
917 aim_tlvlist_t *data = NULL;
|
2991
|
918
|
|
919 if (!sess || !conn)
|
|
920 return -EINVAL;
|
|
921
|
4230
|
922 /* Need to add the x00ca TLV to the TLV chain */
|
|
923 aim_addtlvtochain8(&data, 0x00ca, permdeny);
|
2991
|
924
|
4230
|
925 /* Need to add the x00cb TLV to the TLV chain */
|
|
926 aim_addtlvtochain32(&data, 0x00cb, vismask);
|
2991
|
927
|
4230
|
928 if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, NULL, AIM_SSI_TYPE_PDINFO))) {
|
|
929 aim_freetlvchain(&tmp->data);
|
|
930 tmp->data = data;
|
2991
|
931 } else {
|
4230
|
932 tmp = aim_ssi_itemlist_add(&sess->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PDINFO, data);
|
4236
|
933 aim_freetlvchain(&data);
|
2991
|
934 }
|
|
935
|
4230
|
936 /* Sync our local list with the server list */
|
|
937 aim_ssi_sync(sess, conn);
|
2991
|
938
|
|
939 return 0;
|
|
940 }
|
|
941
|
3210
|
942 /**
|
3109
|
943 * Stores your setting for whether you should show up as idle or not.
|
3210
|
944 *
|
|
945 * @param sess The oscar session.
|
|
946 * @param conn The bos connection for this session.
|
|
947 * @param presence I think it's a bitmask, but I only know what one of the bits is:
|
|
948 * 0x00000400 - Allow others to see your idle time
|
|
949 * @return Return 0 if no errors, otherwise return the error number.
|
3109
|
950 */
|
|
951 faim_export int aim_ssi_setpresence(aim_session_t *sess, aim_conn_t *conn, fu32_t presence) {
|
4230
|
952 struct aim_ssi_item *tmp;
|
|
953 aim_tlvlist_t *data = NULL;
|
3109
|
954
|
|
955 if (!sess || !conn)
|
|
956 return -EINVAL;
|
|
957
|
4230
|
958 /* Need to add the x00c9 TLV to the TLV chain */
|
|
959 aim_addtlvtochain32(&data, 0x00c9, presence);
|
3109
|
960
|
4230
|
961 if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS))) {
|
|
962 aim_freetlvchain(&tmp->data);
|
|
963 tmp->data = data;
|
3109
|
964 } else {
|
4230
|
965 tmp = aim_ssi_itemlist_add(&sess->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PRESENCEPREFS, data);
|
4236
|
966 aim_freetlvchain(&data);
|
3109
|
967 }
|
|
968
|
4230
|
969 /* Sync our local list with the server list */
|
|
970 aim_ssi_sync(sess, conn);
|
3109
|
971
|
|
972 return 0;
|
|
973 }
|
|
974
|
|
975 /*
|
4230
|
976 * Subtype 0x0002 - Request SSI Rights.
|
2672
|
977 */
|
|
978 faim_export int aim_ssi_reqrights(aim_session_t *sess, aim_conn_t *conn)
|
|
979 {
|
3017
|
980 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_REQRIGHTS);
|
2672
|
981 }
|
|
982
|
|
983 /*
|
4230
|
984 * Subtype 0x0003 - SSI Rights Information.
|
2672
|
985 */
|
|
986 static int parserights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
987 {
|
4230
|
988 int ret = 0, i;
|
2672
|
989 aim_rxcallback_t userfunc;
|
4230
|
990 aim_tlvlist_t *tlvlist;
|
|
991 aim_tlv_t *tlv;
|
|
992 aim_bstream_t bstream;
|
|
993 fu16_t *maxitems;
|
|
994
|
|
995 /* This SNAC is made up of a bunch of TLVs */
|
|
996 tlvlist = aim_readtlvchain(bs);
|
|
997
|
|
998 /* TLV 0x0004 contains the maximum number of each item */
|
|
999 if (!(tlv = aim_gettlv(tlvlist, 0x0004, 1))) {
|
|
1000 aim_freetlvchain(&tlvlist);
|
|
1001 return 0;
|
|
1002 }
|
|
1003
|
|
1004 aim_bstream_init(&bstream, tlv->value, tlv->length);
|
|
1005
|
|
1006 if (!(maxitems = (fu16_t *)malloc((tlv->length/2)*sizeof(fu16_t)))) {
|
|
1007 aim_freetlvchain(&tlvlist);
|
|
1008 return 0;
|
|
1009 }
|
|
1010
|
|
1011 for (i=0; i<(tlv->length/2); i++)
|
|
1012 maxitems[i] = aimbs_get16(&bstream);
|
2672
|
1013
|
|
1014 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
4230
|
1015 ret = userfunc(sess, rx, tlv->length/2, maxitems);
|
|
1016
|
|
1017 aim_freetlvchain(&tlvlist);
|
|
1018 free(maxitems);
|
2672
|
1019
|
|
1020 return ret;
|
|
1021 }
|
|
1022
|
|
1023 /*
|
4230
|
1024 * Subtype 0x0004 - Request SSI Data.
|
|
1025 * XXX - If you don't a timestamp and revision number?
|
|
1026 *
|
|
1027 * Note that the client should never increment the revision, only the server.
|
|
1028 *
|
|
1029 */
|
|
1030
|
|
1031
|
|
1032 /*
|
|
1033 * Subtype 0x0005 - Request SSI Data.
|
|
1034 * XXX - If you have a timestamp and revision number?
|
2672
|
1035 *
|
|
1036 * The data will only be sent if it is newer than the posted local
|
|
1037 * timestamp and revision.
|
|
1038 *
|
|
1039 * Note that the client should never increment the revision, only the server.
|
|
1040 *
|
|
1041 */
|
|
1042 faim_export int aim_ssi_reqdata(aim_session_t *sess, aim_conn_t *conn, time_t localstamp, fu16_t localrev)
|
|
1043 {
|
|
1044 aim_frame_t *fr;
|
|
1045 aim_snacid_t snacid;
|
|
1046
|
|
1047 if (!sess || !conn)
|
|
1048 return -EINVAL;
|
|
1049
|
|
1050 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+2)))
|
|
1051 return -ENOMEM;
|
|
1052
|
3017
|
1053 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_REQLIST, 0x0000, NULL, 0);
|
2672
|
1054
|
3017
|
1055 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_REQLIST, 0x0000, snacid);
|
2672
|
1056 aimbs_put32(&fr->data, localstamp);
|
|
1057 aimbs_put16(&fr->data, localrev);
|
|
1058
|
|
1059 aim_tx_enqueue(sess, fr);
|
|
1060
|
4230
|
1061 /* Free any current data, just in case */
|
|
1062 aim_ssi_freelist(sess);
|
|
1063
|
2672
|
1064 return 0;
|
|
1065 }
|
|
1066
|
|
1067 /*
|
4230
|
1068 * Subtype 0x0006 - SSI Data.
|
2672
|
1069 */
|
|
1070 static int parsedata(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1071 {
|
|
1072 int ret = 0;
|
|
1073 aim_rxcallback_t userfunc;
|
|
1074 fu8_t fmtver; /* guess */
|
4236
|
1075 fu16_t numitems, namelen, gid, bid, type;
|
2991
|
1076 fu32_t timestamp;
|
4236
|
1077 char *name;
|
|
1078 aim_tlvlist_t *data;
|
2672
|
1079
|
4230
|
1080 if (snac->flags & 0x0001) {
|
|
1081 /* XXX - Free all ssi data? */
|
|
1082 }
|
|
1083
|
2991
|
1084 fmtver = aimbs_get8(bs); /* Version of ssi data. Should be 0x00 */
|
4236
|
1085 numitems = aimbs_get16(bs); /* # of items in this SSI SNAC */
|
4230
|
1086 sess->ssi.numitems += numitems;
|
2672
|
1087
|
4230
|
1088 /* Read in the list */
|
|
1089 while (aim_bstream_empty(bs) > 4) { /* last four bytes are timestamp */
|
2672
|
1090 if ((namelen = aimbs_get16(bs)))
|
4236
|
1091 name = aimbs_getstr(bs, namelen);
|
4230
|
1092 else
|
4236
|
1093 name = NULL;
|
|
1094 gid = aimbs_get16(bs);
|
|
1095 bid = aimbs_get16(bs);
|
|
1096 type = aimbs_get16(bs);
|
|
1097 data = aim_readtlvchain_len(bs, aimbs_get16(bs));
|
|
1098 aim_ssi_itemlist_add(&sess->ssi.official, name, gid, bid, type, data);
|
|
1099 free(name);
|
|
1100 aim_freetlvchain(&data);
|
2672
|
1101 }
|
|
1102
|
4230
|
1103 /* Read in the timestamp */
|
2991
|
1104 timestamp = aimbs_get32(bs);
|
4230
|
1105 sess->ssi.timestamp = timestamp;
|
2672
|
1106
|
4230
|
1107 if (!(snac->flags & 0x0001)) {
|
|
1108 /* Make a copy of the list */
|
4236
|
1109 struct aim_ssi_item *cur;
|
|
1110 for (cur=sess->ssi.official; cur; cur=cur->next)
|
|
1111 aim_ssi_itemlist_add(&sess->ssi.local, cur->name, cur->gid, cur->bid, cur->type, cur->data);
|
4230
|
1112
|
|
1113 sess->ssi.received_data = 1;
|
|
1114
|
|
1115 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1116 ret = userfunc(sess, rx, fmtver, sess->ssi.numitems, sess->ssi.official, sess->ssi.timestamp);
|
|
1117 }
|
2672
|
1118
|
|
1119 return ret;
|
|
1120 }
|
|
1121
|
|
1122 /*
|
4230
|
1123 * Subtype 0x0007 - SSI Activate Data.
|
2672
|
1124 *
|
|
1125 * Should be sent after receiving 13/6 or 13/f to tell the server you
|
|
1126 * are ready to begin using the list. It will promptly give you the
|
|
1127 * presence information for everyone in your list and put your permit/deny
|
|
1128 * settings into effect.
|
|
1129 *
|
|
1130 */
|
|
1131 faim_export int aim_ssi_enable(aim_session_t *sess, aim_conn_t *conn)
|
|
1132 {
|
3017
|
1133 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, 0x0007);
|
2672
|
1134 }
|
|
1135
|
|
1136 /*
|
4230
|
1137 * Subtype 0x0008/0x0009/0x000a - SSI Add/Mod/Del Item(s).
|
2991
|
1138 *
|
3017
|
1139 * Sends the SNAC to add, modify, or delete an item from the server-stored
|
|
1140 * information. These 3 SNACs all have an identical structure. The only
|
|
1141 * difference is the subtype that is set for the SNAC.
|
2991
|
1142 *
|
|
1143 */
|
4230
|
1144 faim_export int aim_ssi_addmoddel(aim_session_t *sess, aim_conn_t *conn)
|
2991
|
1145 {
|
|
1146 aim_frame_t *fr;
|
|
1147 aim_snacid_t snacid;
|
4230
|
1148 int snaclen;
|
|
1149 struct aim_ssi_tmp *cur;
|
2991
|
1150
|
4230
|
1151 if (!sess || !conn || !sess->ssi.pending || !sess->ssi.pending->item)
|
2991
|
1152 return -EINVAL;
|
|
1153
|
4230
|
1154 /* Calculate total SNAC size */
|
2991
|
1155 snaclen = 10; /* For family, subtype, flags, and SNAC ID */
|
4230
|
1156 for (cur=sess->ssi.pending; cur; cur=cur->next) {
|
2991
|
1157 snaclen += 10; /* For length, GID, BID, type, and length */
|
4230
|
1158 if (cur->item->name)
|
|
1159 snaclen += strlen(cur->item->name);
|
|
1160 if (cur->item->data)
|
|
1161 snaclen += aim_sizetlvchain(&cur->item->data);
|
2991
|
1162 }
|
|
1163
|
|
1164 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, snaclen)))
|
|
1165 return -ENOMEM;
|
|
1166
|
4230
|
1167 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, sess->ssi.pending->action, 0x0000, NULL, 0);
|
|
1168 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, sess->ssi.pending->action, 0x0000, snacid);
|
2991
|
1169
|
4230
|
1170 for (cur=sess->ssi.pending; cur; cur=cur->next) {
|
|
1171 aimbs_put16(&fr->data, cur->item->name ? strlen(cur->item->name) : 0);
|
|
1172 if (cur->item->name)
|
|
1173 aimbs_putraw(&fr->data, cur->item->name, strlen(cur->item->name));
|
|
1174 aimbs_put16(&fr->data, cur->item->gid);
|
|
1175 aimbs_put16(&fr->data, cur->item->bid);
|
|
1176 aimbs_put16(&fr->data, cur->item->type);
|
|
1177 aimbs_put16(&fr->data, cur->item->data ? aim_sizetlvchain(&cur->item->data) : 0);
|
|
1178 if (cur->item->data)
|
|
1179 aim_writetlvchain(&fr->data, &cur->item->data);
|
2991
|
1180 }
|
|
1181
|
4230
|
1182 aim_tx_enqueue(sess, fr);
|
2991
|
1183
|
|
1184 return 0;
|
|
1185 }
|
|
1186
|
|
1187 /*
|
4230
|
1188 * Subtype 0x0008 - Incoming SSI add.
|
|
1189 *
|
|
1190 * XXX - It would probably be good for the client to actually do something when it gets this.
|
|
1191 */
|
|
1192 static int parseadd(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1193 {
|
|
1194 int ret = 0;
|
|
1195 aim_rxcallback_t userfunc;
|
|
1196 char *name;
|
|
1197 fu16_t len, gid, bid, type;
|
|
1198 aim_tlvlist_t *data;
|
|
1199
|
|
1200 while (aim_bstream_empty(bs)) {
|
|
1201 if ((len = aimbs_get16(bs)))
|
|
1202 name = aimbs_getstr(bs, len);
|
|
1203 else
|
|
1204 name = NULL;
|
|
1205 gid = aimbs_get16(bs);
|
|
1206 bid = aimbs_get16(bs);
|
|
1207 type = aimbs_get16(bs);
|
|
1208 if ((len = aimbs_get16(bs)))
|
|
1209 data = aim_readtlvchain_len(bs, len);
|
|
1210 else
|
|
1211 data = NULL;
|
|
1212
|
|
1213 aim_ssi_itemlist_add(&sess->ssi.local, name, gid, bid, type, data);
|
4236
|
1214 aim_ssi_itemlist_add(&sess->ssi.official, name, gid, bid, type, data);
|
|
1215 free(name);
|
|
1216 aim_freetlvchain(&data);
|
4230
|
1217
|
|
1218 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1219 ret = userfunc(sess, rx);
|
|
1220
|
|
1221 free(name);
|
|
1222 }
|
|
1223
|
|
1224 return ret;
|
|
1225 }
|
|
1226
|
|
1227 /*
|
|
1228 * Subtype 0x0009 - Incoming SSI mod.
|
|
1229 *
|
|
1230 * XXX - It would probably be good for the client to actually do something when it gets this.
|
|
1231 */
|
|
1232 static int parsemod(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1233 {
|
|
1234 int ret = 0;
|
|
1235 aim_rxcallback_t userfunc;
|
|
1236 char *name;
|
|
1237 fu16_t len, gid, bid, type;
|
|
1238 aim_tlvlist_t *data;
|
|
1239 struct aim_ssi_item *item;
|
|
1240
|
|
1241 while (aim_bstream_empty(bs)) {
|
|
1242 if ((len = aimbs_get16(bs)))
|
|
1243 name = aimbs_getstr(bs, len);
|
|
1244 else
|
|
1245 name = NULL;
|
|
1246 gid = aimbs_get16(bs);
|
|
1247 bid = aimbs_get16(bs);
|
|
1248 type = aimbs_get16(bs);
|
|
1249 if ((len = aimbs_get16(bs)))
|
|
1250 data = aim_readtlvchain_len(bs, len);
|
|
1251 else
|
|
1252 data = NULL;
|
|
1253
|
|
1254 /* Replace the 2 local items with the given one */
|
|
1255 if ((item = aim_ssi_itemlist_find(sess->ssi.local, gid, bid))) {
|
|
1256 item->type = type;
|
|
1257 free(item->name);
|
|
1258 if (name) {
|
|
1259 item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
|
|
1260 strcpy(item->name, name);
|
|
1261 } else
|
|
1262 item->name = NULL;
|
|
1263 aim_freetlvchain(&item->data);
|
4234
|
1264 item->data = aim_tlvlist_copy(data);
|
4230
|
1265 }
|
|
1266
|
|
1267 if ((item = aim_ssi_itemlist_find(sess->ssi.official, gid, bid))) {
|
|
1268 item->type = type;
|
|
1269 free(item->name);
|
|
1270 if (name) {
|
|
1271 item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
|
|
1272 strcpy(item->name, name);
|
|
1273 } else
|
|
1274 item->name = NULL;
|
|
1275 aim_freetlvchain(&item->data);
|
4234
|
1276 item->data = aim_tlvlist_copy(data);
|
4230
|
1277 }
|
|
1278
|
|
1279 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1280 ret = userfunc(sess, rx);
|
|
1281
|
4236
|
1282 free(name);
|
4234
|
1283 aim_freetlvchain(&data);
|
4230
|
1284 }
|
|
1285
|
|
1286 return ret;
|
|
1287 }
|
|
1288
|
|
1289 /*
|
|
1290 * Subtype 0x000a - Incoming SSI del.
|
|
1291 *
|
|
1292 * XXX - It would probably be good for the client to actually do something when it gets this.
|
|
1293 */
|
|
1294 static int parsedel(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1295 {
|
|
1296 int ret = 0;
|
|
1297 aim_rxcallback_t userfunc;
|
|
1298 fu16_t gid, bid;
|
|
1299 struct aim_ssi_item *del;
|
|
1300
|
|
1301 while (aim_bstream_empty(bs)) {
|
|
1302 aim_bstream_advance(bs, aimbs_get16(bs));
|
|
1303 gid = aimbs_get16(bs);
|
|
1304 bid = aimbs_get16(bs);
|
|
1305 aimbs_get16(bs);
|
|
1306 aim_bstream_advance(bs, aimbs_get16(bs));
|
|
1307
|
|
1308 del = aim_ssi_itemlist_find(sess->ssi.local, gid, bid);
|
|
1309 aim_ssi_itemlist_del(&sess->ssi.local, del);
|
|
1310 del = aim_ssi_itemlist_find(sess->ssi.official, gid, bid);
|
|
1311 aim_ssi_itemlist_del(&sess->ssi.official, del);
|
|
1312
|
|
1313 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1314 ret = userfunc(sess, rx);
|
|
1315 }
|
|
1316
|
|
1317 return ret;
|
|
1318 }
|
|
1319
|
|
1320 /*
|
|
1321 * Subtype 0x000e - SSI Add/Mod/Del Ack.
|
2991
|
1322 *
|
3017
|
1323 * Response to add, modify, or delete SNAC (sent with aim_ssi_addmoddel).
|
2991
|
1324 *
|
|
1325 */
|
|
1326 static int parseack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1327 {
|
|
1328 int ret = 0;
|
|
1329 aim_rxcallback_t userfunc;
|
4230
|
1330 struct aim_ssi_tmp *cur, *del;
|
2991
|
1331
|
4230
|
1332 /* Read in the success/failure flags from the ack SNAC */
|
|
1333 cur = sess->ssi.pending;
|
|
1334 while (cur && (aim_bstream_empty(bs)>0)) {
|
|
1335 cur->ack = aimbs_get16(bs);
|
|
1336 cur = cur->next;
|
|
1337 }
|
|
1338
|
|
1339 /*
|
|
1340 * If outcome is 0, then add the item to the item list, or replace the other item,
|
|
1341 * or remove the old item. If outcome is non-zero, then remove the item from the
|
|
1342 * local list, or unmodify it, or add it.
|
|
1343 */
|
|
1344 for (cur=sess->ssi.pending; (cur && (cur->ack != 0xffff)); cur=cur->next) {
|
|
1345 if (cur->item) {
|
|
1346 if (cur->ack) {
|
|
1347 /* Our action was unsuccessful, so change the local list back to how it was */
|
|
1348 if (cur->action == AIM_CB_SSI_ADD) {
|
4236
|
1349 /* Remove the item from the local list */
|
4230
|
1350 if (cur->item->name) {
|
|
1351 cur->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
|
|
1352 strcpy(cur->name, cur->item->name);
|
|
1353 }
|
|
1354 aim_ssi_itemlist_del(&sess->ssi.local, cur->item);
|
|
1355 cur->item = NULL;
|
|
1356
|
|
1357 } else if (cur->action == AIM_CB_SSI_MOD) {
|
4236
|
1358 /* Replace the official item with the item in the local list */
|
4230
|
1359 struct aim_ssi_item *cur1;
|
|
1360 if ((cur1 = aim_ssi_itemlist_find(sess->ssi.local, cur->item->gid, cur->item->bid))) {
|
|
1361 free(cur1->name);
|
|
1362 if (cur->item->name) {
|
|
1363 cur1->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
|
|
1364 strcpy(cur1->name, cur->item->name);
|
|
1365 } else
|
|
1366 cur1->name = NULL;
|
|
1367 aim_freetlvchain(&cur1->data);
|
|
1368 cur1->data = aim_tlvlist_copy(cur->item->data);
|
|
1369 }
|
|
1370
|
|
1371 } else if (cur->action == AIM_CB_SSI_DEL) {
|
4236
|
1372 /* Add the item back into the local list */
|
|
1373 aim_ssi_itemlist_add(&sess->ssi.local, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
|
4230
|
1374 }
|
|
1375
|
|
1376 } else {
|
|
1377 /* Do the exact opposite */
|
|
1378 if (cur->action == AIM_CB_SSI_ADD) {
|
4236
|
1379 /* Add the item to the official list */
|
|
1380 aim_ssi_itemlist_add(&sess->ssi.official, cur->item->name, cur->item->gid, cur->item->bid, cur->item->type, cur->item->data);
|
4230
|
1381
|
|
1382 } else if (cur->action == AIM_CB_SSI_MOD) {
|
|
1383 /* Replace the old item with the new item in the items list */
|
|
1384 struct aim_ssi_item *cur1;
|
|
1385 if ((cur1 = aim_ssi_itemlist_find(sess->ssi.official, cur->item->gid, cur->item->bid))) {
|
|
1386 free(cur1->name);
|
|
1387 if (cur->item->name) {
|
|
1388 cur1->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
|
|
1389 strcpy(cur1->name, cur->item->name);
|
|
1390 } else
|
|
1391 cur1->name = NULL;
|
|
1392 aim_freetlvchain(&cur1->data);
|
|
1393 cur1->data = aim_tlvlist_copy(cur->item->data);
|
|
1394 }
|
|
1395
|
|
1396 } else if (cur->action == AIM_CB_SSI_DEL) {
|
|
1397 /* Remove the item from the items list */
|
|
1398 aim_ssi_itemlist_del(&sess->ssi.official, cur->item);
|
|
1399 cur->item = NULL;
|
|
1400 }
|
|
1401
|
|
1402 }
|
|
1403 } /* End if (cur->item) */
|
|
1404 } /* End for loop */
|
2991
|
1405
|
|
1406 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
4230
|
1407 ret = userfunc(sess, rx, sess->ssi.pending);
|
|
1408
|
|
1409 /* Free all aim_ssi_tmp's with an outcome */
|
|
1410 cur = sess->ssi.pending;
|
|
1411 while (cur && (cur->ack != 0xffff)) {
|
|
1412 del = cur;
|
|
1413 cur = cur->next;
|
|
1414 free(del->name);
|
|
1415 free(del);
|
|
1416 }
|
|
1417 sess->ssi.pending = cur;
|
|
1418
|
|
1419 /* If we're not waiting for any more acks, then send more SNACs */
|
|
1420 if (!sess->ssi.pending) {
|
|
1421 sess->ssi.pending = NULL;
|
|
1422 sess->ssi.waiting_for_ack = 0;
|
|
1423 aim_ssi_sync(sess, rx->conn);
|
|
1424 }
|
2991
|
1425
|
|
1426 return ret;
|
|
1427 }
|
|
1428
|
|
1429 /*
|
4230
|
1430 * Subtype 0x000f - SSI Data Unchanged.
|
2672
|
1431 *
|
|
1432 * Response to aim_ssi_reqdata() if the server-side data is not newer than
|
|
1433 * posted local stamp/revision.
|
|
1434 *
|
|
1435 */
|
|
1436 static int parsedataunchanged(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1437 {
|
|
1438 int ret = 0;
|
|
1439 aim_rxcallback_t userfunc;
|
|
1440
|
2991
|
1441 sess->ssi.received_data = 1;
|
|
1442
|
2672
|
1443 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1444 ret = userfunc(sess, rx);
|
|
1445
|
|
1446 return ret;
|
|
1447 }
|
|
1448
|
4230
|
1449 /*
|
|
1450 * Subtype 0x0011 - SSI Begin Data Modification.
|
|
1451 *
|
|
1452 * Tells the server you're going to start modifying data.
|
|
1453 *
|
|
1454 */
|
|
1455 faim_export int aim_ssi_modbegin(aim_session_t *sess, aim_conn_t *conn)
|
|
1456 {
|
|
1457 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_EDITSTART);
|
|
1458 }
|
|
1459
|
|
1460 /*
|
|
1461 * Subtype 0x0012 - SSI End Data Modification.
|
|
1462 *
|
|
1463 * Tells the server you're finished modifying data.
|
|
1464 *
|
|
1465 */
|
|
1466 faim_export int aim_ssi_modend(aim_session_t *sess, aim_conn_t *conn)
|
|
1467 {
|
|
1468 return aim_genericreq_n(sess, conn, AIM_CB_FAM_SSI, AIM_CB_SSI_EDITSTOP);
|
|
1469 }
|
|
1470
|
|
1471 /*
|
|
1472 * Subtype 0x0014 - Grant authorization
|
|
1473 *
|
|
1474 * Authorizes a contact so they can add you to their contact list.
|
|
1475 *
|
|
1476 */
|
|
1477 faim_export int aim_ssi_sendauth(aim_session_t *sess, aim_conn_t *conn, char *sn, char *msg)
|
|
1478 {
|
|
1479 aim_frame_t *fr;
|
|
1480 aim_snacid_t snacid;
|
|
1481
|
|
1482 if (!sess || !conn || !sn)
|
|
1483 return -EINVAL;
|
|
1484
|
|
1485 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
|
|
1486 return -ENOMEM;
|
|
1487
|
|
1488 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTH, 0x0000, NULL, 0);
|
|
1489 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTH, 0x0000, snacid);
|
|
1490
|
|
1491 /* Screen name */
|
|
1492 aimbs_put8(&fr->data, strlen(sn));
|
|
1493 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1494
|
|
1495 /* Message (null terminated) */
|
|
1496 aimbs_put16(&fr->data, msg ? strlen(msg) : 0);
|
|
1497 if (msg) {
|
|
1498 aimbs_putraw(&fr->data, msg, strlen(msg));
|
|
1499 aimbs_put8(&fr->data, 0x00);
|
|
1500 }
|
|
1501
|
|
1502 /* Unknown */
|
|
1503 aimbs_put16(&fr->data, 0x0000);
|
|
1504
|
|
1505 aim_tx_enqueue(sess, fr);
|
|
1506
|
|
1507 return 0;
|
|
1508 }
|
|
1509
|
|
1510 /*
|
|
1511 * Subtype 0x0015 - Receive an authorization grant
|
|
1512 */
|
|
1513 static int receiveauthgrant(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1514 {
|
|
1515 int ret = 0;
|
|
1516 aim_rxcallback_t userfunc;
|
|
1517 fu16_t tmp;
|
|
1518 char *sn, *msg;
|
|
1519
|
|
1520 /* Read screen name */
|
|
1521 if ((tmp = aimbs_get8(bs)))
|
|
1522 sn = aimbs_getstr(bs, tmp);
|
|
1523 else
|
|
1524 sn = NULL;
|
|
1525
|
|
1526 /* Read message (null terminated) */
|
|
1527 if ((tmp = aimbs_get16(bs)))
|
|
1528 msg = aimbs_getstr(bs, tmp);
|
|
1529 else
|
|
1530 msg = NULL;
|
|
1531
|
|
1532 /* Unknown */
|
|
1533 tmp = aimbs_get16(bs);
|
|
1534
|
|
1535 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1536 ret = userfunc(sess, rx, sn, msg);
|
|
1537
|
|
1538 free(sn);
|
|
1539 free(msg);
|
|
1540
|
|
1541 return ret;
|
|
1542 }
|
|
1543
|
|
1544 /*
|
|
1545 * Subtype 0x0018 - Send authorization request
|
|
1546 *
|
|
1547 * Sends a request for authorization to the given contact. The request will either be
|
|
1548 * granted, denied, or dropped.
|
|
1549 *
|
|
1550 */
|
|
1551 faim_export int aim_ssi_sendauthrequest(aim_session_t *sess, aim_conn_t *conn, char *sn, char *msg)
|
|
1552 {
|
|
1553 aim_frame_t *fr;
|
|
1554 aim_snacid_t snacid;
|
|
1555
|
|
1556 if (!sess || !conn || !sn)
|
|
1557 return -EINVAL;
|
|
1558
|
|
1559 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)+2+(msg ? strlen(msg)+1 : 0)+2)))
|
|
1560 return -ENOMEM;
|
|
1561
|
|
1562 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREQ, 0x0000, NULL, 0);
|
|
1563 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREQ, 0x0000, snacid);
|
|
1564
|
|
1565 /* Screen name */
|
|
1566 aimbs_put8(&fr->data, strlen(sn));
|
|
1567 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1568
|
|
1569 /* Message (null terminated) */
|
|
1570 aimbs_put16(&fr->data, msg ? strlen(msg) : 0);
|
|
1571 if (msg) {
|
|
1572 aimbs_putraw(&fr->data, msg, strlen(msg));
|
|
1573 aimbs_put8(&fr->data, 0x00);
|
|
1574 }
|
|
1575
|
|
1576 /* Unknown */
|
|
1577 aimbs_put16(&fr->data, 0x0000);
|
|
1578
|
|
1579 aim_tx_enqueue(sess, fr);
|
|
1580
|
|
1581 return 0;
|
|
1582 }
|
|
1583
|
|
1584 /*
|
|
1585 * Subtype 0x0019 - Receive an authorization request
|
|
1586 */
|
|
1587 static int receiveauthrequest(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1588 {
|
|
1589 int ret = 0;
|
|
1590 aim_rxcallback_t userfunc;
|
|
1591 fu16_t tmp;
|
|
1592 char *sn, *msg;
|
|
1593
|
|
1594 /* Read screen name */
|
|
1595 if ((tmp = aimbs_get8(bs)))
|
|
1596 sn = aimbs_getstr(bs, tmp);
|
|
1597 else
|
|
1598 sn = NULL;
|
|
1599
|
|
1600 /* Read message (null terminated) */
|
|
1601 if ((tmp = aimbs_get16(bs)))
|
|
1602 msg = aimbs_getstr(bs, tmp);
|
|
1603 else
|
|
1604 msg = NULL;
|
|
1605
|
|
1606 /* Unknown */
|
|
1607 tmp = aimbs_get16(bs);
|
|
1608
|
|
1609 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1610 ret = userfunc(sess, rx, sn, msg);
|
|
1611
|
|
1612 free(sn);
|
|
1613 free(msg);
|
|
1614
|
|
1615 return ret;
|
|
1616 }
|
|
1617
|
|
1618 /*
|
|
1619 * Subtype 0x001a - Send authorization reply
|
|
1620 *
|
|
1621 * Sends a reply to a request for authorization. The reply can either
|
|
1622 * grant authorization or deny authorization.
|
|
1623 *
|
|
1624 * if reply=0x00 then deny
|
|
1625 * if reply=0x01 then grant
|
|
1626 *
|
|
1627 */
|
|
1628 faim_export int aim_ssi_sendauthreply(aim_session_t *sess, aim_conn_t *conn, char *sn, fu8_t reply, char *msg)
|
|
1629 {
|
|
1630 aim_frame_t *fr;
|
|
1631 aim_snacid_t snacid;
|
|
1632
|
|
1633 if (!sess || !conn || !sn)
|
|
1634 return -EINVAL;
|
|
1635
|
|
1636 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 1+strlen(sn) + 1 + 2+(msg ? strlen(msg)+1 : 0) + 2)))
|
|
1637 return -ENOMEM;
|
|
1638
|
|
1639 snacid = aim_cachesnac(sess, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREP, 0x0000, NULL, 0);
|
|
1640 aim_putsnac(&fr->data, AIM_CB_FAM_SSI, AIM_CB_SSI_SENDAUTHREP, 0x0000, snacid);
|
|
1641
|
|
1642 /* Screen name */
|
|
1643 aimbs_put8(&fr->data, strlen(sn));
|
|
1644 aimbs_putraw(&fr->data, sn, strlen(sn));
|
|
1645
|
|
1646 /* Grant or deny */
|
|
1647 aimbs_put8(&fr->data, reply);
|
|
1648
|
|
1649 /* Message (null terminated) */
|
|
1650 aimbs_put16(&fr->data, msg ? (strlen(msg)+1) : 0);
|
|
1651 if (msg) {
|
|
1652 aimbs_putraw(&fr->data, msg, strlen(msg));
|
|
1653 aimbs_put8(&fr->data, 0x00);
|
|
1654 }
|
|
1655
|
|
1656 /* Unknown */
|
|
1657 aimbs_put16(&fr->data, 0x0000);
|
|
1658
|
|
1659 aim_tx_enqueue(sess, fr);
|
|
1660
|
|
1661 return 0;
|
|
1662 }
|
|
1663
|
|
1664 /*
|
|
1665 * Subtype 0x001b - Receive an authorization reply
|
|
1666 * You get this bad boy when other people respond to the authorization
|
|
1667 * request that you have previously sent them.
|
|
1668 */
|
|
1669 static int receiveauthreply(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1670 {
|
|
1671 int ret = 0;
|
|
1672 aim_rxcallback_t userfunc;
|
|
1673 fu16_t tmp;
|
|
1674 fu8_t reply;
|
|
1675 char *sn, *msg;
|
|
1676
|
|
1677 /* Read screen name */
|
|
1678 if ((tmp = aimbs_get8(bs)))
|
|
1679 sn = aimbs_getstr(bs, tmp);
|
|
1680 else
|
|
1681 sn = NULL;
|
|
1682
|
|
1683 /* Read reply */
|
|
1684 reply = aimbs_get8(bs);
|
|
1685
|
|
1686 /* Read message (null terminated) */
|
|
1687 if ((tmp = aimbs_get16(bs)))
|
|
1688 msg = aimbs_getstr(bs, tmp);
|
|
1689 else
|
|
1690 msg = NULL;
|
|
1691
|
|
1692 /* Unknown */
|
|
1693 tmp = aimbs_get16(bs);
|
|
1694
|
|
1695 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1696 ret = userfunc(sess, rx, sn, reply, msg);
|
|
1697
|
|
1698 free(sn);
|
|
1699 free(msg);
|
|
1700
|
|
1701 return ret;
|
|
1702 }
|
|
1703
|
|
1704 /*
|
|
1705 * Subtype 0x001c - Receive a message telling you someone added you to their list.
|
|
1706 */
|
|
1707 static int receiveadded(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1708 {
|
|
1709 int ret = 0;
|
|
1710 aim_rxcallback_t userfunc;
|
|
1711 fu16_t tmp;
|
|
1712 char *sn;
|
|
1713
|
|
1714 /* Read screen name */
|
|
1715 if ((tmp = aimbs_get8(bs)))
|
|
1716 sn = aimbs_getstr(bs, tmp);
|
|
1717 else
|
|
1718 sn = NULL;
|
|
1719
|
|
1720 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
1721 ret = userfunc(sess, rx, sn);
|
|
1722
|
|
1723 free(sn);
|
|
1724
|
|
1725 return ret;
|
|
1726 }
|
|
1727
|
2672
|
1728 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
1729 {
|
|
1730
|
3017
|
1731 if (snac->subtype == AIM_CB_SSI_RIGHTSINFO)
|
2672
|
1732 return parserights(sess, mod, rx, snac, bs);
|
3017
|
1733 else if (snac->subtype == AIM_CB_SSI_LIST)
|
2672
|
1734 return parsedata(sess, mod, rx, snac, bs);
|
4230
|
1735 else if (snac->subtype == AIM_CB_SSI_ADD)
|
|
1736 return parseadd(sess, mod, rx, snac, bs);
|
|
1737 else if (snac->subtype == AIM_CB_SSI_MOD)
|
|
1738 return parsemod(sess, mod, rx, snac, bs);
|
|
1739 else if (snac->subtype == AIM_CB_SSI_DEL)
|
|
1740 return parsedel(sess, mod, rx, snac, bs);
|
2991
|
1741 else if (snac->subtype == AIM_CB_SSI_SRVACK)
|
|
1742 return parseack(sess, mod, rx, snac, bs);
|
3017
|
1743 else if (snac->subtype == AIM_CB_SSI_NOLIST)
|
2672
|
1744 return parsedataunchanged(sess, mod, rx, snac, bs);
|
4230
|
1745 else if (snac->subtype == AIM_CB_SSI_RECVAUTH)
|
|
1746 return receiveauthgrant(sess, mod, rx, snac, bs);
|
|
1747 else if (snac->subtype == AIM_CB_SSI_RECVAUTHREQ)
|
|
1748 return receiveauthrequest(sess, mod, rx, snac, bs);
|
|
1749 else if (snac->subtype == AIM_CB_SSI_RECVAUTHREP)
|
|
1750 return receiveauthreply(sess, mod, rx, snac, bs);
|
|
1751 else if (snac->subtype == AIM_CB_SSI_ADDED)
|
|
1752 return receiveadded(sess, mod, rx, snac, bs);
|
2672
|
1753
|
|
1754 return 0;
|
|
1755 }
|
|
1756
|
2991
|
1757 static void ssi_shutdown(aim_session_t *sess, aim_module_t *mod)
|
|
1758 {
|
|
1759 aim_ssi_freelist(sess);
|
|
1760
|
|
1761 return;
|
|
1762 }
|
|
1763
|
2672
|
1764 faim_internal int ssi_modfirst(aim_session_t *sess, aim_module_t *mod)
|
|
1765 {
|
|
1766
|
3017
|
1767 mod->family = AIM_CB_FAM_SSI;
|
4230
|
1768 mod->version = 0x0004;
|
2672
|
1769 mod->toolid = 0x0110;
|
4071
|
1770 mod->toolversion = 0x0629;
|
2672
|
1771 mod->flags = 0;
|
|
1772 strncpy(mod->name, "ssi", sizeof(mod->name));
|
|
1773 mod->snachandler = snachandler;
|
2991
|
1774 mod->shutdown = ssi_shutdown;
|
2672
|
1775
|
|
1776 return 0;
|
|
1777 }
|