changeset 7322:ab828b8c3f22

[gaim-migrate @ 7908] all sorts of stuff including tweaks to logging so it mostly works again for jabber. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 24 Oct 2003 05:46:01 +0000
parents c41e522028f2
children 443fc7d6fbff
files src/gtkconv.c src/log.c src/protocols/jabber/chat.c src/protocols/jabber/jabber.c src/protocols/jabber/jutil.c src/protocols/jabber/jutil.h src/protocols/jabber/presence.c src/protocols/msn/msn.c src/protocols/zephyr/zephyr.c src/prpl.h src/server.c src/util.c
diffstat 12 files changed, 60 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/gtkconv.c	Fri Oct 24 05:46:01 2003 +0000
@@ -4027,7 +4027,8 @@
 			FILE *fd;
 			char filename[256];
 
-			g_snprintf(filename, sizeof(filename), "%s%s", name,
+			g_snprintf(filename, sizeof(filename), "%s%s",
+					gaim_normalize(gaim_conversation_get_account(conv),name),
 					   (conv_type == GAIM_CONV_CHAT ? ".chat" : ""));
 
 			fd = open_log_file(filename, (conv_type == GAIM_CONV_CHAT));
@@ -4520,17 +4521,20 @@
 
 			char *t1;
 			char nm[256];
+			const char *nm2;
 
 			if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html"))
 				t1 = gaim_markup_strip_html(buf);
 			else
 				t1 = buf;
 
+			nm2 = gaim_normalize(gaim_conversation_get_account(conv),
+					gaim_conversation_get_name(conv));
+
 			if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
-				g_snprintf(nm, sizeof(nm), "%s.chat",
-						   gaim_conversation_get_name(conv));
+				g_snprintf(nm, sizeof(nm), "%s.chat", nm2);
 			else
-				strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm));
+				strncpy(nm, nm2, sizeof(nm));
 
 			fd = open_log_file(nm,
 				(gaim_conversation_get_type(conv) == GAIM_CONV_CHAT));
@@ -4689,12 +4693,15 @@
 		if (gaim_conversation_is_logging(conv)) {
 			char *t1, *t2;
 			char nm[256];
+			const char *nm2;
+
+			nm2 = gaim_normalize(gaim_conversation_get_account(conv),
+					gaim_conversation_get_name(conv));
 
 			if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
-				g_snprintf(nm, sizeof(nm), "%s.chat",
-						   gaim_conversation_get_name(conv));
+				g_snprintf(nm, sizeof(nm), "%s.chat", nm2);
 			else
-				strncpy(nm, gaim_conversation_get_name(conv), sizeof(nm));
+				strncpy(nm, nm2, sizeof(nm));
 
 			if (gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) {
 				t1 = gaim_markup_strip_html(buf);
--- a/src/log.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/log.c	Fri Oct 24 05:46:01 2003 +0000
@@ -215,7 +215,7 @@
 		return fd;
 	}
 
-	g_snprintf(realname, sizeof(realname), "%s.log", gaim_normalize(NULL, name));
+	g_snprintf(realname, sizeof(realname), "%s.log", name);
 	fd = open_gaim_log_file(realname, &flag);
 
 	if (fd && flag) {	/* is a new file */
--- a/src/protocols/jabber/chat.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/protocols/jabber/chat.c	Fri Oct 24 05:46:01 2003 +0000
@@ -69,7 +69,7 @@
 
 	room_jid = g_strdup_printf("%s@%s", room, server);
 
-	chat = g_hash_table_lookup(js->chats, jabber_normalize(room_jid));
+	chat = g_hash_table_lookup(js->chats, jabber_normalize(NULL, room_jid));
 	g_free(room_jid);
 
 	return chat;
@@ -147,8 +147,6 @@
 
 	chat = jabber_chat_find_by_id(js, id);
 
-	/* TODO: we get real Jabber IDs from MUC sometimes, we need to cache
-	 * them eventually */
 	full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, who);
 
 	jabber_message_send_im(gc, full_jid, message, 0);
@@ -194,7 +192,7 @@
 		return;
 
 	tmp = g_strdup_printf("%s@%s", room, server);
-	room_jid = g_strdup(jabber_normalize(tmp));
+	room_jid = g_strdup(jabber_normalize(NULL, tmp));
 	g_free(tmp);
 
 	chat = g_new0(JabberChat, 1);
@@ -248,7 +246,7 @@
 	JabberStream *js = chat->js;
 	char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
 
-	g_hash_table_remove(js->chats, jabber_normalize(room_jid));
+	g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid));
 	g_free(room_jid);
 
 	g_free(chat->room);
--- a/src/protocols/jabber/jabber.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/protocols/jabber/jabber.c	Fri Oct 24 05:46:01 2003 +0000
@@ -361,6 +361,7 @@
 	js->chats = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, NULL);
 	js->user = jabber_id_new(gaim_account_get_username(account));
+	js->next_id = g_random_int();
 
 	if(!js->user) {
 		gaim_connection_error(gc, _("Invalid Jabber ID"));
@@ -654,6 +655,7 @@
 	js->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, NULL);
 	js->user = jabber_id_new(gaim_account_get_username(account));
+	js->next_id = g_random_int();
 
 	if(!js->user) {
 		gaim_connection_error(gc, _("Invalid Jabber ID"));
@@ -762,7 +764,7 @@
 
 char *jabber_get_next_id(JabberStream *js)
 {
-	return g_strdup_printf("gaim%d", js->next_id++);
+	return g_strdup_printf("gaim%x", js->next_id++);
 }
 
 void jabber_idle_set(GaimConnection *gc, int idle)
--- a/src/protocols/jabber/jutil.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/protocols/jabber/jutil.c	Fri Oct 24 05:46:01 2003 +0000
@@ -21,6 +21,7 @@
 #include "internal.h"
 #include "server.h"
 
+#include "chat.h"
 #include "presence.h"
 #include "jutil.h"
 
@@ -260,24 +261,33 @@
 	if(!jid)
 		return NULL;
 
-	out = g_strdup_printf("%s@%s", jid->node, jid->domain);
+	out = g_strdup_printf("%s%s%s", jid->node ? jid->node : "",
+			jid->node ? "@" : "", jid->domain);
 	jabber_id_free(jid);
 
 	return out;
 }
 
-const char *jabber_normalize(const char *in)
+const char *jabber_normalize(const GaimAccount *account, const char *in)
 {
-	static char buf[2048]; /* maximum legal length of a jabber jid */
-	char *tmp;
+	GaimConnection *gc = account ? account->gc : NULL;
+	JabberStream *js = gc ? gc->proto_data : NULL;
+	static char buf[3072]; /* maximum legal length of a jabber jid */
+	JabberID *jid;
 
-	tmp = jabber_get_bare_jid(in);
+	jid = jabber_id_new(in);
 
-	if(!tmp)
+	if(!jid)
 		return NULL;
 
-	g_snprintf(buf, sizeof(buf), "%s", tmp);
-	g_free(tmp);
+	if(js && jid->node && jid->resource &&
+			jabber_chat_find(js, jid->node, jid->domain))
+		g_snprintf(buf, sizeof(buf), "%s@%s/%s", jid->node, jid->domain,
+				jid->resource);
+	else
+		g_snprintf(buf, sizeof(buf), "%s%s%s", jid->node ? jid->node : "",
+				jid->node ? "@" : "", jid->domain);
+
 	return buf;
 }
 
--- a/src/protocols/jabber/jutil.h	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/protocols/jabber/jutil.h	Fri Oct 24 05:46:01 2003 +0000
@@ -40,7 +40,7 @@
 time_t str_to_time(const char *timestamp);
 const char *jabber_get_state_string(int state);
 
-const char *jabber_normalize(const char *in);
+const char *jabber_normalize(const GaimAccount *account, const char *in);
 
 gboolean jabber_nodeprep_validate(const char *);
 gboolean jabber_nameprep_validate(const char *);
--- a/src/protocols/jabber/presence.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/protocols/jabber/presence.c	Fri Oct 24 05:46:01 2003 +0000
@@ -236,7 +236,7 @@
 	}
 
 
-	if((chat = jabber_chat_find(js, jid->node, jid->domain))) {
+	if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) {
 		static int i = 0;
 		char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain);
 
@@ -305,7 +305,8 @@
 			return;
 		}
 
-		buddy_name = g_strdup_printf("%s@%s", jid->node, jid->domain);
+		buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "",
+				jid->node ? "@" : "", jid->domain);
 		if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) {
 			jabber_id_free(jid);
 			g_free(buddy_name);
--- a/src/protocols/msn/msn.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/protocols/msn/msn.c	Fri Oct 24 05:46:01 2003 +0000
@@ -36,7 +36,7 @@
 
 static GaimPlugin *my_protocol = NULL;
 
-static const char *msn_normalize(const char *str);
+static const char *msn_normalize(const GaimAccount *account, const char *str);
 
 typedef struct
 {
@@ -481,7 +481,7 @@
 	gaim_connection_update_progress(gc, _("Connecting"), 0, MSN_CONNECT_STEPS);
 
 	/* Hmm, I don't like this. */
-	username = msn_normalize(gaim_account_get_username(account));
+	username = msn_normalize(account, gaim_account_get_username(account));
 
 	if (strcmp(username, gaim_account_get_username(account)))
 		gaim_account_set_username(account, username);
@@ -674,7 +674,7 @@
 	char outparams[MSN_BUF_LEN];
 	GSList *l;
 
-	who = msn_normalize(name);
+	who = msn_normalize(gc->account, name);
 
 	if (strchr(who, ' ')) {
 		/* This is a broken blist entry. */
@@ -1207,7 +1207,7 @@
 }
 
 static const char *
-msn_normalize(const char *str)
+msn_normalize(const GaimAccount *account, const char *str)
 {
 	static char buf[BUF_LEN];
 
--- a/src/protocols/zephyr/zephyr.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/protocols/zephyr/zephyr.c	Fri Oct 24 05:46:01 2003 +0000
@@ -71,7 +71,7 @@
 					return;\
 				}
 
-static const char *zephyr_normalize(const char *);
+static const char *zephyr_normalize(const GaimAccount *, const char *);
 
 /* this is so bad, and if Zephyr weren't so fucked up to begin with I
  * wouldn't do this. but it is so i will. */
@@ -307,7 +307,7 @@
 {
 	GList *curr;
 	for (curr = pending_zloc_names; curr != NULL; curr = curr->next) {
-		if (!g_ascii_strcasecmp(zephyr_normalize(who), (char*)curr->data)) {
+		if (!g_ascii_strcasecmp(zephyr_normalize(NULL, who), (char*)curr->data)) {
 			g_free((char*)curr->data);
 			pending_zloc_names = g_list_remove(pending_zloc_names, curr->data);
 			return TRUE;
@@ -466,7 +466,7 @@
 					continue;
 				if(b->account->gc == zgc) {
 					const char *chk;
-					chk = zephyr_normalize(b->name);
+					chk = zephyr_normalize(b->account, b->name);
 					/* doesn't matter if this fails or not; we'll just move on to the next one */
 					ZRequestLocations(chk, &ald, UNACKED, ZAUTH);
 					free(ald.user);
@@ -783,9 +783,9 @@
 	notice.z_class = zt->class;
 	notice.z_class_inst = zt->instance;
 	if (!g_ascii_strcasecmp(zt->recipient, "*"))
-		notice.z_recipient = zephyr_normalize("");
+		notice.z_recipient = zephyr_normalize(gc->account, "");
 	else
-		notice.z_recipient = zephyr_normalize(zt->recipient);
+		notice.z_recipient = zephyr_normalize(gc->account, zt->recipient);
 	notice.z_sender = 0;
 	notice.z_default_format =
 		"Class $class, Instance $instance:\n"
@@ -832,7 +832,7 @@
 	return 1;
 }
 
-static const char *zephyr_normalize(const char *orig)
+static const char *zephyr_normalize(const GaimAccount *account,const char *orig)
 {
 	static char buf[80];
 	if (!g_ascii_strcasecmp(orig, "")) {
@@ -851,12 +851,12 @@
 {
 	ZAsyncLocateData_t ald;
 
-	if (ZRequestLocations(zephyr_normalize(who), &ald, UNACKED, ZAUTH)
+	if (ZRequestLocations(zephyr_normalize(gc->account, who), &ald, UNACKED, ZAUTH)
 					!= ZERR_NONE) {
 		return;
 	}
 	pending_zloc_names = g_list_append(pending_zloc_names,
-					g_strdup(zephyr_normalize(who)));
+					g_strdup(zephyr_normalize(gc->account, who)));
 }
 
 static GList *zephyr_buddy_menu(GaimConnection *gc, const char *who)
--- a/src/prpl.h	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/prpl.h	Fri Oct 24 05:46:01 2003 +0000
@@ -306,7 +306,7 @@
 
 	void (*convo_closed)(GaimConnection *, const char *who);
 
-	const char *(*normalize)(const char *);
+	const char *(*normalize)(const GaimAccount *, const char *);
 
 	void (*set_buddy_icon)(GaimConnection *, const char *filename);
 
--- a/src/server.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/server.c	Fri Oct 24 05:46:01 2003 +0000
@@ -1370,7 +1370,9 @@
 		char *filename;
 
 		filename = (char *)malloc(100);
-		g_snprintf(filename, 100, "%s.chat", gaim_conversation_get_name(conv));
+		g_snprintf(filename, 100, "%s.chat",
+				gaim_normalize(gaim_conversation_get_account(conv),
+					gaim_conversation_get_name(conv)));
 
 		fd = open_log_file(filename, TRUE);
 
--- a/src/util.c	Thu Oct 23 21:56:16 2003 +0000
+++ b/src/util.c	Fri Oct 24 05:46:01 2003 +0000
@@ -1309,7 +1309,7 @@
 		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
 
 	if(prpl_info && prpl_info->normalize) {
-		return prpl_info->normalize(s);
+		return prpl_info->normalize(account, s);
 	} else {
 		static char buf[BUF_LEN];
 		char *tmp;