Wed, 10 Feb 2010 05:56:53 +0000
jabber: Cleanup (and drop that unnormalized find function)!
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 3 | * |
|
28322
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
27900
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
27900
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ac8fec1d2234
Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents:
27900
diff
changeset
|
6 | * source distribution. |
| 7014 | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19419
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 21 | * |
| 22 | */ | |
| 23 | #include "internal.h" | |
| 24 | ||
| 25 | #include "debug.h" | |
| 26 | #include "notify.h" | |
| 27 | #include "server.h" | |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7014
diff
changeset
|
28 | #include "util.h" |
|
26871
d62964222795
Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents:
26867
diff
changeset
|
29 | #include "adhoccommands.h" |
| 7014 | 30 | #include "buddy.h" |
| 31 | #include "chat.h" | |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
32 | #include "data.h" |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
33 | #include "google.h" |
| 7014 | 34 | #include "message.h" |
| 35 | #include "xmlnode.h" | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
36 | #include "pep.h" |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
37 | #include "smiley.h" |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
38 | #include "iq.h" |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
39 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
40 | #include <string.h> |
| 7014 | 41 | |
| 42 | void jabber_message_free(JabberMessage *jm) | |
| 43 | { | |
| 15980 | 44 | g_free(jm->from); |
| 13484 | 45 | g_free(jm->to); |
| 46 | g_free(jm->id); | |
| 47 | g_free(jm->subject); | |
| 48 | g_free(jm->body); | |
| 49 | g_free(jm->xhtml); | |
| 50 | g_free(jm->password); | |
|
20057
728a7dce565e
grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents:
19917
diff
changeset
|
51 | g_free(jm->error); |
|
728a7dce565e
grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents:
19917
diff
changeset
|
52 | g_free(jm->thread_id); |
| 13484 | 53 | g_list_free(jm->etc); |
|
20057
728a7dce565e
grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents:
19917
diff
changeset
|
54 | g_list_free(jm->eventitems); |
| 7014 | 55 | |
| 56 | g_free(jm); | |
| 57 | } | |
| 58 | ||
| 7145 | 59 | static void handle_chat(JabberMessage *jm) |
| 7014 | 60 | { |
| 61 | JabberID *jid = jabber_id_new(jm->from); | |
| 62 | ||
|
29331
9e828e599fc2
jabber: Use some convenience variables here.
Paul Aurich <darkrain42@pidgin.im>
parents:
29330
diff
changeset
|
63 | PurpleConnection *gc; |
|
9e828e599fc2
jabber: Use some convenience variables here.
Paul Aurich <darkrain42@pidgin.im>
parents:
29330
diff
changeset
|
64 | PurpleAccount *account; |
| 7014 | 65 | JabberBuddy *jb; |
| 66 | JabberBuddyResource *jbr; | |
| 67 | ||
| 7310 | 68 | if(!jid) |
| 69 | return; | |
| 70 | ||
|
29331
9e828e599fc2
jabber: Use some convenience variables here.
Paul Aurich <darkrain42@pidgin.im>
parents:
29330
diff
changeset
|
71 | gc = jm->js->gc; |
|
9e828e599fc2
jabber: Use some convenience variables here.
Paul Aurich <darkrain42@pidgin.im>
parents:
29330
diff
changeset
|
72 | account = purple_connection_get_account(gc); |
|
9e828e599fc2
jabber: Use some convenience variables here.
Paul Aurich <darkrain42@pidgin.im>
parents:
29330
diff
changeset
|
73 | |
| 7014 | 74 | jb = jabber_buddy_find(jm->js, jm->from, TRUE); |
| 7306 | 75 | jbr = jabber_buddy_find_resource(jb, jid->resource); |
| 7014 | 76 | |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
77 | if (jid->resource) { |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
78 | /* |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
79 | * We received a message from a specific resource, so we probably want a |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
80 | * reply to go to this specific resource (i.e. bind/lock the |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
81 | * conversation to this resource). |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
82 | * |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
83 | * This works because purple_conv_im_send gets the name from |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
84 | * purple_conversation_get_name() |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
85 | */ |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
86 | PurpleConversation *conv; |
| 7258 | 87 | |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
88 | conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, jm->from, account); |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
89 | if (conv) |
|
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
90 | purple_conversation_set_name(conv, jm->from); |
| 7258 | 91 | } |
| 7014 | 92 | |
| 93 | if(!jm->xhtml && !jm->body) { | |
|
28341
491467d3da13
jabber: Fix typing notifications between 2.6.0 and <= 2.5.9.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
94 | if (jbr) { |
|
491467d3da13
jabber: Fix typing notifications between 2.6.0 and <= 2.5.9.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
95 | if (jm->chat_state != JM_STATE_NONE) |
|
491467d3da13
jabber: Fix typing notifications between 2.6.0 and <= 2.5.9.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
96 | jbr->chat_states = JABBER_CHAT_STATES_SUPPORTED; |
|
491467d3da13
jabber: Fix typing notifications between 2.6.0 and <= 2.5.9.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
97 | else |
|
491467d3da13
jabber: Fix typing notifications between 2.6.0 and <= 2.5.9.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
98 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; |
|
491467d3da13
jabber: Fix typing notifications between 2.6.0 and <= 2.5.9.
Paul Aurich <darkrain42@pidgin.im>
parents:
28322
diff
changeset
|
99 | } |
|
27750
f25b6a565494
Use Entity Capabilities to pick up Chat States support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27749
diff
changeset
|
100 | |
|
15710
fbc4a200c853
Receiving XEP 85 'gone' messages. Doesn't do anything because of the string freeze. This is akin to the MSN 'so-and-so has closed the conversation window' messages. Rlaager made a strong point to me that they're not altogether stalky, but can be useful.
Sean Egan <seanegan@pidgin.im>
parents:
15709
diff
changeset
|
101 | if(JM_STATE_COMPOSING == jm->chat_state) { |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
102 | serv_got_typing(gc, jm->from, 0, PURPLE_TYPING); |
|
15710
fbc4a200c853
Receiving XEP 85 'gone' messages. Doesn't do anything because of the string freeze. This is akin to the MSN 'so-and-so has closed the conversation window' messages. Rlaager made a strong point to me that they're not altogether stalky, but can be useful.
Sean Egan <seanegan@pidgin.im>
parents:
15709
diff
changeset
|
103 | } else if(JM_STATE_PAUSED == jm->chat_state) { |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
104 | serv_got_typing(gc, jm->from, 0, PURPLE_TYPED); |
|
15710
fbc4a200c853
Receiving XEP 85 'gone' messages. Doesn't do anything because of the string freeze. This is akin to the MSN 'so-and-so has closed the conversation window' messages. Rlaager made a strong point to me that they're not altogether stalky, but can be useful.
Sean Egan <seanegan@pidgin.im>
parents:
15709
diff
changeset
|
105 | } else if(JM_STATE_GONE == jm->chat_state) { |
| 15884 | 106 | PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
107 | jm->from, account); |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
108 | if (conv && jid->node && jid->domain) { |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
109 | char buf[256]; |
| 15884 | 110 | PurpleBuddy *buddy; |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
111 | |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
112 | g_snprintf(buf, sizeof(buf), "%s@%s", jid->node, jid->domain); |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
113 | |
|
29331
9e828e599fc2
jabber: Use some convenience variables here.
Paul Aurich <darkrain42@pidgin.im>
parents:
29330
diff
changeset
|
114 | if ((buddy = purple_find_buddy(account, buf))) { |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
115 | const char *who; |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
116 | char *escaped; |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
117 | |
| 15884 | 118 | who = purple_buddy_get_alias(buddy); |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
119 | escaped = g_markup_escape_text(who, -1); |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
120 | |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
121 | g_snprintf(buf, sizeof(buf), |
| 16946 | 122 | _("%s has left the conversation."), escaped); |
|
21193
e918a1846d03
Use an independant status type for 'current media' stuff, instead of using
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20361
diff
changeset
|
123 | g_free(escaped); |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
124 | |
| 15884 | 125 | /* At some point when we restructure PurpleConversation, |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
126 | * this should be able to be implemented by removing the |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
127 | * user from the conversation like we do with chats now. */ |
| 15884 | 128 | purple_conversation_write(conv, "", buf, |
| 129 | PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
130 | } |
|
15710
fbc4a200c853
Receiving XEP 85 'gone' messages. Doesn't do anything because of the string freeze. This is akin to the MSN 'so-and-so has closed the conversation window' messages. Rlaager made a strong point to me that they're not altogether stalky, but can be useful.
Sean Egan <seanegan@pidgin.im>
parents:
15709
diff
changeset
|
131 | } |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
132 | serv_got_typing_stopped(gc, jm->from); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
133 | |
|
15710
fbc4a200c853
Receiving XEP 85 'gone' messages. Doesn't do anything because of the string freeze. This is akin to the MSN 'so-and-so has closed the conversation window' messages. Rlaager made a strong point to me that they're not altogether stalky, but can be useful.
Sean Egan <seanegan@pidgin.im>
parents:
15709
diff
changeset
|
134 | } else { |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
135 | serv_got_typing_stopped(gc, jm->from); |
|
15710
fbc4a200c853
Receiving XEP 85 'gone' messages. Doesn't do anything because of the string freeze. This is akin to the MSN 'so-and-so has closed the conversation window' messages. Rlaager made a strong point to me that they're not altogether stalky, but can be useful.
Sean Egan <seanegan@pidgin.im>
parents:
15709
diff
changeset
|
136 | } |
| 7014 | 137 | } else { |
| 8400 | 138 | if(jbr) { |
|
27429
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
139 | if (jm->chat_state != JM_STATE_NONE) |
| 13708 | 140 | jbr->chat_states = JABBER_CHAT_STATES_SUPPORTED; |
|
27429
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
141 | else |
| 13708 | 142 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; |
| 143 | ||
| 8400 | 144 | if(jbr->thread_id) |
| 145 | g_free(jbr->thread_id); | |
| 146 | jbr->thread_id = g_strdup(jbr->thread_id); | |
| 147 | } | |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
148 | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
149 | if (jm->js->googletalk && jm->xhtml == NULL) { |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
150 | char *tmp = jm->body; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
151 | jm->body = jabber_google_format_to_html(jm->body); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
152 | g_free(tmp); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
153 | } |
|
29336
11ae11b31743
jabber: Cleanup (and drop that unnormalized find function)!
Paul Aurich <darkrain42@pidgin.im>
parents:
29332
diff
changeset
|
154 | serv_got_im(gc, jm->from, jm->xhtml ? jm->xhtml : jm->body, 0, jm->sent); |
| 7014 | 155 | } |
| 156 | ||
| 157 | jabber_id_free(jid); | |
| 158 | } | |
| 159 | ||
| 7145 | 160 | static void handle_headline(JabberMessage *jm) |
| 161 | { | |
| 162 | char *title; | |
|
17819
862fe0f947a9
Added buzz support using a private extension. Maybe I should write a XEP about that.
Andreas Monitzer <am@adiumx.com>
parents:
17811
diff
changeset
|
163 | GString *body; |
| 7145 | 164 | GList *etc; |
| 165 | ||
|
17819
862fe0f947a9
Added buzz support using a private extension. Maybe I should write a XEP about that.
Andreas Monitzer <am@adiumx.com>
parents:
17811
diff
changeset
|
166 | if(!jm->xhtml && !jm->body) |
|
862fe0f947a9
Added buzz support using a private extension. Maybe I should write a XEP about that.
Andreas Monitzer <am@adiumx.com>
parents:
17811
diff
changeset
|
167 | return; /* ignore headlines without any content */ |
| 7145 | 168 | |
|
17819
862fe0f947a9
Added buzz support using a private extension. Maybe I should write a XEP about that.
Andreas Monitzer <am@adiumx.com>
parents:
17811
diff
changeset
|
169 | body = g_string_new(""); |
| 7145 | 170 | title = g_strdup_printf(_("Message from %s"), jm->from); |
| 171 | ||
| 172 | if(jm->xhtml) | |
| 173 | g_string_append(body, jm->xhtml); | |
| 174 | else if(jm->body) | |
| 175 | g_string_append(body, jm->body); | |
| 176 | ||
| 177 | for(etc = jm->etc; etc; etc = etc->next) { | |
| 178 | xmlnode *x = etc->data; | |
| 13808 | 179 | const char *xmlns = xmlnode_get_namespace(x); |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28979
diff
changeset
|
180 | if(xmlns && !strcmp(xmlns, NS_OOB_X_DATA)) { |
| 7145 | 181 | xmlnode *url, *desc; |
| 182 | char *urltxt, *desctxt; | |
| 183 | ||
| 184 | url = xmlnode_get_child(x, "url"); | |
| 185 | desc = xmlnode_get_child(x, "desc"); | |
| 186 | ||
| 187 | if(!url || !desc) | |
| 188 | continue; | |
| 189 | ||
| 190 | urltxt = xmlnode_get_data(url); | |
| 191 | desctxt = xmlnode_get_data(desc); | |
| 192 | ||
| 193 | /* I'm all about ugly hacks */ | |
|
14790
a0226bec3707
[gaim-migrate @ 17484]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
194 | if(body->len && jm->body && !strcmp(body->str, jm->body)) |
| 7145 | 195 | g_string_printf(body, "<a href='%s'>%s</a>", |
| 196 | urltxt, desctxt); | |
| 197 | else | |
| 198 | g_string_append_printf(body, "<br/><a href='%s'>%s</a>", | |
| 199 | urltxt, desctxt); | |
| 200 | ||
| 201 | g_free(urltxt); | |
| 202 | g_free(desctxt); | |
| 203 | } | |
| 204 | } | |
| 205 | ||
| 15884 | 206 | purple_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title, |
| 7145 | 207 | NULL, body->str, NULL, NULL); |
| 208 | ||
| 209 | g_free(title); | |
| 210 | g_string_free(body, TRUE); | |
| 211 | } | |
| 212 | ||
| 213 | static void handle_groupchat(JabberMessage *jm) | |
| 7014 | 214 | { |
| 215 | JabberID *jid = jabber_id_new(jm->from); | |
| 7310 | 216 | JabberChat *chat; |
| 217 | ||
| 218 | if(!jid) | |
| 219 | return; | |
| 220 | ||
| 221 | chat = jabber_chat_find(jm->js, jid->node, jid->domain); | |
| 7014 | 222 | |
| 223 | if(!chat) | |
| 224 | return; | |
| 225 | ||
| 7971 | 226 | if(jm->subject) { |
| 15884 | 227 | purple_conv_chat_set_topic(PURPLE_CONV_CHAT(chat->conv), jid->resource, |
| 7183 | 228 | jm->subject); |
| 7971 | 229 | if(!jm->xhtml && !jm->body) { |
| 9762 | 230 | char *msg, *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10607
diff
changeset
|
231 | tmp = g_markup_escape_text(jm->subject, -1); |
| 15884 | 232 | tmp2 = purple_markup_linkify(tmp); |
| 7971 | 233 | if(jid->resource) |
| 9762 | 234 | msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, tmp2); |
| 7971 | 235 | else |
| 9762 | 236 | msg = g_strdup_printf(_("The topic is: %s"), tmp2); |
| 15884 | 237 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", msg, PURPLE_MESSAGE_SYSTEM, jm->sent); |
| 9762 | 238 | g_free(tmp); |
| 239 | g_free(tmp2); | |
| 7971 | 240 | g_free(msg); |
| 241 | } | |
| 242 | } | |
| 7014 | 243 | |
| 7630 | 244 | if(jm->xhtml || jm->body) { |
| 245 | if(jid->resource) | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
246 | serv_got_chat_in(jm->js->gc, chat->id, jid->resource, |
| 15884 | 247 | jm->delayed ? PURPLE_MESSAGE_DELAYED : 0, |
| 7630 | 248 | jm->xhtml ? jm->xhtml : jm->body, jm->sent); |
| 249 | else if(chat->muc) | |
| 15884 | 250 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", |
| 7630 | 251 | jm->xhtml ? jm->xhtml : jm->body, |
| 15884 | 252 | PURPLE_MESSAGE_SYSTEM, jm->sent); |
| 7630 | 253 | } |
| 254 | ||
| 7014 | 255 | jabber_id_free(jid); |
| 256 | } | |
| 257 | ||
| 7145 | 258 | static void handle_groupchat_invite(JabberMessage *jm) |
| 7014 | 259 | { |
| 7310 | 260 | GHashTable *components; |
| 7014 | 261 | JabberID *jid = jabber_id_new(jm->to); |
| 262 | ||
| 7310 | 263 | if(!jid) |
| 264 | return; | |
| 265 | ||
|
15598
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
266 | components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); |
| 7310 | 267 | |
|
15598
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
268 | g_hash_table_replace(components, "room", g_strdup(jid->node)); |
|
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
269 | g_hash_table_replace(components, "server", g_strdup(jid->domain)); |
|
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
270 | g_hash_table_replace(components, "handle", g_strdup(jm->js->user->node)); |
|
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
271 | g_hash_table_replace(components, "password", g_strdup(jm->password)); |
| 7014 | 272 | |
| 273 | jabber_id_free(jid); | |
|
10774
f4238d6312ff
[gaim-migrate @ 12383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
274 | serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components); |
| 7014 | 275 | } |
| 276 | ||
| 7145 | 277 | static void handle_error(JabberMessage *jm) |
| 7014 | 278 | { |
| 279 | char *buf; | |
| 280 | ||
| 281 | if(!jm->body) | |
| 282 | return; | |
| 283 | ||
| 284 | buf = g_strdup_printf(_("Message delivery to %s failed: %s"), | |
|
13766
6b92ce47f7e5
[gaim-migrate @ 16176]
Daniel Atallah <datallah@pidgin.im>
parents:
13708
diff
changeset
|
285 | jm->from, jm->error ? jm->error : ""); |
| 7014 | 286 | |
|
16961
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16946
diff
changeset
|
287 | purple_notify_formatted(jm->js->gc, _("XMPP Message Error"), _("XMPP Message Error"), buf, |
| 7944 | 288 | jm->xhtml ? jm->xhtml : jm->body, NULL, NULL); |
| 7014 | 289 | |
| 290 | g_free(buf); | |
| 291 | } | |
| 292 | ||
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
293 | static void handle_buzz(JabberMessage *jm) { |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
294 | PurpleBuddy *buddy; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
295 | PurpleAccount *account; |
|
25316
8b6461a2f967
Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents:
25154
diff
changeset
|
296 | |
|
17823
2ca25e7e65dd
Switched buzz namespace and tag name to be libpurple-specific and use a more professionally-sounding name ('attention' instead of 'buzz').
Andreas Monitzer <am@adiumx.com>
parents:
17822
diff
changeset
|
297 | /* Delayed buzz MUST NOT be accepted */ |
|
2ca25e7e65dd
Switched buzz namespace and tag name to be libpurple-specific and use a more professionally-sounding name ('attention' instead of 'buzz').
Andreas Monitzer <am@adiumx.com>
parents:
17822
diff
changeset
|
298 | if(jm->delayed) |
|
2ca25e7e65dd
Switched buzz namespace and tag name to be libpurple-specific and use a more professionally-sounding name ('attention' instead of 'buzz').
Andreas Monitzer <am@adiumx.com>
parents:
17822
diff
changeset
|
299 | return; |
|
25316
8b6461a2f967
Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents:
25154
diff
changeset
|
300 | |
|
17824
52683dfc1f7d
Added the option to enable/disable buzz via a status setting. It's default off for the pidgin folks.
Andreas Monitzer <am@adiumx.com>
parents:
17823
diff
changeset
|
301 | /* Reject buzz when it's not enabled */ |
|
52683dfc1f7d
Added the option to enable/disable buzz via a status setting. It's default off for the pidgin folks.
Andreas Monitzer <am@adiumx.com>
parents:
17823
diff
changeset
|
302 | if(!jm->js->allowBuzz) |
|
52683dfc1f7d
Added the option to enable/disable buzz via a status setting. It's default off for the pidgin folks.
Andreas Monitzer <am@adiumx.com>
parents:
17823
diff
changeset
|
303 | return; |
|
25316
8b6461a2f967
Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents:
25154
diff
changeset
|
304 | |
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
305 | account = purple_connection_get_account(jm->js->gc); |
|
25316
8b6461a2f967
Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents:
25154
diff
changeset
|
306 | |
|
8b6461a2f967
Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents:
25154
diff
changeset
|
307 | if ((buddy = purple_find_buddy(account, jm->from)) == NULL) |
|
17823
2ca25e7e65dd
Switched buzz namespace and tag name to be libpurple-specific and use a more professionally-sounding name ('attention' instead of 'buzz').
Andreas Monitzer <am@adiumx.com>
parents:
17822
diff
changeset
|
308 | return; /* Do not accept buzzes from unknown people */ |
|
2ca25e7e65dd
Switched buzz namespace and tag name to be libpurple-specific and use a more professionally-sounding name ('attention' instead of 'buzz').
Andreas Monitzer <am@adiumx.com>
parents:
17822
diff
changeset
|
309 | |
|
25316
8b6461a2f967
Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents:
25154
diff
changeset
|
310 | /* xmpp only has 1 attention type, so index is 0 */ |
|
25974
a92b44bfe15e
Give username (JID) to purple_prpl_got_attention, not alias
Marcus Lundblad <malu@pidgin.im>
parents:
25968
diff
changeset
|
311 | purple_prpl_got_attention(jm->js->gc, jm->from, 0); |
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
312 | } |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
313 | |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
314 | /* used internally by the functions below */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
315 | typedef struct { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
316 | gchar *cid; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
317 | gchar *alt; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
318 | } JabberSmileyRef; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
319 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
320 | |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
321 | static void |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
322 | jabber_message_get_refs_from_xmlnode_internal(const xmlnode *message, |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
323 | GHashTable *table) |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
324 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
325 | xmlnode *child; |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
326 | |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
327 | for (child = xmlnode_get_child(message, "img") ; child ; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
328 | child = xmlnode_get_next_twin(child)) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
329 | const gchar *src = xmlnode_get_attrib(child, "src"); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
330 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
331 | if (g_str_has_prefix(src, "cid:")) { |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
332 | const gchar *cid = src + 4; |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
333 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
334 | /* if we haven't "fetched" this yet... */ |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
335 | if (!g_hash_table_lookup(table, cid)) { |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
336 | /* take a copy of the cid and let the SmileyRef own it... */ |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
337 | gchar *temp_cid = g_strdup(cid); |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
338 | JabberSmileyRef *ref = g_new0(JabberSmileyRef, 1); |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
339 | const gchar *alt = xmlnode_get_attrib(child, "alt"); |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
340 | ref->cid = temp_cid; |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
341 | /* if there is no "alt" string, use the cid... |
|
24258
9ae10fafad7a
When receiving an <img/> without the "alt" attribute, set
Marcus Lundblad <malu@pidgin.im>
parents:
24257
diff
changeset
|
342 | include the entire src, eg. "cid:.." to avoid linkification */ |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
343 | if (alt && alt[0] != '\0') { |
|
24259
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
344 | /* workaround for when "alt" is set to the value of the |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
345 | CID (which Jabbim seems to do), to avoid it showing up |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
346 | as an mailto: link */ |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
347 | if (purple_email_is_valid(alt)) { |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
348 | ref->alt = g_strdup_printf("smiley:%s", alt); |
|
24259
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
349 | } else { |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
350 | ref->alt = g_strdup(alt); |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
351 | } |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
352 | } else { |
|
24258
9ae10fafad7a
When receiving an <img/> without the "alt" attribute, set
Marcus Lundblad <malu@pidgin.im>
parents:
24257
diff
changeset
|
353 | ref->alt = g_strdup(src); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
354 | } |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
355 | g_hash_table_insert(table, temp_cid, ref); |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
356 | } |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
357 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
358 | } |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
359 | |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
360 | for (child = message->child ; child ; child = child->next) { |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
361 | jabber_message_get_refs_from_xmlnode_internal(child, table); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
362 | } |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
363 | } |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
364 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
365 | static gboolean |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
366 | jabber_message_get_refs_steal(gpointer key, gpointer value, gpointer user_data) |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
367 | { |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
368 | GList **refs = (GList **) user_data; |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
369 | JabberSmileyRef *ref = (JabberSmileyRef *) value; |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
370 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
371 | *refs = g_list_append(*refs, ref); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
372 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
373 | return TRUE; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
374 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
375 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
376 | static GList * |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
377 | jabber_message_get_refs_from_xmlnode(const xmlnode *message) |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
378 | { |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
379 | GList *refs = NULL; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
380 | GHashTable *unique_refs = g_hash_table_new(g_str_hash, g_str_equal); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
381 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
382 | jabber_message_get_refs_from_xmlnode_internal(message, unique_refs); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
383 | (void) g_hash_table_foreach_steal(unique_refs, |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
384 | jabber_message_get_refs_steal, (gpointer) &refs); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
385 | g_hash_table_destroy(unique_refs); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
386 | return refs; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
387 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
388 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
389 | static gchar * |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
390 | jabber_message_xml_to_string_strip_img_smileys(xmlnode *xhtml) |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
391 | { |
|
24387
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
392 | gchar *markup = xmlnode_to_str(xhtml, NULL); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
393 | int len = strlen(markup); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
394 | int pos = 0; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
395 | GString *out = g_string_new(NULL); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
396 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
397 | while (pos < len) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
398 | /* this is a bit cludgy, maybe there is a better way to do this... |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
399 | we need to find all <img> tags within the XHTML and replace those |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
400 | tags with the value of their "alt" attributes */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
401 | if (g_str_has_prefix(&(markup[pos]), "<img")) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
402 | xmlnode *img = NULL; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
403 | int pos2 = pos; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
404 | const gchar *src; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
405 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
406 | for (; pos2 < len ; pos2++) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
407 | if (g_str_has_prefix(&(markup[pos2]), "/>")) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
408 | pos2 += 2; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
409 | break; |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
410 | } else if (g_str_has_prefix(&(markup[pos2]), "</img>")) { |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
411 | pos2 += 5; |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
412 | break; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
413 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
414 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
415 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
416 | /* note, if the above loop didn't find the end of the <img> tag, |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
417 | it the parsed string will be until the end of the input string, |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
418 | in which case xmlnode_from_str will bail out and return NULL, |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
419 | in this case the "if" statement below doesn't trigger and the |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
420 | text is copied unchanged */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
421 | img = xmlnode_from_str(&(markup[pos]), pos2 - pos); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
422 | src = xmlnode_get_attrib(img, "src"); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
423 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
424 | if (g_str_has_prefix(src, "cid:")) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
425 | const gchar *alt = xmlnode_get_attrib(img, "alt"); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
426 | /* if the "alt" attribute is empty, put the cid as smiley string */ |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
427 | if (alt && alt[0] != '\0') { |
|
24259
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
428 | /* if the "alt" is the same as the CID, as Jabbim does, |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
429 | this prevents linkification... */ |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
430 | if (purple_email_is_valid(alt)) { |
|
24386
0710eb7a41c5
A couple of compile warning fixes, a couple of memory leak plugs.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24259
diff
changeset
|
431 | gchar *safe_alt = g_strdup_printf("smiley:%s", alt); |
|
24259
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
432 | out = g_string_append(out, safe_alt); |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
433 | g_free(safe_alt); |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
434 | } else { |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
435 | out = g_string_append(out, alt); |
|
e69d72917038
Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents:
24258
diff
changeset
|
436 | } |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
437 | } else { |
|
24258
9ae10fafad7a
When receiving an <img/> without the "alt" attribute, set
Marcus Lundblad <malu@pidgin.im>
parents:
24257
diff
changeset
|
438 | out = g_string_append(out, src); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
439 | } |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
440 | pos += pos2 - pos; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
441 | } else { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
442 | out = g_string_append_c(out, markup[pos]); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
443 | pos++; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
444 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
445 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
446 | xmlnode_free(img); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
447 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
448 | } else { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
449 | out = g_string_append_c(out, markup[pos]); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
450 | pos++; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
451 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
452 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
453 | |
|
24387
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
454 | g_free(markup); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
455 | return g_string_free(out, FALSE); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
456 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
457 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
458 | static void |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
459 | jabber_message_add_remote_smileys(const xmlnode *message) |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
460 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
461 | xmlnode *data_tag; |
|
28979
191942cc7747
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents:
28832
diff
changeset
|
462 | for (data_tag = xmlnode_get_child_with_namespace(message, "data", NS_BOB) ; |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
463 | data_tag ; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
464 | data_tag = xmlnode_get_next_twin(data_tag)) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
465 | const gchar *cid = xmlnode_get_attrib(data_tag, "cid"); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
466 | const JabberData *data = jabber_data_find_remote_by_cid(cid); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
467 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
468 | if (!data && cid != NULL) { |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
469 | /* we haven't cached this already, let's add it */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
470 | JabberData *new_data = jabber_data_create_from_xml(data_tag); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
471 | jabber_data_associate_remote(new_data); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
472 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
473 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
474 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
475 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
476 | /* used in the function below to supply a conversation and shortcut for a |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
477 | smiley */ |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
478 | typedef struct { |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
479 | PurpleConversation *conv; |
|
24387
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
480 | gchar *alt; |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
481 | } JabberDataRef; |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
482 | |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
483 | static void |
|
26687
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
484 | jabber_message_get_data_cb(JabberStream *js, const char *from, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
485 | JabberIqType type, const char *id, |
|
1e799151fabe
Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
Paul Aurich <darkrain42@pidgin.im>
parents:
26042
diff
changeset
|
486 | xmlnode *packet, gpointer data) |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
487 | { |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
488 | JabberDataRef *ref = (JabberDataRef *) data; |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
489 | PurpleConversation *conv = ref->conv; |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
490 | const gchar *alt = ref->alt; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
491 | xmlnode *data_element = xmlnode_get_child(packet, "data"); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
492 | xmlnode *item_not_found = xmlnode_get_child(packet, "item-not-found"); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
493 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
494 | /* did we get a data element as result? */ |
|
28442
2da956f23839
Don't crash when receiving an error iq response when trying fetch a custom
Marcus Lundblad <malu@pidgin.im>
parents:
28341
diff
changeset
|
495 | if (data_element && type == JABBER_IQ_RESULT) { |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
496 | JabberData *data = jabber_data_create_from_xml(data_element); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
497 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
498 | if (data) { |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
499 | jabber_data_associate_remote(data); |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
500 | purple_conv_custom_smiley_write(conv, alt, |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
501 | jabber_data_get_data(data), |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
502 | jabber_data_get_size(data)); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
503 | purple_conv_custom_smiley_close(conv, alt); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
504 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
505 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
506 | } else if (item_not_found) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
507 | purple_debug_info("jabber", |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
508 | "Responder didn't recognize requested data\n"); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
509 | } else { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
510 | purple_debug_error("jabber", "Unknown response to data request\n"); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
511 | } |
|
24387
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
512 | g_free(ref->alt); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
513 | g_free(ref); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
514 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
515 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
516 | static void |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
517 | jabber_message_send_data_request(JabberStream *js, PurpleConversation *conv, |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
518 | const gchar *cid, const gchar *who, |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
519 | const gchar *alt) |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
520 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
521 | JabberIq *request = jabber_iq_new(js, JABBER_IQ_GET); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
522 | JabberDataRef *ref = g_new0(JabberDataRef, 1); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
523 | xmlnode *data_request = jabber_data_get_xml_request(cid); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
524 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
525 | xmlnode_set_attrib(request->node, "to", who); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
526 | ref->conv = conv; |
|
24387
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
527 | ref->alt = g_strdup(alt); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
528 | jabber_iq_set_callback(request, jabber_message_get_data_cb, ref); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
529 | xmlnode_insert_child(request->node, data_request); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
530 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
531 | jabber_iq_send(request); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
532 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
533 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
534 | |
| 7014 | 535 | void jabber_message_parse(JabberStream *js, xmlnode *packet) |
| 536 | { | |
| 537 | JabberMessage *jm; | |
|
27103
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
538 | const char *id, *from, *to, *type; |
| 7014 | 539 | xmlnode *child; |
|
27103
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
540 | gboolean signal_return; |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
541 | |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
542 | from = xmlnode_get_attrib(packet, "from"); |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
543 | id = xmlnode_get_attrib(packet, "id"); |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
544 | to = xmlnode_get_attrib(packet, "to"); |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
545 | type = xmlnode_get_attrib(packet, "type"); |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
546 | |
|
28832
4e4b609b85e4
jabber: Use purple_connection_get_prpl() instead of jabber_plugin.
Paul Aurich <darkrain42@pidgin.im>
parents:
28828
diff
changeset
|
547 | signal_return = GPOINTER_TO_INT(purple_signal_emit_return_1(purple_connection_get_prpl(js->gc), |
|
27103
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
548 | "jabber-receiving-message", js->gc, type, id, from, to, packet)); |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
549 | if (signal_return) |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
550 | return; |
| 7014 | 551 | |
| 552 | jm = g_new0(JabberMessage, 1); | |
| 553 | jm->js = js; | |
| 554 | jm->sent = time(NULL); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
555 | jm->delayed = FALSE; |
|
27429
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
556 | jm->chat_state = JM_STATE_NONE; |
| 7014 | 557 | |
| 558 | if(type) { | |
| 559 | if(!strcmp(type, "normal")) | |
| 560 | jm->type = JABBER_MESSAGE_NORMAL; | |
|
20320
6337e101f6ab
Plug some memory leaks.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19917
diff
changeset
|
561 | else if(!strcmp(type, "chat")) |
| 7014 | 562 | jm->type = JABBER_MESSAGE_CHAT; |
| 563 | else if(!strcmp(type, "groupchat")) | |
| 564 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 565 | else if(!strcmp(type, "headline")) | |
| 566 | jm->type = JABBER_MESSAGE_HEADLINE; | |
| 567 | else if(!strcmp(type, "error")) | |
| 568 | jm->type = JABBER_MESSAGE_ERROR; | |
| 569 | else | |
| 570 | jm->type = JABBER_MESSAGE_OTHER; | |
| 571 | } else { | |
| 572 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 573 | } | |
| 574 | ||
|
27103
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
575 | jm->from = g_strdup(from); |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
576 | jm->to = g_strdup(to); |
|
815af6acd59b
Add jabber signals for IQ, Message, and Presence stanzas. Lightly tested (it doesn't crash [Prove me wrong!]) and as you'll note, I refer to documentation that doesn't yet exist.
Paul Aurich <darkrain42@pidgin.im>
parents:
27061
diff
changeset
|
577 | jm->id = g_strdup(id); |
| 7014 | 578 | |
| 579 | for(child = packet->child; child; child = child->next) { | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
580 | const char *xmlns = xmlnode_get_namespace(child); |
| 8135 | 581 | if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 582 | continue; |
| 583 | ||
|
25154
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
584 | if(!strcmp(child->name, "error")) { |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
585 | const char *code = xmlnode_get_attrib(child, "code"); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
586 | char *code_txt = NULL; |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
587 | char *text = xmlnode_get_data(child); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
588 | if (!text) { |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
589 | xmlnode *enclosed_text_node; |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
590 | |
|
25154
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
591 | if ((enclosed_text_node = xmlnode_get_child(child, "text"))) |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
592 | text = xmlnode_get_data(enclosed_text_node); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
593 | } |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
594 | |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
595 | if(code) |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
596 | code_txt = g_strdup_printf(_("(Code %s)"), code); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
597 | |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
598 | if(!jm->error) |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
599 | jm->error = g_strdup_printf("%s%s%s", |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
600 | text ? text : "", |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
601 | text && code_txt ? " " : "", |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
602 | code_txt ? code_txt : ""); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
603 | |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
604 | g_free(code_txt); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
605 | g_free(text); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
606 | } else if (xmlns == NULL) { |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
607 | /* QuLogic: Not certain this is correct, but it would have happened |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
608 | with the previous code. */ |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
609 | if(!strcmp(child->name, "x")) |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
610 | jm->etc = g_list_append(jm->etc, child); |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
611 | /* The following tests expect xmlns != NULL */ |
|
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
612 | continue; |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28979
diff
changeset
|
613 | } else if(!strcmp(child->name, "subject") && !strcmp(xmlns, NS_XMPP_CLIENT)) { |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26711
diff
changeset
|
614 | if(!jm->subject) { |
| 7014 | 615 | jm->subject = xmlnode_get_data(child); |
|
26859
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26711
diff
changeset
|
616 | if(!jm->subject) |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26711
diff
changeset
|
617 | jm->subject = g_strdup(""); |
|
8175186cf34a
Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents:
26711
diff
changeset
|
618 | } |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28979
diff
changeset
|
619 | } else if(!strcmp(child->name, "thread") && !strcmp(xmlns, NS_XMPP_CLIENT)) { |
| 8400 | 620 | if(!jm->thread_id) |
| 621 | jm->thread_id = xmlnode_get_data(child); | |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28979
diff
changeset
|
622 | } else if(!strcmp(child->name, "body") && !strcmp(xmlns, NS_XMPP_CLIENT)) { |
| 13385 | 623 | if(!jm->body) { |
| 624 | char *msg = xmlnode_to_str(child, NULL); | |
| 15884 | 625 | jm->body = purple_strdup_withhtml(msg); |
| 13385 | 626 | g_free(msg); |
| 627 | } | |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28979
diff
changeset
|
628 | } else if(!strcmp(child->name, "html") && !strcmp(xmlns, NS_XHTML_IM)) { |
|
17328
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
629 | if(!jm->xhtml && xmlnode_get_child(child, "body")) { |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
630 | char *c; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
631 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
632 | const PurpleConnection *gc = js->gc; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
633 | PurpleAccount *account = purple_connection_get_account(gc); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
634 | PurpleConversation *conv = NULL; |
|
24386
0710eb7a41c5
A couple of compile warning fixes, a couple of memory leak plugs.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24259
diff
changeset
|
635 | GList *smiley_refs = NULL; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
636 | gchar *reformatted_xhtml; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
637 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
638 | if (purple_account_get_bool(account, "custom_smileys", TRUE)) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
639 | /* find a list of smileys ("cid" and "alt" text pairs) |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
640 | occuring in the message */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
641 | smiley_refs = jabber_message_get_refs_from_xmlnode(child); |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
642 | purple_debug_info("jabber", "found %d smileys\n", |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
643 | g_list_length(smiley_refs)); |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
644 | |
|
27155
53502d71efdd
Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents:
27131
diff
changeset
|
645 | if (smiley_refs) { |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
646 | if (jm->type == JABBER_MESSAGE_GROUPCHAT) { |
|
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
647 | JabberID *jid = jabber_id_new(jm->from); |
|
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
648 | JabberChat *chat = NULL; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
649 | |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
650 | if (jid) { |
|
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
651 | chat = jabber_chat_find(js, jid->node, jid->domain); |
|
27782
68314a2ac01b
Break the 'if' onto two lines and don't bother calling jabber_id_free()
Mark Doliner <markdoliner@pidgin.im>
parents:
27750
diff
changeset
|
652 | if (chat) |
|
68314a2ac01b
Break the 'if' onto two lines and don't bother calling jabber_id_free()
Mark Doliner <markdoliner@pidgin.im>
parents:
27750
diff
changeset
|
653 | conv = chat->conv; |
|
68314a2ac01b
Break the 'if' onto two lines and don't bother calling jabber_id_free()
Mark Doliner <markdoliner@pidgin.im>
parents:
27750
diff
changeset
|
654 | jabber_id_free(jid); |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
655 | } |
|
26867
20bf84d510d8
Only look for and add custom smileys to incoming messages that are going to
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
656 | } else if (jm->type == JABBER_MESSAGE_NORMAL || |
|
20bf84d510d8
Only look for and add custom smileys to incoming messages that are going to
Paul Aurich <darkrain42@pidgin.im>
parents:
26859
diff
changeset
|
657 | jm->type == JABBER_MESSAGE_CHAT) { |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
658 | conv = |
|
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
659 | purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, |
|
27749
f9c5a1a95204
Remove a superfluous variable.
Paul Aurich <darkrain42@pidgin.im>
parents:
27748
diff
changeset
|
660 | from, account); |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
661 | if (!conv) { |
|
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
662 | /* we need to create the conversation here */ |
|
27155
53502d71efdd
Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents:
27131
diff
changeset
|
663 | conv = |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
664 | purple_conversation_new(PURPLE_CONV_TYPE_IM, |
|
27749
f9c5a1a95204
Remove a superfluous variable.
Paul Aurich <darkrain42@pidgin.im>
parents:
27748
diff
changeset
|
665 | account, from); |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
666 | } |
|
24257
d6402f066933
Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <malu@pidgin.im>
parents:
24254
diff
changeset
|
667 | } |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
668 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
669 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
670 | /* process any newly provided smileys */ |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
671 | jabber_message_add_remote_smileys(packet); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
672 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
673 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
674 | /* reformat xhtml so that img tags with a "cid:" src gets |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
675 | translated to the bare text of the emoticon (the "alt" attrib) */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
676 | /* this is done also when custom smiley retrieval is turned off, |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
677 | this way the receiver always sees the shortcut instead */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
678 | reformatted_xhtml = |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
679 | jabber_message_xml_to_string_strip_img_smileys(child); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
680 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
681 | jm->xhtml = reformatted_xhtml; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
682 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
683 | /* add known custom emoticons to the conversation */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
684 | /* note: if there were no smileys in the incoming message, or |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
685 | if receiving custom smileys is turned off, smiley_refs will |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
686 | be NULL */ |
|
24669
5642bb588664
I got a crash happened at dereferencing chat when it's NULL, I think this
Ka-Hing Cheung <khc@pidgin.im>
parents:
24387
diff
changeset
|
687 | for (; conv && smiley_refs ; smiley_refs = g_list_delete_link(smiley_refs, smiley_refs)) { |
|
24387
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
688 | JabberSmileyRef *ref = (JabberSmileyRef *) smiley_refs->data; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
689 | const gchar *cid = ref->cid; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
690 | const gchar *alt = ref->alt; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
691 | |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
692 | purple_debug_info("jabber", |
|
24257
d6402f066933
Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <malu@pidgin.im>
parents:
24254
diff
changeset
|
693 | "about to add custom smiley %s to the conv\n", alt); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
694 | if (purple_conv_custom_smiley_add(conv, alt, "cid", cid, |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
695 | TRUE)) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
696 | const JabberData *data = |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
697 | jabber_data_find_remote_by_cid(cid); |
|
26711
07cfe1520055
Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents:
26687
diff
changeset
|
698 | /* if data is already known, we write it immediatly */ |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
699 | if (data) { |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
700 | purple_debug_info("jabber", |
|
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
701 | "data is already known\n"); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
702 | purple_conv_custom_smiley_write(conv, alt, |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
703 | jabber_data_get_data(data), |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
704 | jabber_data_get_size(data)); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
705 | purple_conv_custom_smiley_close(conv, alt); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
706 | } else { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
707 | /* we need to request the smiley (data) */ |
|
24257
d6402f066933
Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <malu@pidgin.im>
parents:
24254
diff
changeset
|
708 | purple_debug_info("jabber", |
|
d6402f066933
Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <malu@pidgin.im>
parents:
24254
diff
changeset
|
709 | "data is unknown, need to request it\n"); |
|
27749
f9c5a1a95204
Remove a superfluous variable.
Paul Aurich <darkrain42@pidgin.im>
parents:
27748
diff
changeset
|
710 | jabber_message_send_data_request(js, conv, cid, from, |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
711 | alt); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
712 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
713 | } |
|
24387
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
714 | g_free(ref->cid); |
|
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
715 | g_free(ref->alt); |
|
cba0cfba936e
Another memory leak fix. Also, keep a copy of the alt-text in
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24386
diff
changeset
|
716 | g_free(ref); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
717 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
718 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
719 | /* Convert all newlines to whitespace. Technically, even regular, non-XML HTML is supposed to ignore newlines, but Pidgin has, as convention |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
720 | * treated \n as a newline for compatibility with other protocols |
|
17328
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
721 | */ |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
722 | for (c = jm->xhtml; *c != '\0'; c++) { |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
723 | if (*c == '\n') |
|
17328
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
724 | *c = ' '; |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
725 | } |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
726 | } |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
727 | } else if(!strcmp(child->name, "active") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 728 | jm->chat_state = JM_STATE_ACTIVE; |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
729 | } else if(!strcmp(child->name, "composing") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 730 | jm->chat_state = JM_STATE_COMPOSING; |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
731 | } else if(!strcmp(child->name, "paused") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 732 | jm->chat_state = JM_STATE_PAUSED; |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
733 | } else if(!strcmp(child->name, "inactive") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 734 | jm->chat_state = JM_STATE_INACTIVE; |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
735 | } else if(!strcmp(child->name, "gone") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 736 | jm->chat_state = JM_STATE_GONE; |
|
17774
fdb76fddd16a
Implemented <required/> for x-data forms, simplified malloc/sprintf, message type headline is not a requirement for incoming PEP messages (it is just recommended to avoid offline message storage).
Andreas Monitzer <am@adiumx.com>
parents:
17768
diff
changeset
|
737 | } else if(!strcmp(child->name, "event") && !strcmp(xmlns,"http://jabber.org/protocol/pubsub#event")) { |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
738 | xmlnode *items; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
739 | jm->type = JABBER_MESSAGE_EVENT; |
|
17780
749862fd4a87
Fixed a few small mistakes I discovered while testing user mood in Adium.
Andreas Monitzer <am@adiumx.com>
parents:
17779
diff
changeset
|
740 | for(items = xmlnode_get_child(child,"items"); items; items = items->next) |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
741 | jm->eventitems = g_list_append(jm->eventitems, items); |
|
28979
191942cc7747
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents:
28832
diff
changeset
|
742 | } else if(!strcmp(child->name, "attention") && !strcmp(xmlns, NS_ATTENTION)) { |
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
743 | jm->hasBuzz = TRUE; |
|
28996
8296bccbfd50
jabber: Delayed Delivery namespaces
Paul Aurich <darkrain42@pidgin.im>
parents:
28984
diff
changeset
|
744 | } else if(!strcmp(child->name, "delay") && !strcmp(xmlns, NS_DELAYED_DELIVERY)) { |
|
17811
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
745 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
746 | jm->delayed = TRUE; |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
747 | if(timestamp) |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
748 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 749 | } else if(!strcmp(child->name, "x")) { |
|
28996
8296bccbfd50
jabber: Delayed Delivery namespaces
Paul Aurich <darkrain42@pidgin.im>
parents:
28984
diff
changeset
|
750 | if(!strcmp(xmlns, NS_DELAYED_DELIVERY_LEGACY)) { |
|
27434
7d8b32345d10
disapproval of revision '0c1545afc98299c6d7004554eb7443091d42e8ca'
Paul Aurich <darkrain42@pidgin.im>
parents:
27431
diff
changeset
|
751 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); |
|
7d8b32345d10
disapproval of revision '0c1545afc98299c6d7004554eb7443091d42e8ca'
Paul Aurich <darkrain42@pidgin.im>
parents:
27431
diff
changeset
|
752 | jm->delayed = TRUE; |
|
7d8b32345d10
disapproval of revision '0c1545afc98299c6d7004554eb7443091d42e8ca'
Paul Aurich <darkrain42@pidgin.im>
parents:
27431
diff
changeset
|
753 | if(timestamp) |
|
7d8b32345d10
disapproval of revision '0c1545afc98299c6d7004554eb7443091d42e8ca'
Paul Aurich <darkrain42@pidgin.im>
parents:
27431
diff
changeset
|
754 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
|
7d8b32345d10
disapproval of revision '0c1545afc98299c6d7004554eb7443091d42e8ca'
Paul Aurich <darkrain42@pidgin.im>
parents:
27431
diff
changeset
|
755 | } else if(!strcmp(xmlns, "jabber:x:conference") && |
| 11230 | 756 | jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE && |
| 757 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 758 | const char *jid = xmlnode_get_attrib(child, "jid"); |
| 759 | if(jid) { | |
|
28703
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
760 | const char *reason = xmlnode_get_attrib(child, "reason"); |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
761 | const char *password = xmlnode_get_attrib(child, "password"); |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
762 | |
| 7014 | 763 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; |
| 764 | g_free(jm->to); | |
| 765 | jm->to = g_strdup(jid); | |
|
28703
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
766 | |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
767 | if (reason) { |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
768 | g_free(jm->body); |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
769 | jm->body = g_strdup(reason); |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
770 | } |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
771 | |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
772 | if (password) { |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
773 | g_free(jm->password); |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
774 | jm->password = g_strdup(password); |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
775 | } |
| 7014 | 776 | } |
|
25154
492b9d6b48a5
Remove a double call to xmlnode_get_namespace and multiple tests for xmlns
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
24800
diff
changeset
|
777 | } else if(!strcmp(xmlns, "http://jabber.org/protocol/muc#user") && |
| 11230 | 778 | jm->type != JABBER_MESSAGE_ERROR) { |
| 7014 | 779 | xmlnode *invite = xmlnode_get_child(child, "invite"); |
| 780 | if(invite) { | |
| 781 | xmlnode *reason, *password; | |
| 7968 | 782 | const char *jid = xmlnode_get_attrib(invite, "from"); |
| 7014 | 783 | g_free(jm->to); |
| 784 | jm->to = jm->from; | |
| 785 | jm->from = g_strdup(jid); | |
| 786 | if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 787 | g_free(jm->body); | |
| 788 | jm->body = xmlnode_get_data(reason); | |
| 789 | } | |
|
28703
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
790 | if((password = xmlnode_get_child(child, "password"))) { |
|
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
791 | g_free(jm->password); |
| 7014 | 792 | jm->password = xmlnode_get_data(password); |
|
28703
521344e75710
jabber: Improved support for XEP-0249 (and document the legacy stuff).
Paul Aurich <darkrain42@pidgin.im>
parents:
28534
diff
changeset
|
793 | } |
| 7014 | 794 | |
| 795 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 796 | } | |
| 7145 | 797 | } else { |
| 798 | jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 799 | } |
|
26871
d62964222795
Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents:
26867
diff
changeset
|
800 | } else if (g_str_equal(child->name, "query")) { |
|
d62964222795
Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents:
26867
diff
changeset
|
801 | const char *node = xmlnode_get_attrib(child, "node"); |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28979
diff
changeset
|
802 | if (purple_strequal(xmlns, NS_DISCO_ITEMS) |
|
26871
d62964222795
Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents:
26867
diff
changeset
|
803 | && purple_strequal(node, "http://jabber.org/protocol/commands")) { |
|
d62964222795
Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents:
26867
diff
changeset
|
804 | jabber_adhoc_got_list(js, jm->from, child); |
|
d62964222795
Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents:
26867
diff
changeset
|
805 | } |
| 7014 | 806 | } |
| 807 | } | |
| 808 | ||
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
809 | if(jm->hasBuzz) |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
810 | handle_buzz(jm); |
| 7014 | 811 | |
| 812 | switch(jm->type) { | |
|
27900
23b6b4dfeb82
Allow fallback for broken XMPP <message/> types. Closes #7837.
Paul Aurich <darkrain42@pidgin.im>
parents:
27844
diff
changeset
|
813 | case JABBER_MESSAGE_OTHER: |
|
28828
7c1855f037e7
jabber: Convert to purple_debug_* convenience functions.
Paul Aurich <darkrain42@pidgin.im>
parents:
28726
diff
changeset
|
814 | purple_debug_info("jabber", |
|
27900
23b6b4dfeb82
Allow fallback for broken XMPP <message/> types. Closes #7837.
Paul Aurich <darkrain42@pidgin.im>
parents:
27844
diff
changeset
|
815 | "Received message of unknown type: %s\n", type); |
|
23b6b4dfeb82
Allow fallback for broken XMPP <message/> types. Closes #7837.
Paul Aurich <darkrain42@pidgin.im>
parents:
27844
diff
changeset
|
816 | /* Fall-through is intentional */ |
| 7014 | 817 | case JABBER_MESSAGE_NORMAL: |
| 818 | case JABBER_MESSAGE_CHAT: | |
| 7145 | 819 | handle_chat(jm); |
| 820 | break; | |
| 7014 | 821 | case JABBER_MESSAGE_HEADLINE: |
| 7145 | 822 | handle_headline(jm); |
| 7014 | 823 | break; |
| 824 | case JABBER_MESSAGE_GROUPCHAT: | |
| 825 | handle_groupchat(jm); | |
| 826 | break; | |
| 827 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 828 | handle_groupchat_invite(jm); | |
| 829 | break; | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
830 | case JABBER_MESSAGE_EVENT: |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
831 | jabber_handle_event(jm); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
832 | break; |
| 7014 | 833 | case JABBER_MESSAGE_ERROR: |
| 834 | handle_error(jm); | |
| 835 | break; | |
| 836 | } | |
| 837 | jabber_message_free(jm); | |
| 838 | } | |
| 839 | ||
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
840 | static const gchar * |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
841 | jabber_message_get_mimetype_from_ext(const gchar *ext) |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
842 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
843 | if (strcmp(ext, "png") == 0) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
844 | return "image/png"; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
845 | } else if (strcmp(ext, "gif") == 0) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
846 | return "image/gif"; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
847 | } else if (strcmp(ext, "jpg") == 0) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
848 | return "image/jpeg"; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
849 | } else if (strcmp(ext, "tif") == 0) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
850 | return "image/tif"; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
851 | } else { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
852 | return "image/x-icon"; /* or something... */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
853 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
854 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
855 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
856 | static GList * |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
857 | jabber_message_xhtml_find_smileys(const char *xhtml) |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
858 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
859 | GList *smileys = purple_smileys_get_all(); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
860 | GList *found_smileys = NULL; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
861 | |
|
23628
3d540eeb2e74
Ooops ... compile\!
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23627
diff
changeset
|
862 | for (; smileys ; smileys = g_list_delete_link(smileys, smileys)) { |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
863 | PurpleSmiley *smiley = (PurpleSmiley *) smileys->data; |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
864 | |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
865 | const gchar *shortcut = purple_smiley_get_shortcut(smiley); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
866 | const gssize len = strlen(shortcut); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
867 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
868 | gchar *escaped = g_markup_escape_text(shortcut, len); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
869 | const char *pos = strstr(xhtml, escaped); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
870 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
871 | if (pos) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
872 | found_smileys = g_list_append(found_smileys, smiley); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
873 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
874 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
875 | g_free(escaped); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
876 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
877 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
878 | return found_smileys; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
879 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
880 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
881 | static gchar * |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
882 | jabber_message_get_smileyfied_xhtml(const gchar *xhtml, const GList *smileys) |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
883 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
884 | /* create XML element for all smileys (img tags) */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
885 | GString *result = g_string_new(NULL); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
886 | int pos = 0; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
887 | int length = strlen(xhtml); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
888 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
889 | while (pos < length) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
890 | const GList *iterator; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
891 | gboolean found_smiley = FALSE; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
892 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
893 | for (iterator = smileys ; iterator ; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
894 | iterator = g_list_next(iterator)) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
895 | const PurpleSmiley *smiley = (PurpleSmiley *) iterator->data; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
896 | const gchar *shortcut = purple_smiley_get_shortcut(smiley); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
897 | const gssize len = strlen(shortcut); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
898 | gchar *escaped = g_markup_escape_text(shortcut, len); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
899 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
900 | if (g_str_has_prefix(&(xhtml[pos]), escaped)) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
901 | /* we found the current smiley at this position */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
902 | const JabberData *data = |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
903 | jabber_data_find_local_by_alt(shortcut); |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
904 | xmlnode *img = jabber_data_get_xhtml_im(data, shortcut); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
905 | int len; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
906 | gchar *img_text = xmlnode_to_str(img, &len); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
907 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
908 | found_smiley = TRUE; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
909 | result = g_string_append(result, img_text); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
910 | g_free(img_text); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
911 | pos += strlen(escaped); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
912 | g_free(escaped); |
|
24386
0710eb7a41c5
A couple of compile warning fixes, a couple of memory leak plugs.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
24259
diff
changeset
|
913 | xmlnode_free(img); |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
914 | break; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
915 | } else { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
916 | /* cleanup from the before the next round... */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
917 | g_free(escaped); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
918 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
919 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
920 | if (!found_smiley) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
921 | /* there was no smiley here, just copy one byte */ |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
922 | result = g_string_append_c(result, xhtml[pos]); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
923 | pos++; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
924 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
925 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
926 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
927 | return g_string_free(result, FALSE); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
928 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
929 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
930 | static gboolean |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
931 | jabber_conv_support_custom_smileys(const PurpleConnection *gc, |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
932 | PurpleConversation *conv, |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
933 | const gchar *who) |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
934 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
935 | JabberStream *js = (JabberStream *) gc->proto_data; |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
936 | JabberBuddy *jb; |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
937 | JabberChat *chat; |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
938 | |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
939 | if (!js) { |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
940 | purple_debug_error("jabber", |
|
24254
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
941 | "jabber_conv_support_custom_smileys: could not find stream\n"); |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
942 | return FALSE; |
|
2d990726bf92
Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents:
23628
diff
changeset
|
943 | } |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
944 | |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
945 | switch (purple_conversation_get_type(conv)) { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
946 | case PURPLE_CONV_TYPE_IM: |
|
24789
ee944c10dab6
Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents:
24672
diff
changeset
|
947 | jb = jabber_buddy_find(js, who, FALSE); |
|
ee944c10dab6
Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents:
24672
diff
changeset
|
948 | if (jb) { |
|
28979
191942cc7747
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents:
28832
diff
changeset
|
949 | return jabber_buddy_has_capability(jb, NS_BOB); |
|
24789
ee944c10dab6
Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents:
24672
diff
changeset
|
950 | } else { |
|
24800
09769f68ea8a
Whoops, should return FALSE, not NULL, when jabber_buddy_find returns NULL
Marcus Lundblad <malu@pidgin.im>
parents:
24789
diff
changeset
|
951 | return FALSE; |
|
24789
ee944c10dab6
Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents:
24672
diff
changeset
|
952 | } |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
953 | break; |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
954 | case PURPLE_CONV_TYPE_CHAT: |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
955 | chat = jabber_chat_find_by_conv(conv); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
956 | if (chat) { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
957 | /* do not attempt to send custom smileys in a MUC with more than |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
958 | 10 people, to avoid getting too many BoB requests */ |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
959 | return jabber_chat_get_num_participants(chat) <= 10 && |
|
27155
53502d71efdd
Remove trailing whitespace that has snuck in.
Paul Aurich <darkrain42@pidgin.im>
parents:
27131
diff
changeset
|
960 | jabber_chat_all_participants_have_capability(chat, |
|
28979
191942cc7747
jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <darkrain42@pidgin.im>
parents:
28832
diff
changeset
|
961 | NS_BOB); |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
962 | } else { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
963 | return FALSE; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
964 | } |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
965 | break; |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
966 | default: |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
967 | return FALSE; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
968 | break; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
969 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
970 | } |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
971 | |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
972 | static char * |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
973 | jabber_message_smileyfy_xhtml(JabberMessage *jm, const char *xhtml) |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
974 | { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
975 | PurpleAccount *account = purple_connection_get_account(jm->js->gc); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
976 | PurpleConversation *conv = |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
977 | purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, jm->to, |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
978 | account); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
979 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
980 | if (jabber_conv_support_custom_smileys(jm->js->gc, conv, jm->to)) { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
981 | GList *found_smileys = jabber_message_xhtml_find_smileys(xhtml); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
982 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
983 | if (found_smileys) { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
984 | gchar *smileyfied_xhtml = NULL; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
985 | const GList *iterator; |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
986 | GList *valid_smileys = NULL; |
|
29270
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
987 | gboolean has_too_large_smiley = FALSE; |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
988 | |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
989 | for (iterator = found_smileys; iterator ; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
990 | iterator = g_list_next(iterator)) { |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
991 | PurpleSmiley *smiley = (PurpleSmiley *) iterator->data; |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
992 | const gchar *shortcut = purple_smiley_get_shortcut(smiley); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
993 | const JabberData *data = |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
994 | jabber_data_find_local_by_alt(shortcut); |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
995 | PurpleStoredImage *image = purple_smiley_get_stored_image(smiley); |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
996 | |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
997 | if (purple_imgstore_get_size(image) <= JABBER_DATA_MAX_SIZE) { |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
998 | /* the object has not been sent before */ |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
999 | if (!data) { |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1000 | const gchar *ext = purple_imgstore_get_extension(image); |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1001 | JabberStream *js = jm->js; |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1002 | |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1003 | JabberData *new_data = |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1004 | jabber_data_create_from_data(purple_imgstore_get_data(image), |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1005 | purple_imgstore_get_size(image), |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1006 | jabber_message_get_mimetype_from_ext(ext), js); |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1007 | purple_debug_info("jabber", |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1008 | "cache local smiley alt = %s, cid = %s\n", |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1009 | shortcut, jabber_data_get_cid(new_data)); |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1010 | jabber_data_associate_local(new_data, shortcut); |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1011 | } |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1012 | valid_smileys = g_list_append(valid_smileys, smiley); |
|
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1013 | } else { |
|
29270
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
1014 | has_too_large_smiley = TRUE; |
|
29277
ff5a56fae229
jabber: Log a warning (with the shortcut) when refusing to send a smiley.
Paul Aurich <darkrain42@pidgin.im>
parents:
29270
diff
changeset
|
1015 | purple_debug_warning("jabber", "Refusing to send smiley %s " |
|
ff5a56fae229
jabber: Log a warning (with the shortcut) when refusing to send a smiley.
Paul Aurich <darkrain42@pidgin.im>
parents:
29270
diff
changeset
|
1016 | "(too large, max is %d)\n", |
|
ff5a56fae229
jabber: Log a warning (with the shortcut) when refusing to send a smiley.
Paul Aurich <darkrain42@pidgin.im>
parents:
29270
diff
changeset
|
1017 | purple_smiley_get_shortcut(smiley), |
|
ff5a56fae229
jabber: Log a warning (with the shortcut) when refusing to send a smiley.
Paul Aurich <darkrain42@pidgin.im>
parents:
29270
diff
changeset
|
1018 | JABBER_DATA_MAX_SIZE); |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1019 | } |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1020 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1021 | |
|
29270
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
1022 | if (has_too_large_smiley) { |
|
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
1023 | purple_conversation_write(conv, NULL, |
|
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
1024 | _("A custom smiley in the message is too large to send."), |
|
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
1025 | PURPLE_MESSAGE_ERROR, time(NULL)); |
|
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
1026 | } |
|
642d7a9e5f0a
jabber: Don't print the smiley shortcut in the error message when trying to
Marcus Lundblad <malu@pidgin.im>
parents:
29269
diff
changeset
|
1027 | |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1028 | smileyfied_xhtml = |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1029 | jabber_message_get_smileyfied_xhtml(xhtml, valid_smileys); |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1030 | g_list_free(found_smileys); |
|
29269
8145c8ab4935
jabber: Don't send custom smileys larger than the recommended maximum BoB size
Marcus Lundblad <malu@pidgin.im>
parents:
29229
diff
changeset
|
1031 | g_list_free(valid_smileys); |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1032 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1033 | return smileyfied_xhtml; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1034 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1035 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1036 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1037 | return NULL; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1038 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1039 | |
| 7014 | 1040 | void jabber_message_send(JabberMessage *jm) |
| 1041 | { | |
| 1042 | xmlnode *message, *child; | |
| 1043 | const char *type = NULL; | |
| 1044 | ||
| 1045 | message = xmlnode_new("message"); | |
| 1046 | ||
| 1047 | switch(jm->type) { | |
| 1048 | case JABBER_MESSAGE_NORMAL: | |
| 1049 | type = "normal"; | |
| 1050 | break; | |
| 1051 | case JABBER_MESSAGE_CHAT: | |
| 1052 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 1053 | type = "chat"; | |
| 1054 | break; | |
| 1055 | case JABBER_MESSAGE_HEADLINE: | |
| 1056 | type = "headline"; | |
| 1057 | break; | |
| 1058 | case JABBER_MESSAGE_GROUPCHAT: | |
| 1059 | type = "groupchat"; | |
| 1060 | break; | |
| 1061 | case JABBER_MESSAGE_ERROR: | |
| 1062 | type = "error"; | |
| 1063 | break; | |
| 1064 | case JABBER_MESSAGE_OTHER: | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
1065 | default: |
| 7014 | 1066 | type = NULL; |
| 1067 | break; | |
| 1068 | } | |
| 1069 | ||
| 1070 | if(type) | |
| 1071 | xmlnode_set_attrib(message, "type", type); | |
|
26042
4dabdb5fe213
Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25983
diff
changeset
|
1072 | |
| 13484 | 1073 | if (jm->id) |
| 1074 | xmlnode_set_attrib(message, "id", jm->id); | |
| 7014 | 1075 | |
| 1076 | xmlnode_set_attrib(message, "to", jm->to); | |
| 1077 | ||
| 8400 | 1078 | if(jm->thread_id) { |
| 1079 | child = xmlnode_new_child(message, "thread"); | |
| 1080 | xmlnode_insert_data(child, jm->thread_id, -1); | |
| 1081 | } | |
| 1082 | ||
| 27432 | 1083 | child = NULL; |
| 1084 | switch(jm->chat_state) | |
| 1085 | { | |
| 1086 | case JM_STATE_ACTIVE: | |
| 1087 | child = xmlnode_new_child(message, "active"); | |
| 1088 | break; | |
| 1089 | case JM_STATE_COMPOSING: | |
| 1090 | child = xmlnode_new_child(message, "composing"); | |
| 1091 | break; | |
| 1092 | case JM_STATE_PAUSED: | |
| 1093 | child = xmlnode_new_child(message, "paused"); | |
| 1094 | break; | |
| 1095 | case JM_STATE_INACTIVE: | |
| 1096 | child = xmlnode_new_child(message, "inactive"); | |
| 1097 | break; | |
| 1098 | case JM_STATE_GONE: | |
| 1099 | child = xmlnode_new_child(message, "gone"); | |
| 1100 | break; | |
| 1101 | case JM_STATE_NONE: | |
| 1102 | /* yep, nothing */ | |
| 1103 | break; | |
| 7014 | 1104 | } |
| 27432 | 1105 | if(child) |
| 1106 | xmlnode_set_namespace(child, "http://jabber.org/protocol/chatstates"); | |
| 13708 | 1107 | |
| 7014 | 1108 | if(jm->subject) { |
| 1109 | child = xmlnode_new_child(message, "subject"); | |
| 1110 | xmlnode_insert_data(child, jm->subject, -1); | |
| 1111 | } | |
| 1112 | ||
| 1113 | if(jm->body) { | |
| 1114 | child = xmlnode_new_child(message, "body"); | |
| 1115 | xmlnode_insert_data(child, jm->body, -1); | |
| 1116 | } | |
| 1117 | ||
| 1118 | if(jm->xhtml) { | |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1119 | if ((child = xmlnode_from_str(jm->xhtml, -1))) { |
| 7014 | 1120 | xmlnode_insert_child(message, child); |
| 1121 | } else { | |
|
28828
7c1855f037e7
jabber: Convert to purple_debug_* convenience functions.
Paul Aurich <darkrain42@pidgin.im>
parents:
28726
diff
changeset
|
1122 | purple_debug_error("jabber", |
| 7014 | 1123 | "XHTML translation/validation failed, returning: %s\n", |
| 1124 | jm->xhtml); | |
| 1125 | } | |
| 1126 | } | |
| 1127 | ||
| 1128 | jabber_send(jm->js, message); | |
| 1129 | ||
| 1130 | xmlnode_free(message); | |
| 1131 | } | |
| 1132 | ||
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1133 | /* |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1134 | * Compare the XHTML and plain strings passed in for "equality". Any HTML markup |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1135 | * other than <br/> (matches a newline) in the XHTML will cause this to return |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1136 | * FALSE. |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1137 | */ |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1138 | static gboolean |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1139 | jabber_xhtml_plain_equal(const char *xhtml_escaped, |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1140 | const char *plain) |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1141 | { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1142 | int i = 0; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1143 | int j = 0; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1144 | gboolean ret; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1145 | char *xhtml = purple_unescape_html(xhtml_escaped); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1146 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1147 | while (xhtml[i] && plain[j]) { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1148 | if (xhtml[i] == plain[j]) { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1149 | i += 1; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1150 | j += 1; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1151 | continue; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1152 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1153 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1154 | if (plain[j] == '\n' && !strncmp(xhtml+i, "<br/>", 5)) { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1155 | i += 5; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1156 | j += 1; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1157 | continue; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1158 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1159 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1160 | g_free(xhtml); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1161 | return FALSE; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1162 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1163 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1164 | /* Are we at the end of both strings? */ |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1165 | ret = (xhtml[i] == plain[j]) && (xhtml[i] == '\0'); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1166 | g_free(xhtml); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1167 | return ret; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1168 | } |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1169 | |
| 15884 | 1170 | int jabber_message_send_im(PurpleConnection *gc, const char *who, const char *msg, |
| 1171 | PurpleMessageFlags flags) | |
| 7014 | 1172 | { |
| 1173 | JabberMessage *jm; | |
| 1174 | JabberBuddy *jb; | |
| 1175 | JabberBuddyResource *jbr; | |
| 7135 | 1176 | char *xhtml; |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1177 | char *tmp; |
| 7306 | 1178 | char *resource; |
| 7014 | 1179 | |
| 1180 | if(!who || !msg) | |
| 1181 | return 0; | |
| 1182 | ||
| 7306 | 1183 | resource = jabber_get_resource(who); |
| 1184 | ||
| 7014 | 1185 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); |
| 7306 | 1186 | jbr = jabber_buddy_find_resource(jb, resource); |
| 1187 | ||
| 1188 | g_free(resource); | |
| 7014 | 1189 | |
| 1190 | jm = g_new0(JabberMessage, 1); | |
| 1191 | jm->js = gc->proto_data; | |
| 1192 | jm->type = JABBER_MESSAGE_CHAT; | |
| 13708 | 1193 | jm->chat_state = JM_STATE_ACTIVE; |
| 7014 | 1194 | jm->to = g_strdup(who); |
| 13484 | 1195 | jm->id = jabber_get_next_id(jm->js); |
| 13708 | 1196 | |
| 1197 | if(jbr) { | |
| 1198 | if(jbr->thread_id) | |
| 1199 | jm->thread_id = jbr->thread_id; | |
| 1200 | ||
|
27429
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1201 | if (jbr->chat_states == JABBER_CHAT_STATES_UNSUPPORTED) |
|
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1202 | jm->chat_state = JM_STATE_NONE; |
|
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1203 | else { |
| 13708 | 1204 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) |
| 1205 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ | |
| 1206 | } | |
| 1207 | } | |
| 7014 | 1208 | |
|
27237
0643ac0e5658
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <darkrain42@pidgin.im>
parents:
27155
diff
changeset
|
1209 | tmp = purple_utf8_strip_unprintables(msg); |
|
0643ac0e5658
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <darkrain42@pidgin.im>
parents:
27155
diff
changeset
|
1210 | purple_markup_html_to_xhtml(tmp, &xhtml, &jm->body); |
|
0643ac0e5658
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <darkrain42@pidgin.im>
parents:
27155
diff
changeset
|
1211 | g_free(tmp); |
|
29229
1fd36e207795
jabber: Wrap XHTML-IM messages in <p/> for greater interoperability justice. Closes #11253
Paul Aurich <darkrain42@pidgin.im>
parents:
28996
diff
changeset
|
1212 | |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1213 | tmp = jabber_message_smileyfy_xhtml(jm, xhtml); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1214 | if (tmp) { |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1215 | g_free(xhtml); |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1216 | xhtml = tmp; |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1217 | } |
| 7014 | 1218 | |
|
27746
4b3f015977d9
For contacts who advertise Entity Caps, check for XHTML-IM support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1219 | /* |
|
4b3f015977d9
For contacts who advertise Entity Caps, check for XHTML-IM support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1220 | * For backward compatibility with user expectations or for those not on |
|
4b3f015977d9
For contacts who advertise Entity Caps, check for XHTML-IM support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1221 | * the user's roster, allow sending XHTML-IM markup. |
|
4b3f015977d9
For contacts who advertise Entity Caps, check for XHTML-IM support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1222 | */ |
|
4b3f015977d9
For contacts who advertise Entity Caps, check for XHTML-IM support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1223 | if (!jbr || !jbr->caps.info || |
|
28984
1d84517d56eb
jabber: More namespaces! This is a good stopping point for now.
Paul Aurich <darkrain42@pidgin.im>
parents:
28979
diff
changeset
|
1224 | jabber_resource_has_capability(jbr, NS_XHTML_IM)) { |
|
27746
4b3f015977d9
For contacts who advertise Entity Caps, check for XHTML-IM support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1225 | if (!jabber_xhtml_plain_equal(xhtml, jm->body)) |
|
29229
1fd36e207795
jabber: Wrap XHTML-IM messages in <p/> for greater interoperability justice. Closes #11253
Paul Aurich <darkrain42@pidgin.im>
parents:
28996
diff
changeset
|
1226 | /* Wrap the message in <p/> for great interoperability justice. */ |
|
1fd36e207795
jabber: Wrap XHTML-IM messages in <p/> for greater interoperability justice. Closes #11253
Paul Aurich <darkrain42@pidgin.im>
parents:
28996
diff
changeset
|
1227 | jm->xhtml = g_strdup_printf("<html xmlns='" NS_XHTML_IM "'><body xmlns='" NS_XHTML "'><p>%s</p></body></html>", xhtml); |
|
27746
4b3f015977d9
For contacts who advertise Entity Caps, check for XHTML-IM support. Refs #4650.
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1228 | } |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1229 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1230 | g_free(xhtml); |
| 7014 | 1231 | |
| 1232 | jabber_message_send(jm); | |
| 1233 | jabber_message_free(jm); | |
| 1234 | return 1; | |
| 1235 | } | |
| 1236 | ||
| 15884 | 1237 | int jabber_message_send_chat(PurpleConnection *gc, int id, const char *msg, PurpleMessageFlags flags) |
| 7014 | 1238 | { |
| 1239 | JabberChat *chat; | |
| 1240 | JabberMessage *jm; | |
| 8042 | 1241 | JabberStream *js; |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1242 | char *xhtml; |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
1243 | char *tmp; |
| 7014 | 1244 | |
| 8042 | 1245 | if(!msg || !gc) |
| 7014 | 1246 | return 0; |
| 1247 | ||
| 8042 | 1248 | js = gc->proto_data; |
| 7014 | 1249 | chat = jabber_chat_find_by_id(js, id); |
| 1250 | ||
| 8043 | 1251 | if(!chat) |
| 1252 | return 0; | |
| 1253 | ||
| 9130 | 1254 | jm = g_new0(JabberMessage, 1); |
| 1255 | jm->js = gc->proto_data; | |
| 1256 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 1257 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 13484 | 1258 | jm->id = jabber_get_next_id(jm->js); |
| 9130 | 1259 | |
|
27237
0643ac0e5658
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <darkrain42@pidgin.im>
parents:
27155
diff
changeset
|
1260 | tmp = purple_utf8_strip_unprintables(msg); |
|
28534
df58e9ce5eca
Oops, it helps to actually use the stripped message.
Paul Aurich <darkrain42@pidgin.im>
parents:
28442
diff
changeset
|
1261 | purple_markup_html_to_xhtml(tmp, &xhtml, &jm->body); |
|
27237
0643ac0e5658
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <darkrain42@pidgin.im>
parents:
27155
diff
changeset
|
1262 | g_free(tmp); |
|
27110
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
1263 | tmp = jabber_message_smileyfy_xhtml(jm, xhtml); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
1264 | if (tmp) { |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
1265 | g_free(xhtml); |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
1266 | xhtml = tmp; |
|
05ca719b901b
Support custom smileys in MUCs (when all participants support BoB and a maximum
Marcus Lundblad <malu@pidgin.im>
parents:
27103
diff
changeset
|
1267 | } |
| 8858 | 1268 | |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1269 | if (chat->xhtml && !jabber_xhtml_plain_equal(xhtml, jm->body)) |
|
29229
1fd36e207795
jabber: Wrap XHTML-IM messages in <p/> for greater interoperability justice. Closes #11253
Paul Aurich <darkrain42@pidgin.im>
parents:
28996
diff
changeset
|
1270 | /* Wrap the message in <p/> for greater interoperability justice. */ |
|
1fd36e207795
jabber: Wrap XHTML-IM messages in <p/> for greater interoperability justice. Closes #11253
Paul Aurich <darkrain42@pidgin.im>
parents:
28996
diff
changeset
|
1271 | jm->xhtml = g_strdup_printf("<html xmlns='" NS_XHTML_IM "'><body xmlns='" NS_XHTML "'><p>%s</p></body></html>", xhtml); |
|
27061
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1272 | |
|
b1bfbf77cf90
Only include XHTML payload in XMPP message when it's needed. Closes #8738.
Paul Aurich <darkrain42@pidgin.im>
parents:
26984
diff
changeset
|
1273 | g_free(xhtml); |
| 7923 | 1274 | |
| 9130 | 1275 | jabber_message_send(jm); |
| 1276 | jabber_message_free(jm); | |
| 1277 | ||
| 7014 | 1278 | return 1; |
| 1279 | } | |
| 1280 | ||
| 15884 | 1281 | unsigned int jabber_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) |
| 7014 | 1282 | { |
| 1283 | JabberMessage *jm; | |
| 1284 | JabberBuddy *jb; | |
| 1285 | JabberBuddyResource *jbr; | |
| 7306 | 1286 | char *resource = jabber_get_resource(who); |
| 7014 | 1287 | |
| 1288 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); | |
| 7306 | 1289 | jbr = jabber_buddy_find_resource(jb, resource); |
| 1290 | ||
| 1291 | g_free(resource); | |
| 7014 | 1292 | |
|
27748
2f3e6478093b
Fix reversed logic in 3313d7d749620e50714c8678ab078851d1592764.
Paul Aurich <darkrain42@pidgin.im>
parents:
27747
diff
changeset
|
1293 | if (!jbr || (jbr->chat_states == JABBER_CHAT_STATES_UNSUPPORTED)) |
| 7014 | 1294 | return 0; |
| 1295 | ||
| 13708 | 1296 | /* TODO: figure out threading */ |
| 7014 | 1297 | jm = g_new0(JabberMessage, 1); |
| 1298 | jm->js = gc->proto_data; | |
| 1299 | jm->type = JABBER_MESSAGE_CHAT; | |
| 1300 | jm->to = g_strdup(who); | |
| 13484 | 1301 | jm->id = jabber_get_next_id(jm->js); |
| 7014 | 1302 | |
| 15884 | 1303 | if(PURPLE_TYPING == state) |
| 13708 | 1304 | jm->chat_state = JM_STATE_COMPOSING; |
| 15884 | 1305 | else if(PURPLE_TYPED == state) |
| 13708 | 1306 | jm->chat_state = JM_STATE_PAUSED; |
| 1307 | else | |
| 1308 | jm->chat_state = JM_STATE_ACTIVE; | |
| 1309 | ||
|
27429
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1310 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) |
|
3313d7d74962
Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents:
27237
diff
changeset
|
1311 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ |
| 7014 | 1312 | |
| 1313 | jabber_message_send(jm); | |
| 1314 | jabber_message_free(jm); | |
| 1315 | ||
| 13708 | 1316 | return 0; |
| 7014 | 1317 | } |
| 1318 | ||
|
23586
e495a4623f76
Removing short-names for features and calculating own caps hash.
Tobias Markmann <tfar@soc.pidgin.im>
parents:
23249
diff
changeset
|
1319 | gboolean jabber_buzz_isenabled(JabberStream *js, const gchar *namespace) { |
|
17824
52683dfc1f7d
Added the option to enable/disable buzz via a status setting. It's default off for the pidgin folks.
Andreas Monitzer <am@adiumx.com>
parents:
17823
diff
changeset
|
1320 | return js->allowBuzz; |
|
52683dfc1f7d
Added the option to enable/disable buzz via a status setting. It's default off for the pidgin folks.
Andreas Monitzer <am@adiumx.com>
parents:
17823
diff
changeset
|
1321 | } |
|
52683dfc1f7d
Added the option to enable/disable buzz via a status setting. It's default off for the pidgin folks.
Andreas Monitzer <am@adiumx.com>
parents:
17823
diff
changeset
|
1322 | |
|
24715
69aaae59e205
Fix compilation errors and many warnings
Paul Aurich <darkrain42@pidgin.im>
parents:
24714
diff
changeset
|
1323 | gboolean jabber_custom_smileys_isenabled(JabberStream *js, const gchar *namespace) |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
1324 | { |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
1325 | const PurpleConnection *gc = js->gc; |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
1326 | PurpleAccount *account = purple_connection_get_account(gc); |
|
23627
dbdc407798af
A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
23626
diff
changeset
|
1327 | |
|
23626
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
1328 | return purple_account_get_bool(account, "custom_smileys", TRUE); |
|
e21afec2f485
Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents:
23249
diff
changeset
|
1329 | } |