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