comparison libpurple/protocols/oscar/family_feedbag.c @ 32389:fac08a235b68

Make the oscar cleanlist function ensure that buddy comments and aliases are valid utf8. If they're not, then we use purple_utf8_salvage() to fix them and save the result in our server list.
author Mark Doliner <mark@kingant.net>
date Mon, 12 Dec 2011 09:01:21 +0000
parents 3a4fc19e168e
children 28b741b2fc1d
comparison
equal deleted inserted replaced
32388:3a4fc19e168e 32389:fac08a235b68
732 od->ssi.pending = NULL; 732 od->ssi.pending = NULL;
733 od->ssi.timestamp = (time_t)0; 733 od->ssi.timestamp = (time_t)0;
734 } 734 }
735 735
736 /** 736 /**
737 * This "cleans" the ssi list. It does the following: 737 * Look up the given TLV type in the item's data. If the value of
738 * 1) Makes sure all buddies, permits, and denies have names. 738 * the TLV is not a valid UTF-8 string then use purple_utf8_salvage()
739 * 2) Makes sure that all buddies are in a group that exist. 739 * to replace invalid bytes with question marks.
740 * 3) Deletes any empty groups 740 */
741 static void cleanlist_ensure_utf8_data(struct aim_ssi_item *item, guint16 tlvtype)
742 {
743 aim_tlv_t *tlv;
744 gchar *value, *salvaged;
745
746 tlv = aim_tlv_gettlv(item->data, tlvtype, 1);
747 if (tlv && tlv->length && !g_utf8_validate((const gchar *)tlv->value, tlv->length, NULL)) {
748 purple_debug_warning("oscar", "cleanlist found invalid UTF-8 "
749 "for 0x%04hx field of 0x%04hx item with name %s. "
750 "Attempting to repair.\n",
751 tlvtype, item->type, item->name ? item->name : "(null)");
752 value = g_strndup((const gchar *)tlv->value, tlv->length);
753 salvaged = purple_utf8_salvage(value);
754 g_free(value);
755 if (*salvaged)
756 aim_tlvlist_replace_str(&item->data, tlvtype, salvaged);
757 else
758 aim_tlvlist_remove(&item->data, tlvtype);
759 g_free(salvaged);
760 }
761 }
762
763 /**
764 * This "cleans" the ssi list. It does things like:
765 * - Makes sure all buddies, permits, and denies have names
766 * - Makes sure all buddies are in a group that exist
767 * - Makes sure strings are valid UTF-8
741 * 768 *
742 * @param od The oscar odion. 769 * @param od The oscar odion.
743 * @return Return 0 if no errors, otherwise return the error number. 770 * @return Return 0 if no errors, otherwise return the error number.
744 */ 771 */
745 int aim_ssi_cleanlist(OscarData *od) 772 int aim_ssi_cleanlist(OscarData *od)
790 { 817 {
791 aim_ssi_itemlist_del(&od->ssi.local, cur2); 818 aim_ssi_itemlist_del(&od->ssi.local, cur2);
792 } 819 }
793 cur2 = next2; 820 cur2 = next2;
794 } 821 }
822
823 /* Make sure alias is valid UTF-8 */
824 cleanlist_ensure_utf8_data(cur, 0x0131);
825
826 /* Make sure comment is valid UTF-8 */
827 cleanlist_ensure_utf8_data(cur, 0x013c);
795 } 828 }
796 cur = cur->next; 829 cur = cur->next;
797 } 830 }
798 831
799 /* If we've made any changes then sync our list with the server's */ 832 /* If we've made any changes then sync our list with the server's */