comparison libpurple/protocols/bonjour/jabber.c @ 26766:9331016df8ac

Use more efficient purple_find_buddies in bonjour.
author Paul Aurich <paul@darkrain42.org>
date Fri, 01 May 2009 16:25:56 +0000
parents 2b7604ede0e4
children d078048fb03a
comparison
equal deleted inserted replaced
26765:998f471bb801 26766:9331016df8ac
231 } 231 }
232 232
233 struct _match_buddies_by_address_t { 233 struct _match_buddies_by_address_t {
234 const char *address; 234 const char *address;
235 GSList *matched_buddies; 235 GSList *matched_buddies;
236 BonjourJabber *jdata;
237 }; 236 };
238 237
239 static void 238 static void
240 _match_buddies_by_address(gpointer value, gpointer data) 239 _match_buddies_by_address(gpointer value, gpointer data)
241 { 240 {
242 PurpleBuddy *pb = value; 241 PurpleBuddy *pb = value;
243 PurpleAccount *account = NULL;
244 BonjourBuddy *bb = NULL; 242 BonjourBuddy *bb = NULL;
245 struct _match_buddies_by_address_t *mbba = data; 243 struct _match_buddies_by_address_t *mbba = data;
246 244
247 account = purple_buddy_get_account(pb);
248 bb = purple_buddy_get_protocol_data(pb); 245 bb = purple_buddy_get_protocol_data(pb);
249 246
250 /* 247 /*
251 * If the current PurpleBuddy's data is not null and the PurpleBuddy's account 248 * If the current PurpleBuddy's data is not null, then continue to determine
252 * is the same as the account requesting the check then continue to determine
253 * whether one of the buddies IPs matches the target IP. 249 * whether one of the buddies IPs matches the target IP.
254 */ 250 */
255 if (mbba->jdata->account == account && bb != NULL) 251 if (bb != NULL)
256 { 252 {
257 const char *ip; 253 const char *ip;
258 GSList *tmp = bb->ips; 254 GSList *tmp = bb->ips;
259 255
260 while(tmp) { 256 while(tmp) {
656 /* Look for the buddy that has opened the conversation and fill information */ 652 /* Look for the buddy that has opened the conversation and fill information */
657 address_text = inet_ntoa(their_addr.sin_addr); 653 address_text = inet_ntoa(their_addr.sin_addr);
658 purple_debug_info("bonjour", "Received incoming connection from %s.\n", address_text); 654 purple_debug_info("bonjour", "Received incoming connection from %s.\n", address_text);
659 mbba = g_new0(struct _match_buddies_by_address_t, 1); 655 mbba = g_new0(struct _match_buddies_by_address_t, 1);
660 mbba->address = address_text; 656 mbba->address = address_text;
661 mbba->jdata = jdata; 657
662 658 buddies = purple_find_buddies(jdata->account, NULL);
663 buddies = purple_blist_get_buddies();
664 g_slist_foreach(buddies, _match_buddies_by_address, mbba); 659 g_slist_foreach(buddies, _match_buddies_by_address, mbba);
665 g_slist_free(buddies); 660 g_slist_free(buddies);
666 661
667 if (mbba->matched_buddies == NULL) { 662 if (mbba->matched_buddies == NULL) {
668 purple_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n"); 663 purple_debug_info("bonjour", "We don't like invisible buddies, this is not a superheros comic\n");
669 g_slist_free(mbba->matched_buddies);
670 g_free(mbba); 664 g_free(mbba);
671 close(client_socket); 665 close(client_socket);
672 return; 666 return;
673 } 667 }
674 668
856 struct _match_buddies_by_address_t *mbba; 850 struct _match_buddies_by_address_t *mbba;
857 GSList *buddies; 851 GSList *buddies;
858 852
859 mbba = g_new0(struct _match_buddies_by_address_t, 1); 853 mbba = g_new0(struct _match_buddies_by_address_t, 1);
860 mbba->address = bconv->ip; 854 mbba->address = bconv->ip;
861 mbba->jdata = jdata; 855
862 856 buddies = purple_find_buddies(jdata->account, NULL);
863 buddies = purple_blist_get_buddies();
864 g_slist_foreach(buddies, _match_buddies_by_address, mbba); 857 g_slist_foreach(buddies, _match_buddies_by_address, mbba);
865 g_slist_free(buddies); 858 g_slist_free(buddies);
866 859
867 /* If there is exactly one match, use it */ 860 /* If there is exactly one match, use it */
868 if(mbba->matched_buddies != NULL) { 861 if(mbba->matched_buddies != NULL) {