Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/roster.c @ 27568:ff099a916d6b
Use jabber_is_own_account and perform way fewer normalizations per iteration
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 06 Jun 2009 22:38:15 +0000 |
parents | 7c864f388c96 |
children | 65b5bc543214 |
comparison
equal
deleted
inserted
replaced
27140:c96a7d9361bb | 27568:ff099a916d6b |
---|---|
147 | 147 |
148 void jabber_roster_parse(JabberStream *js, const char *from, | 148 void jabber_roster_parse(JabberStream *js, const char *from, |
149 JabberIqType type, const char *id, xmlnode *query) | 149 JabberIqType type, const char *id, xmlnode *query) |
150 { | 150 { |
151 xmlnode *item, *group; | 151 xmlnode *item, *group; |
152 | 152 gchar *own_jid; |
153 if(from) { | 153 |
154 char *from_norm; | 154 if (!jabber_is_own_account(js, from)) { |
155 gboolean invalid; | 155 purple_debug_warning("jabber", "Received bogon roster push from %s\n", |
156 | 156 from); |
157 from_norm = g_strdup(jabber_normalize(js->gc->account, from)); | 157 return; |
158 | |
159 if(!from_norm) | |
160 return; | |
161 | |
162 invalid = g_utf8_collate(from_norm, | |
163 jabber_normalize(js->gc->account, | |
164 purple_account_get_username(js->gc->account))); | |
165 | |
166 g_free(from_norm); | |
167 | |
168 if(invalid) | |
169 return; | |
170 } | 158 } |
171 | 159 |
172 js->currently_parsing_roster_push = TRUE; | 160 js->currently_parsing_roster_push = TRUE; |
161 | |
162 own_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
173 | 163 |
174 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) | 164 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) |
175 { | 165 { |
176 const char *jid, *name, *subscription, *ask; | 166 const char *jid, *name, *subscription, *ask; |
177 JabberBuddy *jb; | 167 JabberBuddy *jb; |
186 | 176 |
187 if(!(jb = jabber_buddy_find(js, jid, TRUE))) | 177 if(!(jb = jabber_buddy_find(js, jid, TRUE))) |
188 continue; | 178 continue; |
189 | 179 |
190 if(subscription) { | 180 if(subscription) { |
191 gint me = -1; | 181 gboolean me = FALSE; |
192 char *jid_norm; | 182 |
193 const char *username; | 183 me = g_str_equal(own_jid, jabber_normalize(js->gc->account, jid)); |
194 | 184 |
195 jid_norm = g_strdup(jabber_normalize(js->gc->account, jid)); | 185 if(me) |
196 username = purple_account_get_username(js->gc->account); | |
197 me = g_utf8_collate(jid_norm, | |
198 jabber_normalize(js->gc->account, | |
199 username)); | |
200 g_free(jid_norm); | |
201 | |
202 if(me == 0) | |
203 jb->subscription = JABBER_SUB_BOTH; | 186 jb->subscription = JABBER_SUB_BOTH; |
204 else if(!strcmp(subscription, "none")) | 187 else if(!strcmp(subscription, "none")) |
205 jb->subscription = JABBER_SUB_NONE; | 188 jb->subscription = JABBER_SUB_NONE; |
206 else if(!strcmp(subscription, "to")) | 189 else if(!strcmp(subscription, "to")) |
207 jb->subscription = JABBER_SUB_TO; | 190 jb->subscription = JABBER_SUB_TO; |
251 } | 234 } |
252 add_purple_buddies_to_groups(js, jid, name, groups); | 235 add_purple_buddies_to_groups(js, jid, name, groups); |
253 } | 236 } |
254 } | 237 } |
255 | 238 |
239 g_free(own_jid); | |
256 js->currently_parsing_roster_push = FALSE; | 240 js->currently_parsing_roster_push = FALSE; |
257 | 241 |
258 /* if we're just now parsing the roster for the first time, | 242 /* if we're just now parsing the roster for the first time, |
259 * then now would be the time to declare ourselves connected and | 243 * then now would be the time to declare ourselves connected and |
260 * send our initial presence */ | 244 * send our initial presence */ |