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