Mercurial > pidgin.yaz
comparison src/protocols/oscar/ssi.c @ 7166:e6b01bd8d6cd
[gaim-migrate @ 7733]
I fixed the notify_added function, Chip had two of the variables swapped :-)
I changed the way tlvlists are done in ssi.c a little bit. You can alias
ICQ buddies that you don't have authorization for yet, and when you alias
a buddy you will no longer lose any Buddy Alerts that may be set.
Why is this? Previously tlvlists (data associated with each server stored
item) were just deleted and recreated when you set an alias, or changed your
permit/deny setting. Now the lists are modified and TLVs that libfaim
doesn't know about are just left in place.
Why did I wait so long to do this? I'm lazy, it's not really all that fun,
and I don't consider it all that important.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 05 Oct 2003 22:41:29 +0000 |
parents | aee5fd893aba |
children | 6d3d8f11e765 |
comparison
equal
deleted
inserted
replaced
7165:a230b7bca1fb | 7166:e6b01bd8d6cd |
---|---|
43 return NULL; | 43 return NULL; |
44 | 44 |
45 /* Find the group */ | 45 /* Find the group */ |
46 if (!(group = aim_ssi_itemlist_finditem(list, name, NULL, AIM_SSI_TYPE_GROUP))) | 46 if (!(group = aim_ssi_itemlist_finditem(list, name, NULL, AIM_SSI_TYPE_GROUP))) |
47 return NULL; | 47 return NULL; |
48 | |
49 /* Free the old data */ | |
50 aim_freetlvchain(&group->data); | |
51 group->data = NULL; | |
52 | 48 |
53 /* Find the length for the new additional data */ | 49 /* Find the length for the new additional data */ |
54 newlen = 0; | 50 newlen = 0; |
55 if (group->gid == 0x0000) { | 51 if (group->gid == 0x0000) { |
56 for (cur=list; cur; cur=cur->next) | 52 for (cur=list; cur; cur=cur->next) |
76 } else { | 72 } else { |
77 for (cur=list; cur; cur=cur->next) | 73 for (cur=list; cur; cur=cur->next) |
78 if ((cur->gid == group->gid) && (cur->type == AIM_SSI_TYPE_BUDDY)) | 74 if ((cur->gid == group->gid) && (cur->type == AIM_SSI_TYPE_BUDDY)) |
79 newlen += aimutil_put16(newdata+newlen, cur->bid); | 75 newlen += aimutil_put16(newdata+newlen, cur->bid); |
80 } | 76 } |
81 aim_addtlvtochain_raw(&group->data, 0x00c8, newlen, newdata); | 77 aim_tlvlist_replace_raw(&group->data, 0x00c8, newlen, newdata); |
82 | 78 |
83 free(newdata); | 79 free(newdata); |
84 } | 80 } |
85 | 81 |
86 return group; | 82 return group; |
181 *list = (*list)->next; | 177 *list = (*list)->next; |
182 } else { | 178 } else { |
183 struct aim_ssi_item *cur; | 179 struct aim_ssi_item *cur; |
184 for (cur=*list; (cur->next && (cur->next!=del)); cur=cur->next); | 180 for (cur=*list; (cur->next && (cur->next!=del)); cur=cur->next); |
185 if (cur->next) | 181 if (cur->next) |
186 cur->next = cur->next->next; | 182 cur->next = del->next; |
187 } | 183 } |
188 | 184 |
189 /* Free the deleted item */ | 185 /* Free the removed item */ |
190 free(del->name); | 186 free(del->name); |
191 aim_freetlvchain(&del->data); | 187 aim_freetlvchain(&del->data); |
192 free(del); | 188 free(del); |
193 | 189 |
194 return 0; | 190 return 0; |
355 */ | 351 */ |
356 faim_export int aim_ssi_getpermdeny(struct aim_ssi_item *list) | 352 faim_export int aim_ssi_getpermdeny(struct aim_ssi_item *list) |
357 { | 353 { |
358 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PDINFO); | 354 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PDINFO); |
359 if (cur) { | 355 if (cur) { |
360 aim_tlvlist_t *tlvlist = cur->data; | 356 aim_tlv_t *tlv = aim_gettlv(cur->data, 0x00ca, 1); |
361 if (tlvlist) { | 357 if (tlv && tlv->value) |
362 aim_tlv_t *tlv = aim_gettlv(tlvlist, 0x00ca, 1); | 358 return aimutil_get8(tlv->value); |
363 if (tlv && tlv->value) | |
364 return aimutil_get8(tlv->value); | |
365 } | |
366 } | 359 } |
367 return 0; | 360 return 0; |
368 } | 361 } |
369 | 362 |
370 /** | 363 /** |
377 */ | 370 */ |
378 faim_export fu32_t aim_ssi_getpresence(struct aim_ssi_item *list) | 371 faim_export fu32_t aim_ssi_getpresence(struct aim_ssi_item *list) |
379 { | 372 { |
380 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS); | 373 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS); |
381 if (cur) { | 374 if (cur) { |
382 aim_tlvlist_t *tlvlist = cur->data; | 375 aim_tlv_t *tlv = aim_gettlv(cur->data, 0x00c9, 1); |
383 if (tlvlist) { | 376 if (tlv && tlv->length) |
384 aim_tlv_t *tlv = aim_gettlv(tlvlist, 0x00c9, 1); | 377 return aimutil_get32(tlv->value); |
385 if (tlv && tlv->length) | |
386 return aimutil_get32(tlv->value); | |
387 } | |
388 } | 378 } |
389 return 0xFFFFFFFF; | 379 return 0xFFFFFFFF; |
390 } | 380 } |
391 | 381 |
392 /** | 382 /** |
401 */ | 391 */ |
402 faim_export char *aim_ssi_getalias(struct aim_ssi_item *list, const char *gn, const char *sn) | 392 faim_export char *aim_ssi_getalias(struct aim_ssi_item *list, const char *gn, const char *sn) |
403 { | 393 { |
404 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY); | 394 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY); |
405 if (cur) { | 395 if (cur) { |
406 aim_tlvlist_t *tlvlist = cur->data; | 396 aim_tlv_t *tlv = aim_gettlv(cur->data, 0x0131, 1); |
407 if (tlvlist) { | 397 if (tlv && tlv->length) { |
408 aim_tlv_t *tlv = aim_gettlv(tlvlist, 0x0131, 1); | 398 char *alias = (char *)malloc((tlv->length+1)*sizeof(char)); |
409 if (tlv && tlv->length) { | 399 strncpy(alias, tlv->value, tlv->length); |
410 char *alias = (char *)malloc((tlv->length+1)*sizeof(char)); | 400 alias[tlv->length] = 0; |
411 strncpy(alias, tlv->value, tlv->length); | 401 return alias; |
412 alias[tlv->length] = 0; | |
413 return alias; | |
414 } | |
415 } | 402 } |
416 } | 403 } |
417 return NULL; | 404 return NULL; |
418 } | 405 } |
419 | 406 |
429 */ | 416 */ |
430 faim_export int aim_ssi_waitingforauth(struct aim_ssi_item *list, const char *gn, const char *sn) | 417 faim_export int aim_ssi_waitingforauth(struct aim_ssi_item *list, const char *gn, const char *sn) |
431 { | 418 { |
432 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY); | 419 struct aim_ssi_item *cur = aim_ssi_itemlist_finditem(list, gn, sn, AIM_SSI_TYPE_BUDDY); |
433 if (cur) { | 420 if (cur) { |
434 aim_tlvlist_t *tlvlist = cur->data; | 421 if (aim_gettlv(cur->data, 0x0066, 1)) |
435 if (tlvlist) | 422 return 1; |
436 if (aim_gettlv(tlvlist, 0x0066, 1)) | |
437 return 1; | |
438 } | 423 } |
439 return 0; | 424 return 0; |
440 } | 425 } |
441 | 426 |
442 /** | 427 /** |
894 * Change the alias stored on the server for a given buddy. | 879 * Change the alias stored on the server for a given buddy. |
895 * | 880 * |
896 * @param sess The oscar session. | 881 * @param sess The oscar session. |
897 * @param gn The group that the buddy is currently in. | 882 * @param gn The group that the buddy is currently in. |
898 * @param sn The screen name of the buddy. | 883 * @param sn The screen name of the buddy. |
899 * @param alias The new alias for the buddy. | 884 * @param alias The new alias for the buddy, or NULL if you want to remove |
885 * a buddies alias. | |
900 * @return Return 0 if no errors, otherwise return the error number. | 886 * @return Return 0 if no errors, otherwise return the error number. |
901 */ | 887 */ |
902 faim_export int aim_ssi_aliasbuddy(aim_session_t *sess, const char *gn, const char *sn, const char *alias) | 888 faim_export int aim_ssi_aliasbuddy(aim_session_t *sess, const char *gn, const char *sn, const char *alias) |
903 { | 889 { |
904 struct aim_ssi_item *tmp; | 890 struct aim_ssi_item *tmp; |
905 aim_tlvlist_t *data = NULL; | |
906 | 891 |
907 if (!sess || !gn || !sn) | 892 if (!sess || !gn || !sn) |
908 return -EINVAL; | 893 return -EINVAL; |
909 | 894 |
910 if (!(tmp = aim_ssi_itemlist_finditem(sess->ssi.local, gn, sn, AIM_SSI_TYPE_BUDDY))) | 895 if (!(tmp = aim_ssi_itemlist_finditem(sess->ssi.local, gn, sn, AIM_SSI_TYPE_BUDDY))) |
911 return -EINVAL; | 896 return -EINVAL; |
912 | 897 |
913 if (alias && !strlen(alias)) | 898 /* Either add or remove the 0x0131 TLV from the TLV chain */ |
914 alias = NULL; | 899 if ((alias != NULL) && (strlen(alias) > 0)) |
915 | 900 aim_tlvlist_replace_raw(&tmp->data, 0x0131, strlen(alias), alias); |
916 /* Need to add the x0131 TLV to the TLV chain */ | 901 else |
917 if (alias) | 902 aim_tlvlist_remove(&tmp->data, 0x0131); |
918 aim_addtlvtochain_raw(&data, 0x0131, strlen(alias), alias); | |
919 | |
920 aim_freetlvchain(&tmp->data); | |
921 tmp->data = data; | |
922 | 903 |
923 /* Sync our local list with the server list */ | 904 /* Sync our local list with the server list */ |
924 aim_ssi_sync(sess); | 905 aim_ssi_sync(sess); |
925 | 906 |
926 return 0; | 907 return 0; |
969 * @return Return 0 if no errors, otherwise return the error number. | 950 * @return Return 0 if no errors, otherwise return the error number. |
970 */ | 951 */ |
971 faim_export int aim_ssi_setpermdeny(aim_session_t *sess, fu8_t permdeny, fu32_t vismask) | 952 faim_export int aim_ssi_setpermdeny(aim_session_t *sess, fu8_t permdeny, fu32_t vismask) |
972 { | 953 { |
973 struct aim_ssi_item *tmp; | 954 struct aim_ssi_item *tmp; |
974 aim_tlvlist_t *data = NULL; | |
975 | 955 |
976 if (!sess) | 956 if (!sess) |
977 return -EINVAL; | 957 return -EINVAL; |
978 | 958 |
979 /* Need to add the x00ca TLV to the TLV chain */ | 959 /* Find the PDINFO item, or add it if it does not exist */ |
980 aim_addtlvtochain8(&data, 0x00ca, permdeny); | 960 if (!(tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, NULL, AIM_SSI_TYPE_PDINFO))) |
981 | 961 tmp = aim_ssi_itemlist_add(&sess->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PDINFO, NULL); |
982 /* Need to add the x00cb TLV to the TLV chain */ | 962 |
983 aim_addtlvtochain32(&data, 0x00cb, vismask); | 963 /* Need to add the 0x00ca TLV to the TLV chain */ |
984 | 964 aim_tlvlist_replace_8(&tmp->data, 0x00ca, permdeny); |
985 if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, NULL, AIM_SSI_TYPE_PDINFO))) { | 965 |
986 aim_freetlvchain(&tmp->data); | 966 /* Need to add the 0x00cb TLV to the TLV chain */ |
987 tmp->data = data; | 967 aim_tlvlist_replace_32(&tmp->data, 0x00cb, vismask); |
988 } else { | |
989 tmp = aim_ssi_itemlist_add(&sess->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PDINFO, data); | |
990 aim_freetlvchain(&data); | |
991 } | |
992 | 968 |
993 /* Sync our local list with the server list */ | 969 /* Sync our local list with the server list */ |
994 aim_ssi_sync(sess); | 970 aim_ssi_sync(sess); |
995 | 971 |
996 return 0; | 972 return 0; |
1005 * @return Return 0 if no errors, otherwise return the error number. | 981 * @return Return 0 if no errors, otherwise return the error number. |
1006 */ | 982 */ |
1007 faim_export int aim_ssi_seticon(aim_session_t *sess, fu8_t *iconsum, fu16_t iconsumlen) | 983 faim_export int aim_ssi_seticon(aim_session_t *sess, fu8_t *iconsum, fu16_t iconsumlen) |
1008 { | 984 { |
1009 struct aim_ssi_item *tmp; | 985 struct aim_ssi_item *tmp; |
1010 aim_tlvlist_t *data = NULL; | |
1011 fu8_t *csumdata; | 986 fu8_t *csumdata; |
1012 | 987 |
1013 if (!sess || !iconsum || !iconsumlen) | 988 if (!sess || !iconsum || !iconsumlen) |
1014 return -EINVAL; | 989 return -EINVAL; |
1015 | 990 |
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 */ | |
1016 if (!(csumdata = (fu8_t *)malloc((iconsumlen+2)*sizeof(fu8_t)))) | 997 if (!(csumdata = (fu8_t *)malloc((iconsumlen+2)*sizeof(fu8_t)))) |
1017 return -ENOMEM; | 998 return -ENOMEM; |
1018 csumdata[0] = 0x00; | 999 csumdata[0] = 0x00; |
1019 csumdata[1] = 0x10; | 1000 csumdata[1] = 0x10; |
1020 memcpy(&csumdata[2], iconsum, iconsumlen); | 1001 memcpy(&csumdata[2], iconsum, iconsumlen); |
1021 | 1002 aim_tlvlist_replace_raw(&tmp->data, 0x00d5, (iconsumlen+2) * sizeof(fu8_t), csumdata); |
1022 /* Need to add the x00d5 TLV to the TLV chain */ | 1003 free(csumdata); |
1023 aim_addtlvtochain_raw(&data, 0x00d5, (iconsumlen+2) * sizeof(fu8_t), csumdata); | 1004 |
1024 | 1005 /* Need to add the 0x0131 TLV to the TLV chain, used to cache the icon */ |
1025 /* This TLV is added to cache the icon. */ | 1006 aim_tlvlist_replace_noval(&tmp->data, 0x0131); |
1026 aim_addtlvtochain_noval(&data, 0x0131); | |
1027 | |
1028 if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, "1", AIM_SSI_TYPE_ICONINFO))) { | |
1029 /* If the new tlvchain and oldtlvchain are the same, then do nothing */ | |
1030 if (!aim_tlvlist_cmp(tmp->data, data)) { | |
1031 /* The new tlvlist is the identical to the old one */ | |
1032 aim_freetlvchain(&data); | |
1033 free(csumdata); | |
1034 return 0; | |
1035 } | |
1036 aim_freetlvchain(&tmp->data); | |
1037 tmp->data = data; | |
1038 } else { | |
1039 tmp = aim_ssi_itemlist_add(&sess->ssi.local, "1", 0x0000, 0x51F4, AIM_SSI_TYPE_ICONINFO, data); | |
1040 aim_freetlvchain(&data); | |
1041 } | |
1042 | 1007 |
1043 /* Sync our local list with the server list */ | 1008 /* Sync our local list with the server list */ |
1044 aim_ssi_sync(sess); | 1009 aim_ssi_sync(sess); |
1045 free(csumdata); | |
1046 return 0; | 1010 return 0; |
1047 } | 1011 } |
1048 | 1012 |
1049 /** | 1013 /** |
1050 * Stores your setting for whether you should show up as idle or not. | 1014 * Stores your setting for whether you should show up as idle or not. |
1054 * 0x00000400 - Allow others to see your idle time | 1018 * 0x00000400 - Allow others to see your idle time |
1055 * @return Return 0 if no errors, otherwise return the error number. | 1019 * @return Return 0 if no errors, otherwise return the error number. |
1056 */ | 1020 */ |
1057 faim_export int aim_ssi_setpresence(aim_session_t *sess, fu32_t presence) { | 1021 faim_export int aim_ssi_setpresence(aim_session_t *sess, fu32_t presence) { |
1058 struct aim_ssi_item *tmp; | 1022 struct aim_ssi_item *tmp; |
1059 aim_tlvlist_t *data = NULL; | |
1060 | 1023 |
1061 if (!sess) | 1024 if (!sess) |
1062 return -EINVAL; | 1025 return -EINVAL; |
1063 | 1026 |
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); | |
1030 | |
1064 /* Need to add the x00c9 TLV to the TLV chain */ | 1031 /* Need to add the x00c9 TLV to the TLV chain */ |
1065 aim_addtlvtochain32(&data, 0x00c9, presence); | 1032 aim_tlvlist_replace_32(&tmp->data, 0x00c9, presence); |
1066 | |
1067 if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, NULL, AIM_SSI_TYPE_PRESENCEPREFS))) { | |
1068 aim_freetlvchain(&tmp->data); | |
1069 tmp->data = data; | |
1070 } else { | |
1071 tmp = aim_ssi_itemlist_add(&sess->ssi.local, NULL, 0x0000, 0xFFFF, AIM_SSI_TYPE_PRESENCEPREFS, data); | |
1072 aim_freetlvchain(&data); | |
1073 } | |
1074 | 1033 |
1075 /* Sync our local list with the server list */ | 1034 /* Sync our local list with the server list */ |
1076 aim_ssi_sync(sess); | 1035 aim_ssi_sync(sess); |
1077 | 1036 |
1078 return 0; | 1037 return 0; |