libpurple/protocols/jabber/message.c

Sun, 03 May 2009 19:53:53 +0000

author
Paul Aurich <darkrain42@pidgin.im>
date
Sun, 03 May 2009 19:53:53 +0000
changeset 27027
f3129efa65ea
parent 26984
4d7014f1317d
child 27061
b1bfbf77cf90
permissions
-rw-r--r--

Add ability to list roles/affiliations in a chat via slash-commands and
modify roles/affiliations of multiple users at a time. Closes #5649.

Slightly modified patch from Andrei Mozzhuhin. The multiple-user support
is inefficient; all the changes can go in one stanza. We should also
actually track roles/affiliations of members since ejabberd's MUC won't
respond to the list query for a non-admin.

7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
2 * purple - Jabber Protocol Plugin
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * 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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "debug.h"
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "notify.h"
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "server.h"
7095
17d2b54254f8 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
26 #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
27 #include "adhoccommands.h"
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 #include "buddy.h"
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "chat.h"
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
30 #include "data.h"
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
31 #include "google.h"
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 #include "message.h"
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 #include "xmlnode.h"
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents: 17351
diff changeset
34 #include "pep.h"
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
35 #include "smiley.h"
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
36 #include "iq.h"
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
37
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
38 #include <string.h>
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 void jabber_message_free(JabberMessage *jm)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 {
15980
77057c4f658a Minor code cleanup
Mark Doliner <markdoliner@pidgin.im>
parents: 15884
diff changeset
42 g_free(jm->from);
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
43 g_free(jm->to);
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
44 g_free(jm->id);
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
45 g_free(jm->subject);
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
46 g_free(jm->body);
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
47 g_free(jm->xhtml);
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
48 g_free(jm->password);
20057
728a7dce565e grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents: 19917
diff changeset
49 g_free(jm->error);
728a7dce565e grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents: 19917
diff changeset
50 g_free(jm->thread_id);
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
51 g_list_free(jm->etc);
20057
728a7dce565e grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents: 19917
diff changeset
52 g_list_free(jm->eventitems);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 g_free(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
57 static void handle_chat(JabberMessage *jm)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 JabberID *jid = jabber_id_new(jm->from);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 char *from;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 JabberBuddy *jb;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 JabberBuddyResource *jbr;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
65 if(!jid)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
66 return;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
67
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 jb = jabber_buddy_find(jm->js, jm->from, TRUE);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
69 jbr = jabber_buddy_find_resource(jb, jid->resource);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70
8043
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
71 if(jabber_find_unnormalized_conv(jm->from, jm->js->gc->account)) {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 from = g_strdup(jm->from);
7258
7f4af419b0b3 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
73 } else if(jid->node) {
10490
72932e32f29d [gaim-migrate @ 11780]
Nathan Walp <nwalp@pidgin.im>
parents: 9762
diff changeset
74 if(jid->resource) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
75 PurpleConversation *conv;
7258
7f4af419b0b3 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
76
10490
72932e32f29d [gaim-migrate @ 11780]
Nathan Walp <nwalp@pidgin.im>
parents: 9762
diff changeset
77 from = g_strdup_printf("%s@%s", jid->node, jid->domain);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
78 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, jm->js->gc->account);
10490
72932e32f29d [gaim-migrate @ 11780]
Nathan Walp <nwalp@pidgin.im>
parents: 9762
diff changeset
79 if(conv) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
80 purple_conversation_set_name(conv, jm->from);
13304
4ad9297570d2 [gaim-migrate @ 15669]
Sean Egan <seanegan@pidgin.im>
parents: 13120
diff changeset
81 }
10490
72932e32f29d [gaim-migrate @ 11780]
Nathan Walp <nwalp@pidgin.im>
parents: 9762
diff changeset
82 g_free(from);
72932e32f29d [gaim-migrate @ 11780]
Nathan Walp <nwalp@pidgin.im>
parents: 9762
diff changeset
83 }
7258
7f4af419b0b3 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
84 from = g_strdup(jm->from);
7f4af419b0b3 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
85 } else {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 from = g_strdup(jid->domain);
7258
7f4af419b0b3 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
87 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 if(!jm->xhtml && !jm->body) {
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
90 if(JM_STATE_COMPOSING == jm->chat_state) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
91 serv_got_typing(jm->js->gc, 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
92 } else if(JM_STATE_PAUSED == jm->chat_state) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
93 serv_got_typing(jm->js->gc, 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
94 } else if(JM_STATE_GONE == jm->chat_state) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
95 PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
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
96 from, jm->js->gc->account);
15721
8b054202d398 Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents: 15710
diff changeset
97 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
98 char buf[256];
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
99 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
100
8b054202d398 Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents: 15710
diff changeset
101 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
102
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
103 if ((buddy = purple_find_buddy(jm->js->gc->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
104 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
105 char *escaped;
8b054202d398 Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents: 15710
diff changeset
106
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
107 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
108 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
109
8b054202d398 Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents: 15710
diff changeset
110 g_snprintf(buf, sizeof(buf),
16946
6ca2bb9f6039 New string
Sean Egan <seanegan@pidgin.im>
parents: 16799
diff changeset
111 _("%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
112 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
113
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
114 /* 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
115 * 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
116 * user from the conversation like we do with chats now. */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
117 purple_conversation_write(conv, "", buf,
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
118 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
119 }
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
120 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 serv_got_typing_stopped(jm->js->gc, 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
122
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
123 } else {
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
124 serv_got_typing_stopped(jm->js->gc, from);
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
125 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 } else {
8400
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
127 if(jbr) {
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
128 if(JM_TS_JEP_0085 == (jm->typing_style & JM_TS_JEP_0085)) {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
129 jbr->chat_states = JABBER_CHAT_STATES_SUPPORTED;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
130 } else {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
131 jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
132 }
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
133
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
134 if(JM_TS_JEP_0022 == (jm->typing_style & JM_TS_JEP_0022)) {
8400
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
135 jbr->capabilities |= JABBER_CAP_COMPOSING;
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
136 }
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
137
8400
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
138 if(jbr->thread_id)
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
139 g_free(jbr->thread_id);
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
140 jbr->thread_id = g_strdup(jbr->thread_id);
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
141 }
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25983
diff changeset
142
15587
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
143 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
144 char *tmp = jm->body;
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
145 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
146 g_free(tmp);
cbedd543bfae Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
147 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 serv_got_im(jm->js->gc, from, jm->xhtml ? jm->xhtml : jm->body, 0,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 jm->sent);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
152
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 g_free(from);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 jabber_id_free(jid);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
157 static void handle_headline(JabberMessage *jm)
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
158 {
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
159 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
160 GString *body;
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
161 GList *etc;
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
162
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 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
164 return; /* ignore headlines without any content */
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
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 body = g_string_new("");
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
167 title = g_strdup_printf(_("Message from %s"), jm->from);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
168
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
169 if(jm->xhtml)
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
170 g_string_append(body, jm->xhtml);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
171 else if(jm->body)
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
172 g_string_append(body, jm->body);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
173
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
174 for(etc = jm->etc; etc; etc = etc->next) {
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
175 xmlnode *x = etc->data;
13808
411ee56da344 [gaim-migrate @ 16229]
Sean Egan <seanegan@pidgin.im>
parents: 13766
diff changeset
176 const char *xmlns = xmlnode_get_namespace(x);
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
177 if(xmlns && !strcmp(xmlns, "jabber:x:oob")) {
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
178 xmlnode *url, *desc;
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
179 char *urltxt, *desctxt;
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
180
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
181 url = xmlnode_get_child(x, "url");
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
182 desc = xmlnode_get_child(x, "desc");
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
183
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
184 if(!url || !desc)
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
185 continue;
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
186
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
187 urltxt = xmlnode_get_data(url);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
188 desctxt = xmlnode_get_data(desc);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
189
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
190 /* I'm all about ugly hacks */
14790
a0226bec3707 [gaim-migrate @ 17484]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 14254
diff changeset
191 if(body->len && jm->body && !strcmp(body->str, jm->body))
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
192 g_string_printf(body, "<a href='%s'>%s</a>",
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
193 urltxt, desctxt);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
194 else
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
195 g_string_append_printf(body, "<br/><a href='%s'>%s</a>",
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
196 urltxt, desctxt);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
197
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
198 g_free(urltxt);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
199 g_free(desctxt);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
200 }
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
201 }
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
202
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
203 purple_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title,
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
204 NULL, body->str, NULL, NULL);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
205
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
206 g_free(title);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
207 g_string_free(body, TRUE);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
208 }
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
209
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
210 static void handle_groupchat(JabberMessage *jm)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 JabberID *jid = jabber_id_new(jm->from);
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
213 JabberChat *chat;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
214
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
215 if(!jid)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
216 return;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
217
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
218 chat = jabber_chat_find(jm->js, jid->node, jid->domain);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 if(!chat)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 return;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222
7971
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
223 if(jm->subject) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
224 purple_conv_chat_set_topic(PURPLE_CONV_CHAT(chat->conv), jid->resource,
7183
ee17c7833501 [gaim-migrate @ 7751]
Nathan Walp <nwalp@pidgin.im>
parents: 7145
diff changeset
225 jm->subject);
7971
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
226 if(!jm->xhtml && !jm->body) {
9762
125f77c00102 [gaim-migrate @ 10630]
Tim Ringenbach <marv@pidgin.im>
parents: 9584
diff changeset
227 char *msg, *tmp, *tmp2;
10732
5e314ab498bf [gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents: 10607
diff changeset
228 tmp = g_markup_escape_text(jm->subject, -1);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
229 tmp2 = purple_markup_linkify(tmp);
7971
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
230 if(jid->resource)
9762
125f77c00102 [gaim-migrate @ 10630]
Tim Ringenbach <marv@pidgin.im>
parents: 9584
diff changeset
231 msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, tmp2);
7971
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
232 else
9762
125f77c00102 [gaim-migrate @ 10630]
Tim Ringenbach <marv@pidgin.im>
parents: 9584
diff changeset
233 msg = g_strdup_printf(_("The topic is: %s"), tmp2);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
234 purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", msg, PURPLE_MESSAGE_SYSTEM, jm->sent);
9762
125f77c00102 [gaim-migrate @ 10630]
Tim Ringenbach <marv@pidgin.im>
parents: 9584
diff changeset
235 g_free(tmp);
125f77c00102 [gaim-migrate @ 10630]
Tim Ringenbach <marv@pidgin.im>
parents: 9584
diff changeset
236 g_free(tmp2);
7971
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
237 g_free(msg);
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
238 }
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
239 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240
7630
23e09fd7cbeb [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
241 if(jm->xhtml || jm->body) {
23e09fd7cbeb [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
242 if(jid->resource)
9584
1a6198375303 [gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents: 9130
diff changeset
243 serv_got_chat_in(jm->js->gc, chat->id, jid->resource,
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
244 jm->delayed ? PURPLE_MESSAGE_DELAYED : 0,
7630
23e09fd7cbeb [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
245 jm->xhtml ? jm->xhtml : jm->body, jm->sent);
23e09fd7cbeb [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
246 else if(chat->muc)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
247 purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "",
7630
23e09fd7cbeb [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
248 jm->xhtml ? jm->xhtml : jm->body,
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
249 PURPLE_MESSAGE_SYSTEM, jm->sent);
7630
23e09fd7cbeb [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
250 }
23e09fd7cbeb [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
251
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 jabber_id_free(jid);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
255 static void handle_groupchat_invite(JabberMessage *jm)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 {
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
257 GHashTable *components;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 JabberID *jid = jabber_id_new(jm->to);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
260 if(!jid)
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
261 return;
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
262
15598
834a88c83e95 Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents: 15587
diff changeset
263 components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
7310
1346a99cba40 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
264
15598
834a88c83e95 Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents: 15587
diff changeset
265 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
266 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
267 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
268 g_hash_table_replace(components, "password", g_strdup(jm->password));
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 jabber_id_free(jid);
10774
f4238d6312ff [gaim-migrate @ 12383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10732
diff changeset
271 serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
274 static void handle_error(JabberMessage *jm)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 char *buf;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 if(!jm->body)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 return;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281 buf = g_strdup_printf(_("Message delivery to %s failed: %s"),
13766
6b92ce47f7e5 [gaim-migrate @ 16176]
Daniel Atallah <datallah@pidgin.im>
parents: 13708
diff changeset
282 jm->from, jm->error ? jm->error : "");
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283
16961
b6955f946f8f s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents: 16946
diff changeset
284 purple_notify_formatted(jm->js->gc, _("XMPP Message Error"), _("XMPP Message Error"), buf,
7944
619ec16df2c8 [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
285 jm->xhtml ? jm->xhtml : jm->body, NULL, NULL);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287 g_free(buf);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289
17822
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
290 static void handle_buzz(JabberMessage *jm) {
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
291 PurpleBuddy *buddy;
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
292 PurpleAccount *account;
25316
8b6461a2f967 Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents: 25154
diff changeset
293
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
294 /* 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
295 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
296 return;
25316
8b6461a2f967 Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents: 25154
diff changeset
297
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
298 /* 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
299 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
300 return;
25316
8b6461a2f967 Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents: 25154
diff changeset
301
17822
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
302 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
303
8b6461a2f967 Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents: 25154
diff changeset
304 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
305 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
306
25316
8b6461a2f967 Use purple_prpl_got_attention() for XMPP notifications
Evan Schoenberg <evands@pidgin.im>
parents: 25154
diff changeset
307 /* 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
308 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
309 }
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
310
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
311 /* 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
312 typedef struct {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
313 gchar *cid;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
314 gchar *alt;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
315 } JabberSmileyRef;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
316
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
317
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
318 static void
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
319 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
320 GHashTable *table)
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
321 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
322 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
323
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
324 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
325 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
326 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
327
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
328 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
329 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
330
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
331 /* 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
332 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
333 /* 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
334 gchar *temp_cid = g_strdup(cid);
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
335 JabberSmileyRef *ref = g_new0(JabberSmileyRef, 1);
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
336 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
337 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
338 /* 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
339 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
340 if (alt && alt[0] != '\0') {
24259
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
341 /* 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
342 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
343 as an mailto: link */
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
344 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
345 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
346 } else {
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
347 ref->alt = g_strdup(alt);
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
348 }
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
349 } else {
24258
9ae10fafad7a When receiving an <img/> without the "alt" attribute, set
Marcus Lundblad <malu@pidgin.im>
parents: 24257
diff changeset
350 ref->alt = g_strdup(src);
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
351 }
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
352 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
353 }
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
354 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
355 }
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25983
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 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
358 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
359 }
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
360 }
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
361
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
362 static gboolean
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
363 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
364 {
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
365 GList **refs = (GList **) user_data;
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
366 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
367
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
368 *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
369
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
370 return TRUE;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
371 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
372
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
373 static GList *
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
374 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
375 {
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
376 GList *refs = NULL;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
377 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
378
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
379 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
380 (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
381 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
382 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
383 return refs;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
384 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
385
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
386 static gchar *
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
387 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
388 {
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
389 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
390 int len = strlen(markup);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
391 int pos = 0;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
392 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
393
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
394 while (pos < len) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
395 /* 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
396 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
397 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
398 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
399 xmlnode *img = NULL;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
400 int pos2 = pos;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
401 const gchar *src;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
402
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
403 for (; pos2 < len ; pos2++) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
404 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
405 pos2 += 2;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
406 break;
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
407 } 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
408 pos2 += 5;
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
409 break;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
410 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
411 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
412
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
413 /* 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
414 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
415 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
416 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
417 text is copied unchanged */
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
418 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
419 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
420
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
421 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
422 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
423 /* 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
424 if (alt && alt[0] != '\0') {
24259
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
425 /* 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
426 this prevents linkification... */
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
427 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
428 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
429 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
430 g_free(safe_alt);
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
431 } else {
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
432 out = g_string_append(out, alt);
e69d72917038 Added a workaround for receiving smileys from Jabbim,
Marcus Lundblad <malu@pidgin.im>
parents: 24258
diff changeset
433 }
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
434 } else {
24258
9ae10fafad7a When receiving an <img/> without the "alt" attribute, set
Marcus Lundblad <malu@pidgin.im>
parents: 24257
diff changeset
435 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
436 }
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
437 pos += pos2 - pos;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
438 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
439 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
440 pos++;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
441 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
442
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
443 xmlnode_free(img);
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 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
446 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
447 pos++;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
448 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
449 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
450
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
451 g_free(markup);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
452 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
453 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
454
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
455 static void
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
456 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
457 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
458 xmlnode *data_tag;
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
459 for (data_tag = xmlnode_get_child_with_namespace(message, "data", XEP_0231_NAMESPACE) ;
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
460 data_tag ;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
461 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
462 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
463 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
464
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
465 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
466 /* 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
467 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
468 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
469 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
470 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
471 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
472
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
473 /* 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
474 smiley */
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
475 typedef struct {
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
476 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
477 gchar *alt;
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
478 } JabberDataRef;
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
479
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
480 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
481 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
482 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
483 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
484 {
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
485 JabberDataRef *ref = (JabberDataRef *) data;
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
486 PurpleConversation *conv = ref->conv;
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
487 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
488 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
489 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
490
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
491 /* did we get a data element as result? */
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
492 if (data_element) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
493 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
494
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
495 if (data) {
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
496 jabber_data_associate_remote(data);
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
497 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
498 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
499 jabber_data_get_size(data));
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
500 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
501 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
502
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
503 } 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
504 purple_debug_info("jabber",
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
505 "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
506 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
507 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
508 }
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
509 g_free(ref->alt);
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
510 g_free(ref);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
511 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
512
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
513 static void
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
514 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
515 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
516 const gchar *alt)
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
517 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
518 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
519 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
520 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
521
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
522 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
523 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
524 ref->alt = g_strdup(alt);
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
525 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
526 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
527
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
528 jabber_iq_send(request);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
529 }
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
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
532 void jabber_message_parse(JabberStream *js, xmlnode *packet)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
533 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
534 JabberMessage *jm;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
535 const char *type;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
536 xmlnode *child;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
537
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
538 jm = g_new0(JabberMessage, 1);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
539 jm->js = js;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
540 jm->sent = time(NULL);
9584
1a6198375303 [gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents: 9130
diff changeset
541 jm->delayed = FALSE;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
542
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
543 type = xmlnode_get_attrib(packet, "type");
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
544
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
545 if(type) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
546 if(!strcmp(type, "normal"))
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
547 jm->type = JABBER_MESSAGE_NORMAL;
20320
6337e101f6ab Plug some memory leaks.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19917
diff changeset
548 else if(!strcmp(type, "chat"))
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
549 jm->type = JABBER_MESSAGE_CHAT;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
550 else if(!strcmp(type, "groupchat"))
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
551 jm->type = JABBER_MESSAGE_GROUPCHAT;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
552 else if(!strcmp(type, "headline"))
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
553 jm->type = JABBER_MESSAGE_HEADLINE;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
554 else if(!strcmp(type, "error"))
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
555 jm->type = JABBER_MESSAGE_ERROR;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
556 else
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
557 jm->type = JABBER_MESSAGE_OTHER;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
558 } else {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
559 jm->type = JABBER_MESSAGE_NORMAL;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
560 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
561
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
562 jm->from = g_strdup(xmlnode_get_attrib(packet, "from"));
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
563 jm->to = g_strdup(xmlnode_get_attrib(packet, "to"));
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
564 jm->id = g_strdup(xmlnode_get_attrib(packet, "id"));
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
565
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
566 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
567 const char *xmlns = xmlnode_get_namespace(child);
8135
d4df7d1821a5 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
568 if(child->type != XMLNODE_TYPE_TAG)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
569 continue;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
570
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
571 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
572 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
573 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
574 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
575 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
576 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
577
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
578 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
579 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
580 }
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
581
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
582 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
583 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
584
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 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
586 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
587 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
588 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
589 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
590
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 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
592 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
593 } 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
594 /* 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
595 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
596 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
597 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
598 /* 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
599 continue;
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 } else if(!strcmp(child->name, "subject") && !strcmp(xmlns,"jabber:client")) {
26859
8175186cf34a Fix XMPP prpl->set_chat_topic with an empty string (or NULL)
Paul Aurich <darkrain42@pidgin.im>
parents: 26711
diff changeset
601 if(!jm->subject) {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
602 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
603 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
604 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
605 }
17792
d2023e27affd Fixed a bug that resulted in not being able to receive any messages.
Andreas Monitzer <am@adiumx.com>
parents: 17780
diff changeset
606 } else if(!strcmp(child->name, "thread") && !strcmp(xmlns,"jabber:client")) {
8400
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
607 if(!jm->thread_id)
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
608 jm->thread_id = xmlnode_get_data(child);
17792
d2023e27affd Fixed a bug that resulted in not being able to receive any messages.
Andreas Monitzer <am@adiumx.com>
parents: 17780
diff changeset
609 } else if(!strcmp(child->name, "body") && !strcmp(xmlns,"jabber:client")) {
13385
6fb64ae23761 [gaim-migrate @ 15757]
Nathan Walp <nwalp@pidgin.im>
parents: 13304
diff changeset
610 if(!jm->body) {
6fb64ae23761 [gaim-migrate @ 15757]
Nathan Walp <nwalp@pidgin.im>
parents: 13304
diff changeset
611 char *msg = xmlnode_to_str(child, NULL);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
612 jm->body = purple_strdup_withhtml(msg);
13385
6fb64ae23761 [gaim-migrate @ 15757]
Nathan Walp <nwalp@pidgin.im>
parents: 13304
diff changeset
613 g_free(msg);
6fb64ae23761 [gaim-migrate @ 15757]
Nathan Walp <nwalp@pidgin.im>
parents: 13304
diff changeset
614 }
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents: 17351
diff changeset
615 } else if(!strcmp(child->name, "html") && !strcmp(xmlns,"http://jabber.org/protocol/xhtml-im")) {
17328
7a5668fb7bad Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents: 16961
diff changeset
616 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
617 char *c;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
618
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
619 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
620 const gchar *who = xmlnode_get_attrib(packet, "from");
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
621 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
622 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
623 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
624 gchar *reformatted_xhtml;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
625
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
626 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
627 /* 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
628 occuring in the message */
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
629 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
630 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
631 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
632
26711
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
633 if (smiley_refs) {
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
634 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
635 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
636 JabberChat *chat = NULL;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
637
26711
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
638 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
639 chat = jabber_chat_find(js, jid->node, jid->domain);
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
640 if (chat) conv = chat->conv;
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
641 }
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
642
26711
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
643 jabber_id_free(jid);
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
644 } 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
645 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
646 conv =
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
647 purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY,
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
648 who, account);
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
649 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
650 /* we need to create the conversation here */
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
651 conv =
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
652 purple_conversation_new(PURPLE_CONV_TYPE_IM,
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
653 account, who);
07cfe1520055 Only pre-create a PurpleConversation (if there was none yet) if an incoming
Marcus Lundblad <malu@pidgin.im>
parents: 26687
diff changeset
654 }
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
655 }
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
656 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
657
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
658 /* process any newly provided smileys */
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
659 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
660 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
661
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
662 /* 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
663 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
664 /* 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
665 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
666 reformatted_xhtml =
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
667 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
668
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
669 jm->xhtml = reformatted_xhtml;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
670
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
671 /* 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
672 /* 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
673 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
674 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
675 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
676 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
677 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
678 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
679
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25983
diff changeset
680 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
681 "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
682 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
683 TRUE)) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
684 const JabberData *data =
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
685 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
686 /* 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
687 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
688 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
689 "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
690 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
691 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
692 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
693 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
694 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
695 /* 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
696 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
697 "data is unknown, need to request it\n");
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
698 jabber_message_send_data_request(js, conv, cid, who,
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
699 alt);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
700 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
701 }
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
702 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
703 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
704 g_free(ref);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
705 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
706
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
707 /* 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
708 * 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
709 */
7a5668fb7bad Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents: 16961
diff changeset
710 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
711 if (*c == '\n')
17328
7a5668fb7bad Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents: 16961
diff changeset
712 *c = ' ';
7a5668fb7bad Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents: 16961
diff changeset
713 }
7a5668fb7bad Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents: 16961
diff changeset
714 }
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents: 17351
diff changeset
715 } else if(!strcmp(child->name, "active") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
716 jm->chat_state = JM_STATE_ACTIVE;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
717 jm->typing_style |= JM_TS_JEP_0085;
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents: 17351
diff changeset
718 } else if(!strcmp(child->name, "composing") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
719 jm->chat_state = JM_STATE_COMPOSING;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
720 jm->typing_style |= JM_TS_JEP_0085;
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents: 17351
diff changeset
721 } else if(!strcmp(child->name, "paused") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
722 jm->chat_state = JM_STATE_PAUSED;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
723 jm->typing_style |= JM_TS_JEP_0085;
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents: 17351
diff changeset
724 } else if(!strcmp(child->name, "inactive") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
725 jm->chat_state = JM_STATE_INACTIVE;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
726 jm->typing_style |= JM_TS_JEP_0085;
17768
7be011945a1b added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents: 17351
diff changeset
727 } else if(!strcmp(child->name, "gone") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
728 jm->chat_state = JM_STATE_GONE;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
729 jm->typing_style |= JM_TS_JEP_0085;
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
730 } 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
731 xmlnode *items;
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17776
diff changeset
732 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
733 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
734 jm->eventitems = g_list_append(jm->eventitems, items);
24397
fc00edecac72 Updated to new namespace for XEP-0224.
Marcus Lundblad <malu@pidgin.im>
parents: 24387
diff changeset
735 } else if(!strcmp(child->name, "attention") && !strcmp(xmlns, XEP_0224_NAMESPACE)) {
17822
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
736 jm->hasBuzz = TRUE;
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
737 } else if(!strcmp(child->name, "delay") && !strcmp(xmlns,"urn:xmpp:delay")) {
17811
d9a7ec9277f6 Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents: 17792
diff changeset
738 const char *timestamp = xmlnode_get_attrib(child, "stamp");
d9a7ec9277f6 Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents: 17792
diff changeset
739 jm->delayed = TRUE;
d9a7ec9277f6 Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents: 17792
diff changeset
740 if(timestamp)
d9a7ec9277f6 Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents: 17792
diff changeset
741 jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
742 } else if(!strcmp(child->name, "x")) {
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
743 if(!strcmp(xmlns, "jabber:x:event")) {
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
744 if(xmlnode_get_child(child, "composing")) {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
745 if(jm->chat_state == JM_STATE_ACTIVE)
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
746 jm->chat_state = JM_STATE_COMPOSING;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
747 jm->typing_style |= JM_TS_JEP_0022;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
748 }
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
749 } else if(!strcmp(xmlns, "jabber:x:delay")) {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
750 const char *timestamp = xmlnode_get_attrib(child, "stamp");
9584
1a6198375303 [gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents: 9130
diff changeset
751 jm->delayed = TRUE;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
752 if(timestamp)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
753 jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL);
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
754 } else if(!strcmp(xmlns, "jabber:x:conference") &&
11230
a8f28f1058f6 [gaim-migrate @ 13370]
Nathan Walp <nwalp@pidgin.im>
parents: 10774
diff changeset
755 jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE &&
a8f28f1058f6 [gaim-migrate @ 13370]
Nathan Walp <nwalp@pidgin.im>
parents: 10774
diff changeset
756 jm->type != JABBER_MESSAGE_ERROR) {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
757 const char *jid = xmlnode_get_attrib(child, "jid");
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
758 if(jid) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
759 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
760 g_free(jm->to);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
761 jm->to = g_strdup(jid);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
762 }
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
763 } else if(!strcmp(xmlns, "http://jabber.org/protocol/muc#user") &&
11230
a8f28f1058f6 [gaim-migrate @ 13370]
Nathan Walp <nwalp@pidgin.im>
parents: 10774
diff changeset
764 jm->type != JABBER_MESSAGE_ERROR) {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
765 xmlnode *invite = xmlnode_get_child(child, "invite");
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
766 if(invite) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
767 xmlnode *reason, *password;
7968
900c163f8260 [gaim-migrate @ 8645]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
768 const char *jid = xmlnode_get_attrib(invite, "from");
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
769 g_free(jm->to);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
770 jm->to = jm->from;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
771 jm->from = g_strdup(jid);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
772 if((reason = xmlnode_get_child(invite, "reason"))) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
773 g_free(jm->body);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
774 jm->body = xmlnode_get_data(reason);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
775 }
11576
484149428832 [gaim-migrate @ 13845]
Etan Reisner <deryni@pidgin.im>
parents: 11230
diff changeset
776 if((password = xmlnode_get_child(child, "password")))
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
777 jm->password = xmlnode_get_data(password);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
778
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
779 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
780 }
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
781 } else {
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
782 jm->etc = g_list_append(jm->etc, child);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
783 }
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
784 } 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
785 const char *node = xmlnode_get_attrib(child, "node");
d62964222795 Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents: 26867
diff changeset
786 if (purple_strequal(xmlns, "http://jabber.org/protocol/disco#items")
d62964222795 Add a new signal which is emitted (after the account is connected) if the
Paul Aurich <darkrain42@pidgin.im>
parents: 26867
diff changeset
787 && 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
788 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
789 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
790 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
791 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
792
17822
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
793 if(jm->hasBuzz)
1a183f3fa9d7 disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents: 17821
diff changeset
794 handle_buzz(jm);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
795
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
796 switch(jm->type) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
797 case JABBER_MESSAGE_NORMAL:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
798 case JABBER_MESSAGE_CHAT:
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
799 handle_chat(jm);
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
800 break;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
801 case JABBER_MESSAGE_HEADLINE:
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
802 handle_headline(jm);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
803 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
804 case JABBER_MESSAGE_GROUPCHAT:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
805 handle_groupchat(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
806 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
807 case JABBER_MESSAGE_GROUPCHAT_INVITE:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
808 handle_groupchat_invite(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
809 break;
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17776
diff changeset
810 case JABBER_MESSAGE_EVENT:
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17776
diff changeset
811 jabber_handle_event(jm);
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17776
diff changeset
812 break;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
813 case JABBER_MESSAGE_ERROR:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
814 handle_error(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
815 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
816 case JABBER_MESSAGE_OTHER:
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
817 purple_debug(PURPLE_DEBUG_INFO, "jabber",
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
818 "Received message of unknown type: %s\n", type);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
819 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
820 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
821 jabber_message_free(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
822 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
823
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
824 static const gchar *
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
825 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
826 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
827 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
828 return "image/png";
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
829 } 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
830 return "image/gif";
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
831 } 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
832 return "image/jpeg";
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
833 } 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
834 return "image/tif";
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
835 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
836 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
837 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
838 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
839
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
840 static GList *
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
841 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
842 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
843 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
844 GList *found_smileys = NULL;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
845
23628
3d540eeb2e74 Ooops ... compile\!
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23627
diff changeset
846 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
847 PurpleSmiley *smiley = (PurpleSmiley *) smileys->data;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
848 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
849 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
850
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
851 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
852 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
853
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
854 if (pos) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
855 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
856 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
857
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
858 g_free(escaped);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
859 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
860
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
861 return found_smileys;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
862 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
863
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
864 static gchar *
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
865 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
866 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
867 /* 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
868 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
869 int pos = 0;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
870 int length = strlen(xhtml);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
871
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
872 while (pos < length) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
873 const GList *iterator;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
874 gboolean found_smiley = FALSE;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
875
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
876 for (iterator = smileys ; iterator ;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
877 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
878 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
879 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
880 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
881 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
882
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
883 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
884 /* 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
885 const JabberData *data =
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
886 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
887 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
888 int len;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
889 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
890
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
891 found_smiley = TRUE;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
892 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
893 g_free(img_text);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
894 pos += strlen(escaped);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
895 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
896 xmlnode_free(img);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
897 break;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
898 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
899 /* 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
900 g_free(escaped);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
901 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
902 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
903 if (!found_smiley) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
904 /* 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
905 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
906 pos++;
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 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
909
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
910 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
911 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
912
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
913 static gboolean
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
914 jabber_conv_support_custom_smileys(const PurpleConnection *gc,
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
915 const PurpleConversation *conv,
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
916 const gchar *who)
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
917 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
918 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
919 JabberBuddy *jb;
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25983
diff changeset
920
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
921 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
922 purple_debug_error("jabber",
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
923 "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
924 return FALSE;
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
925 }
23626
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 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
928 /* for the time being, we will not support custom smileys in MUCs */
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
929 case PURPLE_CONV_TYPE_IM:
24789
ee944c10dab6 Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents: 24672
diff changeset
930 jb = jabber_buddy_find(js, who, FALSE);
ee944c10dab6 Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents: 24672
diff changeset
931 if (jb) {
ee944c10dab6 Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents: 24672
diff changeset
932 return jabber_buddy_has_capability(jb, XEP_0231_NAMESPACE);
ee944c10dab6 Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents: 24672
diff changeset
933 } else {
24800
09769f68ea8a Whoops, should return FALSE, not NULL, when jabber_buddy_find returns NULL
Marcus Lundblad <malu@pidgin.im>
parents: 24789
diff changeset
934 return FALSE;
24789
ee944c10dab6 Removed som extranious debug output
Marcus Lundblad <malu@pidgin.im>
parents: 24672
diff changeset
935 }
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
936 break;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
937 default:
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
938 return FALSE;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
939 break;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
940 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
941 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
942
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
943 void jabber_message_send(JabberMessage *jm)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
944 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
945 xmlnode *message, *child;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
946 const char *type = NULL;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
947
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
948 message = xmlnode_new("message");
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
949
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
950 switch(jm->type) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
951 case JABBER_MESSAGE_NORMAL:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
952 type = "normal";
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
953 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
954 case JABBER_MESSAGE_CHAT:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
955 case JABBER_MESSAGE_GROUPCHAT_INVITE:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
956 type = "chat";
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
957 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
958 case JABBER_MESSAGE_HEADLINE:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
959 type = "headline";
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
960 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
961 case JABBER_MESSAGE_GROUPCHAT:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
962 type = "groupchat";
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
963 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
964 case JABBER_MESSAGE_ERROR:
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
965 type = "error";
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
966 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
967 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
968 default:
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
969 type = NULL;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
970 break;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
971 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
972
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
973 if(type)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
974 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
975
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
976 if (jm->id)
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
977 xmlnode_set_attrib(message, "id", jm->id);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
978
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
979 xmlnode_set_attrib(message, "to", jm->to);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
980
8400
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
981 if(jm->thread_id) {
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
982 child = xmlnode_new_child(message, "thread");
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
983 xmlnode_insert_data(child, jm->thread_id, -1);
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
984 }
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
985
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
986 if(JM_TS_JEP_0022 == (jm->typing_style & JM_TS_JEP_0022)) {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
987 child = xmlnode_new_child(message, "x");
13808
411ee56da344 [gaim-migrate @ 16229]
Sean Egan <seanegan@pidgin.im>
parents: 13766
diff changeset
988 xmlnode_set_namespace(child, "jabber:x:event");
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
989 if(jm->chat_state == JM_STATE_COMPOSING || jm->body)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
990 xmlnode_new_child(child, "composing");
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
991 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
992
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
993 if(JM_TS_JEP_0085 == (jm->typing_style & JM_TS_JEP_0085)) {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
994 child = NULL;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
995 switch(jm->chat_state)
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
996 {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
997 case JM_STATE_ACTIVE:
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
998 child = xmlnode_new_child(message, "active");
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
999 break;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1000 case JM_STATE_COMPOSING:
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1001 child = xmlnode_new_child(message, "composing");
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1002 break;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1003 case JM_STATE_PAUSED:
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1004 child = xmlnode_new_child(message, "paused");
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1005 break;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1006 case JM_STATE_INACTIVE:
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1007 child = xmlnode_new_child(message, "inactive");
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1008 break;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1009 case JM_STATE_GONE:
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1010 child = xmlnode_new_child(message, "gone");
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1011 break;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1012 }
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1013 if(child)
13808
411ee56da344 [gaim-migrate @ 16229]
Sean Egan <seanegan@pidgin.im>
parents: 13766
diff changeset
1014 xmlnode_set_namespace(child, "http://jabber.org/protocol/chatstates");
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1015 }
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1016
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1017 if(jm->subject) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1018 child = xmlnode_new_child(message, "subject");
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1019 xmlnode_insert_data(child, jm->subject, -1);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1020 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1021
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1022 if(jm->body) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1023 child = xmlnode_new_child(message, "body");
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1024 xmlnode_insert_data(child, jm->body, -1);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1025 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1026
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1027 if(jm->xhtml) {
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1028 PurpleAccount *account = purple_connection_get_account(jm->js->gc);
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1029 PurpleConversation *conv =
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1030 purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, jm->to,
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1031 account);
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25983
diff changeset
1032
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1033 if (jabber_conv_support_custom_smileys(jm->js->gc, conv, jm->to)) {
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1034 GList *found_smileys = jabber_message_xhtml_find_smileys(jm->xhtml);
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1035
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1036 if (found_smileys) {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1037 gchar *smileyfied_xhtml = NULL;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1038 const GList *iterator;
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1039
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1040 for (iterator = found_smileys; iterator ;
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1041 iterator = g_list_next(iterator)) {
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1042 const PurpleSmiley *smiley =
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1043 (PurpleSmiley *) iterator->data;
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1044 const gchar *shortcut = purple_smiley_get_shortcut(smiley);
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1045 const JabberData *data =
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1046 jabber_data_find_local_by_alt(shortcut);
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25983
diff changeset
1047
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1048 /* the object has not been sent before */
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1049 if (!data) {
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1050 PurpleStoredImage *image =
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1051 purple_smiley_get_stored_image(smiley);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1052 const gchar *ext = purple_imgstore_get_extension(image);
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1053 JabberStream *js = jm->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
1054
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1055 JabberData *new_data =
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1056 jabber_data_create_from_data(purple_imgstore_get_data(image),
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1057 purple_imgstore_get_size(image),
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1058 jabber_message_get_mimetype_from_ext(ext), 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
1059 purple_debug_info("jabber",
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1060 "cache local smiley alt = %s, cid = %s\n",
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1061 shortcut, jabber_data_get_cid(new_data));
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1062 jabber_data_associate_local(new_data, shortcut);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1063 }
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1064 }
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1065
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1066 smileyfied_xhtml =
24254
2d990726bf92 Updated to use latest spec. in XEP-0231
Marcus Lundblad <malu@pidgin.im>
parents: 23628
diff changeset
1067 jabber_message_get_smileyfied_xhtml(jm->xhtml, found_smileys);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1068 child = xmlnode_from_str(smileyfied_xhtml, -1);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1069 g_free(smileyfied_xhtml);
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1070 g_list_free(found_smileys);
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1071 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1072 child = xmlnode_from_str(jm->xhtml, -1);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1073 }
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1074 } else {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1075 child = xmlnode_from_str(jm->xhtml, -1);
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1076 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1077 if(child) {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1078 xmlnode_insert_child(message, child);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1079 } else {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1080 purple_debug(PURPLE_DEBUG_ERROR, "jabber",
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1081 "XHTML translation/validation failed, returning: %s\n",
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1082 jm->xhtml);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1083 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1084 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1085
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1086 jabber_send(jm->js, message);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1087
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1088 xmlnode_free(message);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1089 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1090
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1091 int jabber_message_send_im(PurpleConnection *gc, const char *who, const char *msg,
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1092 PurpleMessageFlags flags)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1093 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1094 JabberMessage *jm;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1095 JabberBuddy *jb;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1096 JabberBuddyResource *jbr;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1097 char *buf;
7135
8a92e2e034f9 [gaim-migrate @ 7702]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
1098 char *xhtml;
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1099 char *resource;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1100
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1101 if(!who || !msg)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1102 return 0;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1103
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1104 resource = jabber_get_resource(who);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1105
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1106 jb = jabber_buddy_find(gc->proto_data, who, TRUE);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1107 jbr = jabber_buddy_find_resource(jb, resource);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1108
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1109 g_free(resource);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1110
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1111 jm = g_new0(JabberMessage, 1);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1112 jm->js = gc->proto_data;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1113 jm->type = JABBER_MESSAGE_CHAT;
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1114 jm->chat_state = JM_STATE_ACTIVE;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1115 jm->to = g_strdup(who);
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
1116 jm->id = jabber_get_next_id(jm->js);
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1117 jm->chat_state = JM_STATE_ACTIVE;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1118
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1119 if(jbr) {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1120 if(jbr->thread_id)
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1121 jm->thread_id = jbr->thread_id;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1122
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1123 if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1124 jm->typing_style |= JM_TS_JEP_0085;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1125 /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states)
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1126 jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1127 }
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1128
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1129 if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED)
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1130 jm->typing_style |= JM_TS_JEP_0022;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1131 }
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1132
7773
5d92f7e60cc4 [gaim-migrate @ 8418]
Nathan Walp <nwalp@pidgin.im>
parents: 7642
diff changeset
1133 buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg);
26042
4dabdb5fe213 Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25983
diff changeset
1134
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1135 purple_markup_html_to_xhtml(buf, &xhtml, &jm->body);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1136 g_free(buf);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1137
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1138 if(!jbr || jbr->capabilities & JABBER_CAP_XHTML)
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1139 jm->xhtml = xhtml;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1140 else
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1141 g_free(xhtml);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1142
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1143 jabber_message_send(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1144 jabber_message_free(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1145 return 1;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1146 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1147
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1148 int jabber_message_send_chat(PurpleConnection *gc, int id, const char *msg, PurpleMessageFlags flags)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1149 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1150 JabberChat *chat;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1151 JabberMessage *jm;
8042
3643df1e6e78 [gaim-migrate @ 8726]
Nathan Walp <nwalp@pidgin.im>
parents: 8016
diff changeset
1152 JabberStream *js;
9130
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1153 char *buf;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1154
8042
3643df1e6e78 [gaim-migrate @ 8726]
Nathan Walp <nwalp@pidgin.im>
parents: 8016
diff changeset
1155 if(!msg || !gc)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1156 return 0;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1157
8042
3643df1e6e78 [gaim-migrate @ 8726]
Nathan Walp <nwalp@pidgin.im>
parents: 8016
diff changeset
1158 js = gc->proto_data;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1159 chat = jabber_chat_find_by_id(js, id);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1160
8043
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
1161 if(!chat)
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
1162 return 0;
86a087e9624c [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
1163
9130
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1164 jm = g_new0(JabberMessage, 1);
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1165 jm->js = gc->proto_data;
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1166 jm->type = JABBER_MESSAGE_GROUPCHAT;
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1167 jm->to = g_strdup_printf("%s@%s", chat->room, chat->server);
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
1168 jm->id = jabber_get_next_id(jm->js);
9130
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1169
8858
99c635a80a26 [gaim-migrate @ 9626]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
1170 buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1171 purple_markup_html_to_xhtml(buf, &jm->xhtml, &jm->body);
8858
99c635a80a26 [gaim-migrate @ 9626]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
1172 g_free(buf);
99c635a80a26 [gaim-migrate @ 9626]
Nathan Walp <nwalp@pidgin.im>
parents: 8577
diff changeset
1173
9130
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1174 if(!chat->xhtml) {
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1175 g_free(jm->xhtml);
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1176 jm->xhtml = NULL;
7923
fd43ed3cda18 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7894
diff changeset
1177 }
fd43ed3cda18 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7894
diff changeset
1178
9130
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1179 jabber_message_send(jm);
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1180 jabber_message_free(jm);
2e67295dd047 [gaim-migrate @ 9908]
Nathan Walp <nwalp@pidgin.im>
parents: 8858
diff changeset
1181
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1182 return 1;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1183 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1184
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1185 unsigned int jabber_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state)
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1186 {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1187 JabberMessage *jm;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1188 JabberBuddy *jb;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1189 JabberBuddyResource *jbr;
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1190 char *resource = jabber_get_resource(who);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1191
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1192 jb = jabber_buddy_find(gc->proto_data, who, TRUE);
7306
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1193 jbr = jabber_buddy_find_resource(jb, resource);
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1194
61d7324411f8 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
1195 g_free(resource);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1196
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1197 if(!jbr || !((jbr->capabilities & JABBER_CAP_COMPOSING) || (jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED)))
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1198 return 0;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1199
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1200 /* TODO: figure out threading */
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1201 jm = g_new0(JabberMessage, 1);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1202 jm->js = gc->proto_data;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1203 jm->type = JABBER_MESSAGE_CHAT;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1204 jm->to = g_strdup(who);
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 13385
diff changeset
1205 jm->id = jabber_get_next_id(jm->js);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1206
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1207 if(PURPLE_TYPING == state)
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1208 jm->chat_state = JM_STATE_COMPOSING;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15721
diff changeset
1209 else if(PURPLE_TYPED == state)
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1210 jm->chat_state = JM_STATE_PAUSED;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1211 else
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1212 jm->chat_state = JM_STATE_ACTIVE;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1213
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1214 if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) {
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1215 jm->typing_style |= JM_TS_JEP_0085;
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1216 /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states)
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1217 jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1218 }
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1219
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1220 if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED)
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1221 jm->typing_style |= JM_TS_JEP_0022;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1222
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1223 jabber_message_send(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1224 jabber_message_free(jm);
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1225
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
1226 return 0;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1227 }
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1228
23586
e495a4623f76 Removing short-names for features and calculating own caps hash.
Tobias Markmann <tfar@soc.pidgin.im>
parents: 23249
diff changeset
1229 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
1230 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
1231 }
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
1232
24715
69aaae59e205 Fix compilation errors and many warnings
Paul Aurich <darkrain42@pidgin.im>
parents: 24714
diff changeset
1233 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
1234 {
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1235 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
1236 PurpleAccount *account = purple_connection_get_account(gc);
23627
dbdc407798af A couple of leak fixes.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 23626
diff changeset
1237
23626
e21afec2f485 Custom smileys for XMPP according to XEP 0231. Refs #5627.
Marcus Lundblad <malu@pidgin.im>
parents: 23249
diff changeset
1238 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
1239 }

mercurial