Package: irssi-plugin-xmpp / 0.53-1~bpo8+1

strip_resource_08082009.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
Description: strip resource string from jid
 gchat and others generate semi random character strings (eg:
 foobar@gmail.com/CSCF76A81E) as the resource id on some contacts.  That can
 change rather rapidly and all of the sudden one can wind up with several
 different query windows that really are all for the same contact.
Bug: http://gna.org/bugs/?18078

--- a/docs/GENERAL
+++ b/docs/GENERAL
@@ -149,6 +149,12 @@
     Creates a new window where the raw XML messages are displayed. Useful for
     debugging. (default: OFF)
 
+/SET xmpp_strip_resource ON/OFF
+    Removes resource part from jid at private message window. This is
+    handy for example when chatting with someone using Google talk,
+    because Google talk appends random string to resource thus opening
+    a new private window every time resource changes. (default: OFF)
+
 In "xmpp_proxy" section:
 
     See the "Proxy usage" section of this file.
--- a/src/core/protocol.c
+++ b/src/core/protocol.c
@@ -16,6 +16,7 @@
  */
 
 #include "module.h"
+#include "channels.h"
 #include "signals.h"
 #include "settings.h"
 
@@ -94,6 +95,19 @@
 {
 	LmMessageNode *node, *encrypted;
 	char *str, *subject;
+	const char *from_stripped;
+
+	/* assing from_stripped. If setting xmpp_strip_resource is
+	   True and from is not from a channel private message set
+	   from_stripped to same as from, but strip the
+	   resource. Otherwise just duplicate from to
+	   from_stripped. */
+	str = xmpp_strip_resource(from);
+	from_stripped =
+		((settings_get_bool("xmpp_strip_resource")) &&
+		 (channel_find(SERVER(server), str)) == NULL) ?
+		g_strdup(str) : g_strdup(from);
+	g_free(str);
 	
 	if ((type != LM_MESSAGE_SUB_TYPE_NOT_SET
 	    && type != LM_MESSAGE_SUB_TYPE_HEADLINE
@@ -106,7 +120,7 @@
 		str = xmpp_recode_in(node->value);
 		subject = g_strconcat("Subject: ", str, (void *)NULL);
 		g_free(str);
-		signal_emit("message private", 4, server, subject, from, from);
+		signal_emit("message private", 4, server, subject, from_stripped, from);
 		g_free(subject);
 	}
 
@@ -143,11 +157,11 @@
 	if(str) {
 		if (g_ascii_strncasecmp(str, "/me ", 4) == 0)
 			signal_emit("message xmpp action", 5,
-			    server, str+4, from, from,
+			    server, str+4, from_stripped, from,
 			    GINT_TO_POINTER(SEND_TARGET_NICK));
 		else
 			signal_emit("message private", 4, server,
-			    str, from, from);
+			    str, from_stripped, from);
 		g_free(str);
 	}
 }
--- a/src/core/xmpp-queries.c
+++ b/src/core/xmpp-queries.c
@@ -20,6 +20,7 @@
 #include "module.h"
 #include "channels.h"
 #include "nicklist.h"
+#include "settings.h"
 #include "signals.h"
 
 #include "xmpp-queries.h"
@@ -33,6 +34,7 @@
 	XMPP_SERVER_REC *server;
 	CHANNEL_REC *channel;
 	NICK_REC *nick;
+	char *str;
 	const char *channel_name;
 
 	g_return_val_if_fail(server_tag != NULL, NULL);
@@ -52,8 +54,23 @@
 				rec->name = g_strdup(nick->host);
 		}
 	}
+
 	if (rec->name == NULL)
 		rec->name = rosters_resolve_name(server, data);
+	if (settings_get_bool("xmpp_strip_resource")) {
+		if (rec->name != NULL) {
+			str = xmpp_strip_resource(rec->name);
+			g_free(rec->name);
+			rec->name = NULL;
+		} else {
+			str = xmpp_strip_resource(data);
+		}
+		/* if this not a private message from channel we are
+		   on, strip the resource */
+		if (channel_find(SERVER(server), str) == NULL)
+			rec->name = g_strdup(str);
+		g_free(str);
+	}
 	if (rec->name != NULL) {
 		/* test if the query already exist */
 		if ((rec_tmp = xmpp_query_find(server, rec->name)) != NULL) {
--- a/src/fe-common/fe-xmpp-queries.c
+++ b/src/fe-common/fe-xmpp-queries.c
@@ -21,10 +21,12 @@
 #include "printtext.h"
 #include "signals.h"
 #include "window-items.h"
+#include "settings.h"
 
 #include "xmpp-queries.h"
 #include "rosters-tools.h"
 #include "fe-xmpp-status.h"
+#include "tools.h"
 
 static void
 sig_presence_changed(XMPP_SERVER_REC *server, const char *full_jid,
@@ -32,26 +34,29 @@
 {
 	XMPP_QUERY_REC *rec;
 	XMPP_ROSTER_USER_REC *user;
-	const char *msg;
+	const char *msg, *stripped_jid;
 	char *name;
 
+	stripped_jid = (settings_get_bool("xmpp_strip_resource")) ?
+		xmpp_strip_resource(full_jid) : g_strdup(full_jid);
+
 	g_return_if_fail(server != NULL);
-	g_return_if_fail(full_jid != NULL);
+	g_return_if_fail(stripped_jid != NULL);
 	g_return_if_fail(0 <= show && show < XMPP_PRESENCE_SHOW_LEN);
-	if ((rec = xmpp_query_find(server, full_jid)) == NULL)
+	if ((rec = xmpp_query_find(server, stripped_jid)) == NULL)
 		return;
 	msg = fe_xmpp_presence_show[show];
-	user = rosters_find_user(server->roster, full_jid, NULL, NULL);
+	user = rosters_find_user(server->roster, stripped_jid, NULL, NULL);
 	name = user != NULL && user->name != NULL ?
 	    format_get_text(MODULE_NAME, NULL, server, NULL,
-		XMPPTXT_FORMAT_NAME, user->name, full_jid) :
+		XMPPTXT_FORMAT_NAME, user->name, stripped_jid) :
 	    format_get_text(MODULE_NAME, NULL, server, NULL,
-		XMPPTXT_FORMAT_JID, full_jid);
+		XMPPTXT_FORMAT_JID, stripped_jid);
 	if (status != NULL)
-		printformat_module(MODULE_NAME, server, full_jid, MSGLEVEL_CRAP,
+		printformat_module(MODULE_NAME, server, stripped_jid, MSGLEVEL_CRAP,
 		    XMPPTXT_PRESENCE_CHANGE_REASON, name, msg, status);
 	else
-		printformat_module(MODULE_NAME, server, full_jid, MSGLEVEL_CRAP,
+		printformat_module(MODULE_NAME, server, stripped_jid, MSGLEVEL_CRAP,
 		    XMPPTXT_PRESENCE_CHANGE, name, msg);
 }
 
--- a/src/fe-common/fe-xmpp-status.c
+++ b/src/fe-common/fe-xmpp-status.c
@@ -27,6 +27,7 @@
 
 #include "xmpp-servers.h"
 #include "rosters-tools.h"
+#include "tools.h"
 
 const char *fe_xmpp_presence_show[] = {
 	"Offline",
@@ -84,20 +85,23 @@
 {
 	XMPP_ROSTER_USER_REC *user;
 	WINDOW_REC *window;
-	const char *msg;
+	const char *msg, *stripped_jid;
 	char *name;
 
+	stripped_jid = (settings_get_bool("xmpp_strip_resource")) ?
+		xmpp_strip_resource(full_jid) : g_strdup(full_jid);
+
 	g_return_if_fail(IS_XMPP_SERVER(server));
-	g_return_if_fail(full_jid != NULL);
+	g_return_if_fail(stripped_jid != NULL);
 	g_return_if_fail(0 <= show && show < XMPP_PRESENCE_SHOW_LEN);	
 	window = fe_xmpp_status_get_window(server);
 	msg = fe_xmpp_presence_show[show];
-	user = rosters_find_user(server->roster, full_jid, NULL, NULL);
+	user = rosters_find_user(server->roster, stripped_jid, NULL, NULL);
 	name = user != NULL && user->name != NULL ?
 	    format_get_text(MODULE_NAME, NULL, server, NULL,
-		XMPPTXT_FORMAT_NAME, user->name, full_jid) :
+		XMPPTXT_FORMAT_NAME, user->name, stripped_jid) :
 	    format_get_text(MODULE_NAME, NULL, server, NULL,
-		XMPPTXT_FORMAT_JID, full_jid);
+		XMPPTXT_FORMAT_JID, stripped_jid);
 	if (status != NULL)
 		printformat_module_window(MODULE_NAME, window, MSGLEVEL_CRAP,
 		    XMPPTXT_PRESENCE_CHANGE_REASON, name, msg, status);
@@ -132,6 +136,8 @@
 
 	settings_add_bool("xmpp_lookandfeel", "xmpp_status_window", FALSE);
 
+	settings_add_bool("xmpp_lookandfeel", "xmpp_strip_resource", FALSE);
+
 	if (settings_get_bool("xmpp_status_window"))
 		signal_add("xmpp presence changed", sig_presence_changed);
 }