Mercurial > pidgin
comparison src/protocols/jabber/buddy.c @ 7116:6c8706109f92
[gaim-migrate @ 7683]
fix a big ugly memleak on jabber account signoff, fix the img display in vcards until the gtk code can be talked into understanding proper XHTML, and a few misc other things I felt like getting out of my tree.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 02 Oct 2003 01:58:26 +0000 |
parents | 6faeeecab0dc |
children | 0e4894b3e2a6 |
comparison
equal
deleted
inserted
replaced
7115:7bee4be16385 | 7116:6c8706109f92 |
---|---|
31 #include "jabber.h" | 31 #include "jabber.h" |
32 #include "iq.h" | 32 #include "iq.h" |
33 #include "presence.h" | 33 #include "presence.h" |
34 #include "xmlnode.h" | 34 #include "xmlnode.h" |
35 | 35 |
36 | |
37 void jabber_buddy_free(JabberBuddy *jb) | |
38 { | |
39 g_return_if_fail(jb != NULL); | |
40 | |
41 if(jb->error_msg) | |
42 g_free(jb->error_msg); | |
43 while(jb->resources) | |
44 jabber_buddy_resource_free(jb->resources->data); | |
45 | |
46 g_free(jb); | |
47 } | |
36 | 48 |
37 JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name, | 49 JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name, |
38 gboolean create) | 50 gboolean create) |
39 { | 51 { |
40 JabberBuddy *jb; | 52 JabberBuddy *jb; |
95 { | 107 { |
96 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | 108 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); |
97 | 109 |
98 if(!jbr) { | 110 if(!jbr) { |
99 jbr = g_new0(JabberBuddyResource, 1); | 111 jbr = g_new0(JabberBuddyResource, 1); |
112 jbr->jb = jb; | |
100 jbr->name = g_strdup(resource); | 113 jbr->name = g_strdup(resource); |
101 jbr->capabilities = JABBER_CAP_XHTML; | 114 jbr->capabilities = JABBER_CAP_XHTML; |
102 jb->resources = g_list_append(jb->resources, jbr); | 115 jb->resources = g_list_append(jb->resources, jbr); |
103 } | 116 } |
104 jbr->priority = priority; | 117 jbr->priority = priority; |
106 if(jbr->status) | 119 if(jbr->status) |
107 g_free(jbr->status); | 120 g_free(jbr->status); |
108 jbr->status = g_strdup(status); | 121 jbr->status = g_strdup(status); |
109 } | 122 } |
110 | 123 |
111 void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource) | 124 void jabber_buddy_resource_free(JabberBuddyResource *jbr) |
112 { | 125 { |
113 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | 126 g_return_if_fail(jbr != NULL); |
114 | 127 |
115 if(!jbr) | 128 jbr->jb->resources = g_list_remove(jbr->jb->resources, jbr); |
116 return; | |
117 | |
118 jb->resources = g_list_remove(jb->resources, jbr); | |
119 | 129 |
120 g_free(jbr->name); | 130 g_free(jbr->name); |
121 if(jbr->status) | 131 if(jbr->status) |
122 g_free(jbr->status); | 132 g_free(jbr->status); |
123 g_free(jbr); | 133 g_free(jbr); |
134 } | |
135 | |
136 void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource) | |
137 { | |
138 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
139 | |
140 if(!jbr) | |
141 return; | |
142 | |
143 jabber_buddy_resource_free(jbr); | |
124 } | 144 } |
125 | 145 |
126 const char *jabber_buddy_get_status_msg(JabberBuddy *jb) | 146 const char *jabber_buddy_get_status_msg(JabberBuddy *jb) |
127 { | 147 { |
128 JabberBuddyResource *jbr; | 148 JabberBuddyResource *jbr; |
522 xmlnode *vcard; | 542 xmlnode *vcard; |
523 | 543 |
524 if(!from) | 544 if(!from) |
525 return; | 545 return; |
526 | 546 |
547 /* XXX: make this handle handle errors */ | |
548 | |
527 resource_name = jabber_get_resource(from); | 549 resource_name = jabber_get_resource(from); |
528 | 550 |
529 jb = jabber_buddy_find(js, from, TRUE); | 551 jb = jabber_buddy_find(js, from, TRUE); |
530 info_text = g_string_new(""); | 552 info_text = g_string_new(""); |
531 | 553 |
723 if((text2 = xmlnode_get_data(child2))) { | 745 if((text2 = xmlnode_get_data(child2))) { |
724 gaim_base64_decode(text2, &data, &size); | 746 gaim_base64_decode(text2, &data, &size); |
725 | 747 |
726 imgid = gaim_imgstore_add(data, size, "logo.png"); | 748 imgid = gaim_imgstore_add(data, size, "logo.png"); |
727 g_string_append_printf(info_text, | 749 g_string_append_printf(info_text, |
728 "<b>%s:</b> <img id='%d' /><br/>", | 750 "<b>%s:</b> <img id='%d'><br/>", |
729 strcmp(child->name, "PHOTO") == 0 ? | 751 strcmp(child->name, "PHOTO") == 0 ? |
730 _("Photo") : _("Logo"), | 752 _("Photo") : _("Logo"), |
731 imgid); | 753 imgid); |
732 | 754 |
733 g_free(data); | 755 g_free(data); |