changeset 9912:f6a1054e2bdc

[gaim-migrate @ 10804] " shadow pointed that zephyr_strip_foreign_realm wasn't being consistently used (searches for foo would fail when foo@DEFAULTREALM was in the buddy list), and that this could cause problems. Also, zephyr_strip_foreign_realm was really badly named (it should be zephyr_strip_local_realm). Here's a fix for both those issues, against current cvs." --Arun A Tharuvai committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 30 Aug 2004 01:52:59 +0000
parents 4f1fcf5efaf9
children 0056843d512c
files src/protocols/zephyr/zephyr.c
diffstat 1 files changed, 25 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/zephyr/zephyr.c	Mon Aug 30 01:41:24 2004 +0000
+++ b/src/protocols/zephyr/zephyr.c	Mon Aug 30 01:52:59 2004 +0000
@@ -171,7 +171,7 @@
 static void zephyr_chat_set_topic(GaimConnection * gc, int id, const char *topic);
 char* zephyr_tzc_deescape_str(const char *message);
 
-char *zephyr_strip_foreign_realm(zephyr_account* zephyr,const char* user){
+char *zephyr_strip_local_realm(zephyr_account* zephyr,const char* user){
 	/*
 	  Takes in a username of the form username or username@realm 
 	  and returns:
@@ -696,12 +696,9 @@
 				return;
 
 			if ((b = gaim_find_buddy(gc->account, user)) == NULL) {
-				char *e = strchr(user, '@');
-
-				if (e && !g_ascii_strcasecmp(e + 1, zephyr->realm)) {
-					*e = '\0';
-				}
-				b = gaim_find_buddy(gc->account, user);
+                                char* stripped_user = zephyr_strip_local_realm(zephyr,user);
+                                b = gaim_find_buddy(gc->account,stripped_user);
+                                g_free(stripped_user);
 			}
 			if ((b && pending_zloc(zephyr,b->name)) || pending_zloc(zephyr,user)) {
 				ZLocations_t locs;
@@ -767,7 +764,7 @@
 			gchar* stripped_sender;
 			if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:"))
 				flags |= GAIM_CONV_IM_AUTO_RESP;
-			stripped_sender = zephyr_strip_foreign_realm(zephyr,notice.z_sender);
+			stripped_sender = zephyr_strip_local_realm(zephyr,notice.z_sender);
 			
 			if (!g_ascii_strcasecmp(notice.z_opcode,"PING"))
 				serv_got_typing(gc,stripped_sender,ZEPHYR_TYPING_RECV_TIMEOUT, GAIM_TYPING);
@@ -839,19 +836,19 @@
 			g_free(sendertmp); /* fix memory leak? */
 			/* If the person is in the default Realm, then strip the 
 			   Realm from the sender field */
-			sendertmp = zephyr_strip_foreign_realm(zephyr,notice.z_sender);
+			sendertmp = zephyr_strip_local_realm(zephyr,notice.z_sender);
 			send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst);					
 			send_inst_utf8 = zephyr_recv_convert(gc,send_inst, strlen(send_inst));
 			if (!send_inst_utf8) {
 				gaim_debug(GAIM_DEBUG_ERROR, "zephyr","send_inst %s became null\n", send_inst);
 				send_inst_utf8 = "malformed instance";
 			}
-				
+
 			serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL));
 			g_free(send_inst);
 			gconv1 = gaim_find_conversation_with_account(zt2->name, gc->account);
 			gcc = gaim_conversation_get_chat_data(gconv1);
-				
+
 			if (!gaim_conv_chat_find_user(gcc, sendertmp)) {
 				/* force interpretation in network byte order */
 				unsigned char *addrs = (unsigned char *)&(notice.z_sender_addr.s_addr);
@@ -1097,22 +1094,17 @@
 				char *user; 
 				GaimBuddy *b;
 				int nlocs = 0;
-                                parse_tree *locations;
-                                gchar *locval;
+				parse_tree *locations;
+				gchar *locval;
 				user = tree_child(find_node(newparsetree,"user"),2)->contents;
 
 				if ((b = gaim_find_buddy(gc->account, user)) == NULL) {
-					char *e = strchr(user, '@');
-
-					if (e && !g_ascii_strcasecmp(e + 1, zephyr->realm)) {
-						*e = '\0';
-					}
-					b = gaim_find_buddy(gc->account, user);
+                                        gchar *stripped_user = zephyr_strip_local_realm(zephyr,user);
+					b = gaim_find_buddy(gc->account, stripped_user);
+                                        g_free(stripped_user);
 				}
-
 				locations = find_node(newparsetree,"locations");
 				locval = tree_child(tree_child(tree_child(tree_child(locations,2),0),0),2)->contents;
-                                /*				fprintf(stderr,"locval: %s %d\n",locval,strlen(locval)); */
 
 				if (!locval || !g_ascii_strcasecmp(locval," ") || (strlen(locval) == 0)) {
 					nlocs = 0;
@@ -1424,8 +1416,13 @@
 			strip_comments(buff);
 			if (buff[0]) {
 				if (!(b = gaim_find_buddy(gc->account, buff))) {
-					b = gaim_buddy_new(gc->account, buff, NULL);
-					gaim_blist_add_buddy(b, NULL, g, NULL);
+                                        char *stripped_user = zephyr_strip_local_realm(gc->proto_data,buff);
+                                        gaim_debug_info("zephyr","stripped_user %s\n",stripped_user);
+                                        if (!(b = gaim_find_buddy(gc->account,stripped_user))){
+                                                b = gaim_buddy_new(gc->account, stripped_user, NULL);
+                                                gaim_blist_add_buddy(b, NULL, g, NULL);
+                                        } 
+                                        g_free(stripped_user);
 				}
 			}
 		}
@@ -1777,7 +1774,7 @@
 {
 	GaimBlistNode *gnode, *cnode, *bnode;
 	GaimBuddy *b;
-	char *ptr, *fname, *ptr2;
+	char *fname;
 	FILE *fd;
 	zephyr_account* zephyr = gc->proto_data;
 	fname = g_strdup_printf("%s/.anyone", gaim_home_dir());
@@ -1798,18 +1795,9 @@
 					continue;
 				b = (GaimBuddy *) bnode;
 				if (b->account == gc->account) {
-					if ((ptr = strchr(b->name, '@')) != NULL) {
-						ptr2 = ptr + 1;
-						/* We should only strip the realm name if the principal
-						   is in the user's realm
-						*/
-						if (!g_ascii_strcasecmp(ptr2, zephyr->realm)) {
-							*ptr = '\0';
-						}
-					}
-					fprintf(fd, "%s\n", b->name);
-					if (ptr)
-						*ptr = '@';
+                                        gchar *stripped_user = zephyr_strip_local_realm(zephyr,b->name);
+					fprintf(fd, "%s\n", stripped_user);
+                                        g_free(stripped_user);
 				}
 			}
 		}
@@ -2075,7 +2063,7 @@
 char *local_zephyr_normalize(zephyr_account *zephyr,const char *orig)
 {
 	/* 
-	   Basically the inverse of zephyr_strip_foreign_realm 
+	   Basically the inverse of zephyr_strip_local_realm 
 	*/	
 	char* buf;