~ubuntu-branches/ubuntu/wily/irssi-plugin-xmpp/wily

« back to all changes in this revision

Viewing changes to debian/patches/strip_resource_08082009.patch

  • Committer: Package Import Robot
  • Author(s): Florian Schlichting
  • Date: 2015-03-27 21:44:52 UTC
  • Revision ID: package-import@ubuntu.com-20150327214452-fia86qdiv03fwee7
Tags: 0.52+git20140102-3
* Update XMPP-PGP support (closes: #779156)
* Add strip_resource_08082009.patch to optionally ignore random resource
  strings
* Bump Standards-Version to 3.9.6 (no changes necessary)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: strip resource string from jid
 
2
 gchat and others generate semi random character strings (eg:
 
3
 foobar@gmail.com/CSCF76A81E) as the resource id on some contacts.  That can
 
4
 change rather rapidly and all of the sudden one can wind up with several
 
5
 different query windows that really are all for the same contact.
 
6
Bug: http://gna.org/bugs/?18078
 
7
 
 
8
--- a/docs/GENERAL
 
9
+++ b/docs/GENERAL
 
10
@@ -149,6 +149,12 @@
 
11
     Creates a new window where the raw XML messages are displayed. Useful for
 
12
     debugging. (default: OFF)
 
13
 
 
14
+/SET xmpp_strip_resource ON/OFF
 
15
+    Removes resource part from jid at private message window. This is
 
16
+    handy for example when chatting with someone using Google talk,
 
17
+    because Google talk appends random string to resource thus opening
 
18
+    a new private window every time resource changes. (default: OFF)
 
19
+
 
20
 In "xmpp_proxy" section:
 
21
 
 
22
     See the "Proxy usage" section of this file.
 
23
--- a/src/core/protocol.c
 
24
+++ b/src/core/protocol.c
 
25
@@ -16,6 +16,7 @@
 
26
  */
 
27
 
 
28
 #include "module.h"
 
29
+#include "channels.h"
 
30
 #include "signals.h"
 
31
 #include "settings.h"
 
32
 
 
33
@@ -94,6 +95,19 @@
 
34
 {
 
35
        LmMessageNode *node, *encrypted;
 
36
        char *str, *subject;
 
37
+       const char *from_stripped;
 
38
+
 
39
+       /* assing from_stripped. If setting xmpp_strip_resource is
 
40
+          True and from is not from a channel private message set
 
41
+          from_stripped to same as from, but strip the
 
42
+          resource. Otherwise just duplicate from to
 
43
+          from_stripped. */
 
44
+       str = xmpp_strip_resource(from);
 
45
+       from_stripped =
 
46
+               ((settings_get_bool("xmpp_strip_resource")) &&
 
47
+                (channel_find(SERVER(server), str)) == NULL) ?
 
48
+               g_strdup(str) : g_strdup(from);
 
49
+       g_free(str);
 
50
        
 
51
        if ((type != LM_MESSAGE_SUB_TYPE_NOT_SET
 
52
            && type != LM_MESSAGE_SUB_TYPE_HEADLINE
 
53
@@ -106,7 +120,7 @@
 
54
                str = xmpp_recode_in(node->value);
 
55
                subject = g_strconcat("Subject: ", str, (void *)NULL);
 
56
                g_free(str);
 
57
-               signal_emit("message private", 4, server, subject, from, from);
 
58
+               signal_emit("message private", 4, server, subject, from_stripped, from);
 
59
                g_free(subject);
 
60
        }
 
61
 
 
62
@@ -143,11 +157,11 @@
 
63
        if(str) {
 
64
                if (g_ascii_strncasecmp(str, "/me ", 4) == 0)
 
65
                        signal_emit("message xmpp action", 5,
 
66
-                           server, str+4, from, from,
 
67
+                           server, str+4, from_stripped, from,
 
68
                            GINT_TO_POINTER(SEND_TARGET_NICK));
 
69
                else
 
70
                        signal_emit("message private", 4, server,
 
71
-                           str, from, from);
 
72
+                           str, from_stripped, from);
 
73
                g_free(str);
 
74
        }
 
75
 }
 
76
--- a/src/core/xmpp-queries.c
 
77
+++ b/src/core/xmpp-queries.c
 
78
@@ -20,6 +20,7 @@
 
79
 #include "module.h"
 
80
 #include "channels.h"
 
81
 #include "nicklist.h"
 
82
+#include "settings.h"
 
83
 #include "signals.h"
 
84
 
 
85
 #include "xmpp-queries.h"
 
86
@@ -33,6 +34,7 @@
 
87
        XMPP_SERVER_REC *server;
 
88
        CHANNEL_REC *channel;
 
89
        NICK_REC *nick;
 
90
+       char *str;
 
91
        const char *channel_name;
 
92
 
 
93
        g_return_val_if_fail(server_tag != NULL, NULL);
 
94
@@ -52,8 +54,23 @@
 
95
                                rec->name = g_strdup(nick->host);
 
96
                }
 
97
        }
 
98
+
 
99
        if (rec->name == NULL)
 
100
                rec->name = rosters_resolve_name(server, data);
 
101
+       if (settings_get_bool("xmpp_strip_resource")) {
 
102
+               if (rec->name != NULL) {
 
103
+                       str = xmpp_strip_resource(rec->name);
 
104
+                       g_free(rec->name);
 
105
+                       rec->name = NULL;
 
106
+               } else {
 
107
+                       str = xmpp_strip_resource(data);
 
108
+               }
 
109
+               /* if this not a private message from channel we are
 
110
+                  on, strip the resource */
 
111
+               if (channel_find(SERVER(server), str) == NULL)
 
112
+                       rec->name = g_strdup(str);
 
113
+               g_free(str);
 
114
+       }
 
115
        if (rec->name != NULL) {
 
116
                /* test if the query already exist */
 
117
                if ((rec_tmp = xmpp_query_find(server, rec->name)) != NULL) {
 
118
--- a/src/fe-common/fe-xmpp-queries.c
 
119
+++ b/src/fe-common/fe-xmpp-queries.c
 
120
@@ -21,10 +21,12 @@
 
121
 #include "printtext.h"
 
122
 #include "signals.h"
 
123
 #include "window-items.h"
 
124
+#include "settings.h"
 
125
 
 
126
 #include "xmpp-queries.h"
 
127
 #include "rosters-tools.h"
 
128
 #include "fe-xmpp-status.h"
 
129
+#include "tools.h"
 
130
 
 
131
 static void
 
132
 sig_presence_changed(XMPP_SERVER_REC *server, const char *full_jid,
 
133
@@ -32,26 +34,29 @@
 
134
 {
 
135
        XMPP_QUERY_REC *rec;
 
136
        XMPP_ROSTER_USER_REC *user;
 
137
-       const char *msg;
 
138
+       const char *msg, *stripped_jid;
 
139
        char *name;
 
140
 
 
141
+       stripped_jid = (settings_get_bool("xmpp_strip_resource")) ?
 
142
+               xmpp_strip_resource(full_jid) : g_strdup(full_jid);
 
143
+
 
144
        g_return_if_fail(server != NULL);
 
145
-       g_return_if_fail(full_jid != NULL);
 
146
+       g_return_if_fail(stripped_jid != NULL);
 
147
        g_return_if_fail(0 <= show && show < XMPP_PRESENCE_SHOW_LEN);
 
148
-       if ((rec = xmpp_query_find(server, full_jid)) == NULL)
 
149
+       if ((rec = xmpp_query_find(server, stripped_jid)) == NULL)
 
150
                return;
 
151
        msg = fe_xmpp_presence_show[show];
 
152
-       user = rosters_find_user(server->roster, full_jid, NULL, NULL);
 
153
+       user = rosters_find_user(server->roster, stripped_jid, NULL, NULL);
 
154
        name = user != NULL && user->name != NULL ?
 
155
            format_get_text(MODULE_NAME, NULL, server, NULL,
 
156
-               XMPPTXT_FORMAT_NAME, user->name, full_jid) :
 
157
+               XMPPTXT_FORMAT_NAME, user->name, stripped_jid) :
 
158
            format_get_text(MODULE_NAME, NULL, server, NULL,
 
159
-               XMPPTXT_FORMAT_JID, full_jid);
 
160
+               XMPPTXT_FORMAT_JID, stripped_jid);
 
161
        if (status != NULL)
 
162
-               printformat_module(MODULE_NAME, server, full_jid, MSGLEVEL_CRAP,
 
163
+               printformat_module(MODULE_NAME, server, stripped_jid, MSGLEVEL_CRAP,
 
164
                    XMPPTXT_PRESENCE_CHANGE_REASON, name, msg, status);
 
165
        else
 
166
-               printformat_module(MODULE_NAME, server, full_jid, MSGLEVEL_CRAP,
 
167
+               printformat_module(MODULE_NAME, server, stripped_jid, MSGLEVEL_CRAP,
 
168
                    XMPPTXT_PRESENCE_CHANGE, name, msg);
 
169
 }
 
170
 
 
171
--- a/src/fe-common/fe-xmpp-status.c
 
172
+++ b/src/fe-common/fe-xmpp-status.c
 
173
@@ -27,6 +27,7 @@
 
174
 
 
175
 #include "xmpp-servers.h"
 
176
 #include "rosters-tools.h"
 
177
+#include "tools.h"
 
178
 
 
179
 const char *fe_xmpp_presence_show[] = {
 
180
        "Offline",
 
181
@@ -84,20 +85,23 @@
 
182
 {
 
183
        XMPP_ROSTER_USER_REC *user;
 
184
        WINDOW_REC *window;
 
185
-       const char *msg;
 
186
+       const char *msg, *stripped_jid;
 
187
        char *name;
 
188
 
 
189
+       stripped_jid = (settings_get_bool("xmpp_strip_resource")) ?
 
190
+               xmpp_strip_resource(full_jid) : g_strdup(full_jid);
 
191
+
 
192
        g_return_if_fail(IS_XMPP_SERVER(server));
 
193
-       g_return_if_fail(full_jid != NULL);
 
194
+       g_return_if_fail(stripped_jid != NULL);
 
195
        g_return_if_fail(0 <= show && show < XMPP_PRESENCE_SHOW_LEN);   
 
196
        window = fe_xmpp_status_get_window(server);
 
197
        msg = fe_xmpp_presence_show[show];
 
198
-       user = rosters_find_user(server->roster, full_jid, NULL, NULL);
 
199
+       user = rosters_find_user(server->roster, stripped_jid, NULL, NULL);
 
200
        name = user != NULL && user->name != NULL ?
 
201
            format_get_text(MODULE_NAME, NULL, server, NULL,
 
202
-               XMPPTXT_FORMAT_NAME, user->name, full_jid) :
 
203
+               XMPPTXT_FORMAT_NAME, user->name, stripped_jid) :
 
204
            format_get_text(MODULE_NAME, NULL, server, NULL,
 
205
-               XMPPTXT_FORMAT_JID, full_jid);
 
206
+               XMPPTXT_FORMAT_JID, stripped_jid);
 
207
        if (status != NULL)
 
208
                printformat_module_window(MODULE_NAME, window, MSGLEVEL_CRAP,
 
209
                    XMPPTXT_PRESENCE_CHANGE_REASON, name, msg, status);
 
210
@@ -132,6 +136,8 @@
 
211
 
 
212
        settings_add_bool("xmpp_lookandfeel", "xmpp_status_window", FALSE);
 
213
 
 
214
+       settings_add_bool("xmpp_lookandfeel", "xmpp_strip_resource", FALSE);
 
215
+
 
216
        if (settings_get_bool("xmpp_status_window"))
 
217
                signal_add("xmpp presence changed", sig_presence_changed);
 
218
 }