annotate src/protocols/jabber/message.c @ 8843:1bbe99a07e36

[gaim-migrate @ 9610] Pekka Riikonen has provided us with a nice file selector request API. This is it. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Fri, 30 Apr 2004 03:00:05 +0000
parents 599d6ac9bbfe
children d7b5fbc451da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim - Jabber Protocol Plugin
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
67c4e9d39242 [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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "debug.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "notify.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "server.h"
7095
c8bf2da398e3 [gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
26 #include "util.h"
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 #include "buddy.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "chat.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 #include "message.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include "xmlnode.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 #define JABBER_TYPING_NOTIFY_INT 15
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 void jabber_message_free(JabberMessage *jm)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 if(jm->from)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 g_free(jm->from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 if(jm->to)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 g_free(jm->to);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 if(jm->subject)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 g_free(jm->subject);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 if(jm->body)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 g_free(jm->body);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 if(jm->xhtml)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 g_free(jm->xhtml);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 if(jm->password)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 g_free(jm->password);
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
49 if(jm->etc)
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
50 g_list_free(jm->etc);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 g_free(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
55 static void handle_chat(JabberMessage *jm)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 JabberID *jid = jabber_id_new(jm->from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 char *from;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 JabberBuddy *jb;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 JabberBuddyResource *jbr;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
63 if(!jid)
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
64 return;
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
65
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 jb = jabber_buddy_find(jm->js, jm->from, TRUE);
7306
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
67 jbr = jabber_buddy_find_resource(jb, jid->resource);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
69 if(jabber_find_unnormalized_conv(jm->from, jm->js->gc->account)) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 from = g_strdup(jm->from);
7258
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
71 } else if(jid->node) {
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
72 GaimConversation *conv;
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
73
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74 from = g_strdup_printf("%s@%s", jid->node, jid->domain);
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
75 conv = jabber_find_unnormalized_conv(from, jm->js->gc->account);
7258
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
76 if(conv)
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
77 gaim_conversation_set_name(conv, jm->from);
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
78 g_free(from);
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
79 from = g_strdup(jm->from);
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
80 } else {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 from = g_strdup(jid->domain);
7258
d1974612b994 [gaim-migrate @ 7835]
Nathan Walp <nwalp@pidgin.im>
parents: 7241
diff changeset
82 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 if(!jm->xhtml && !jm->body) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 serv_got_typing(jm->js->gc, from, 0, GAIM_TYPING);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 serv_got_typing_stopped(jm->js->gc, from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 } else {
8400
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
90 if(jbr) {
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
91 if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING)
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
92 jbr->capabilities |= JABBER_CAP_COMPOSING;
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
93 if(jbr->thread_id)
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
94 g_free(jbr->thread_id);
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
95 jbr->thread_id = g_strdup(jbr->thread_id);
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
96 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 serv_got_im(jm->js->gc, from, jm->xhtml ? jm->xhtml : jm->body, 0,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 jm->sent);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 g_free(from);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 jabber_id_free(jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
105 static void handle_headline(JabberMessage *jm)
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
106 {
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
107 char *title;
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
108 GString *body = g_string_new("");
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
109 GList *etc;
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
110
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
111 title = g_strdup_printf(_("Message from %s"), jm->from);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
112
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
113 if(jm->xhtml)
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
114 g_string_append(body, jm->xhtml);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
115 else if(jm->body)
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
116 g_string_append(body, jm->body);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
117
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
118 for(etc = jm->etc; etc; etc = etc->next) {
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
119 xmlnode *x = etc->data;
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
120 const char *xmlns = xmlnode_get_attrib(x, "xmlns");
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
121 if(xmlns && !strcmp(xmlns, "jabber:x:oob")) {
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
122 xmlnode *url, *desc;
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
123 char *urltxt, *desctxt;
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
124
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
125 url = xmlnode_get_child(x, "url");
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
126 desc = xmlnode_get_child(x, "desc");
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
127
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
128 if(!url || !desc)
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
129 continue;
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
130
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
131 urltxt = xmlnode_get_data(url);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
132 desctxt = xmlnode_get_data(desc);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
133
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
134 /* I'm all about ugly hacks */
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
135 if(body->len && !strcmp(body->str, jm->body))
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
136 g_string_printf(body, "<a href='%s'>%s</a>",
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
137 urltxt, desctxt);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
138 else
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
139 g_string_append_printf(body, "<br/><a href='%s'>%s</a>",
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
140 urltxt, desctxt);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
141
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
142 g_free(urltxt);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
143 g_free(desctxt);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
144 }
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
145 }
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
146
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
147 gaim_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title,
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
148 NULL, body->str, NULL, NULL);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
149
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
150 g_free(title);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
151 g_string_free(body, TRUE);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
152 }
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
153
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
154 static void handle_groupchat(JabberMessage *jm)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 JabberID *jid = jabber_id_new(jm->from);
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
157 JabberChat *chat;
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
158
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
159 if(!jid)
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
160 return;
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
161
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
162 chat = jabber_chat_find(jm->js, jid->node, jid->domain);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 if(!chat)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
167 if(jm->subject) {
7183
071dee25c48e [gaim-migrate @ 7751]
Nathan Walp <nwalp@pidgin.im>
parents: 7145
diff changeset
168 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(chat->conv), jid->resource,
071dee25c48e [gaim-migrate @ 7751]
Nathan Walp <nwalp@pidgin.im>
parents: 7145
diff changeset
169 jm->subject);
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
170 if(!jm->xhtml && !jm->body) {
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
171 char *msg;
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
172 if(jid->resource)
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
173 msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, jm->subject);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
174 else
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
175 msg = g_strdup_printf(_("The topic is: %s"), jm->subject);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
176 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", msg, GAIM_MESSAGE_SYSTEM, jm->sent);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
177 g_free(msg);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
178 }
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
179 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180
7630
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
181 if(jm->xhtml || jm->body) {
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
182 if(jid->resource)
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
183 serv_got_chat_in(jm->js->gc, chat->id, jid->resource, 0,
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
184 jm->xhtml ? jm->xhtml : jm->body, jm->sent);
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
185 else if(chat->muc)
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
186 gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "",
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
187 jm->xhtml ? jm->xhtml : jm->body,
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
188 GAIM_MESSAGE_SYSTEM, jm->sent);
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
189 }
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7448
diff changeset
190
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191 jabber_id_free(jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
193
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
194 static void handle_groupchat_invite(JabberMessage *jm)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195 {
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
196 GHashTable *components;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 JabberID *jid = jabber_id_new(jm->to);
8537
dc818b62379e [gaim-migrate @ 9276]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
198 char *stripped;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199
7310
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
200 if(!jid)
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
201 return;
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
202
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
203 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
dd4b4a187171 [gaim-migrate @ 7894]
Nathan Walp <nwalp@pidgin.im>
parents: 7306
diff changeset
204
7332
803c7238f6d8 [gaim-migrate @ 7920]
Nathan Walp <nwalp@pidgin.im>
parents: 7318
diff changeset
205 g_hash_table_replace(components, g_strdup("room"), g_strdup(jid->node));
7448
f3f47de6d8a7 [gaim-migrate @ 8059]
Nathan Walp <nwalp@pidgin.im>
parents: 7444
diff changeset
206 g_hash_table_replace(components, g_strdup("server"), g_strdup(jid->domain));
7332
803c7238f6d8 [gaim-migrate @ 7920]
Nathan Walp <nwalp@pidgin.im>
parents: 7318
diff changeset
207 g_hash_table_replace(components, g_strdup("handle"),
803c7238f6d8 [gaim-migrate @ 7920]
Nathan Walp <nwalp@pidgin.im>
parents: 7318
diff changeset
208 g_strdup(jm->js->user->node));
803c7238f6d8 [gaim-migrate @ 7920]
Nathan Walp <nwalp@pidgin.im>
parents: 7318
diff changeset
209 g_hash_table_replace(components, g_strdup("password"),
803c7238f6d8 [gaim-migrate @ 7920]
Nathan Walp <nwalp@pidgin.im>
parents: 7318
diff changeset
210 g_strdup(jm->password));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 jabber_id_free(jid);
8537
dc818b62379e [gaim-migrate @ 9276]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
213 stripped = gaim_markup_strip_html(jm->body);
dc818b62379e [gaim-migrate @ 9276]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
214 serv_got_chat_invite(jm->js->gc, jm->to, jm->from, stripped, components);
dc818b62379e [gaim-migrate @ 9276]
Nathan Walp <nwalp@pidgin.im>
parents: 8400
diff changeset
215 g_free(stripped);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
218 static void handle_error(JabberMessage *jm)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 char *buf;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 if(!jm->body)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225 buf = g_strdup_printf(_("Message delivery to %s failed: %s"),
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 jm->from, jm->error);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227
7944
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
228 gaim_notify_formatted(jm->js->gc, _("Jabber Message Error"), _("Jabber Message Error"), buf,
a99f0aebc7ce [gaim-migrate @ 8615]
Nathan Walp <nwalp@pidgin.im>
parents: 7923
diff changeset
229 jm->xhtml ? jm->xhtml : jm->body, NULL, NULL);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231 g_free(buf);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 void jabber_message_parse(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 JabberMessage *jm;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 const char *type;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 xmlnode *child;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 if(strcmp(packet->name, "message"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243 jm = g_new0(JabberMessage, 1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 jm->js = js;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 jm->sent = time(NULL);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 type = xmlnode_get_attrib(packet, "type");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 if(type) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 if(!strcmp(type, "normal"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 jm->type = JABBER_MESSAGE_NORMAL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 else if(!strcmp(type, "chat"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 jm->type = JABBER_MESSAGE_CHAT;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 else if(!strcmp(type, "groupchat"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 jm->type = JABBER_MESSAGE_GROUPCHAT;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 else if(!strcmp(type, "headline"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 jm->type = JABBER_MESSAGE_HEADLINE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 else if(!strcmp(type, "error"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 jm->type = JABBER_MESSAGE_ERROR;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 jm->type = JABBER_MESSAGE_OTHER;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 jm->type = JABBER_MESSAGE_NORMAL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 jm->from = g_strdup(xmlnode_get_attrib(packet, "from"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 jm->to = g_strdup(xmlnode_get_attrib(packet, "to"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 for(child = packet->child; child; child = child->next) {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8043
diff changeset
270 if(child->type != XMLNODE_TYPE_TAG)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 continue;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273 if(!strcmp(child->name, "subject")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 if(!jm->subject)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 jm->subject = xmlnode_get_data(child);
8400
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
276 } else if(!strcmp(child->name, "thread")) {
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
277 if(!jm->thread_id)
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
278 jm->thread_id = xmlnode_get_data(child);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 } else if(!strcmp(child->name, "body")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280 if(!jm->body)
7894
8a9f0754f0be [gaim-migrate @ 8554]
Nathan Walp <nwalp@pidgin.im>
parents: 7773
diff changeset
281 jm->body = xmlnode_to_str(child, NULL);
7241
04e80607aff2 [gaim-migrate @ 7816]
Nathan Walp <nwalp@pidgin.im>
parents: 7187
diff changeset
282 } else if(!strcmp(child->name, "html")) {
04e80607aff2 [gaim-migrate @ 7816]
Nathan Walp <nwalp@pidgin.im>
parents: 7187
diff changeset
283 if(!jm->xhtml)
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7630
diff changeset
284 jm->xhtml = xmlnode_to_str(child, NULL);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285 } else if(!strcmp(child->name, "error")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 const char *code = xmlnode_get_attrib(child, "code");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287 char *code_txt = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 char *text = xmlnode_get_data(child);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290 if(code)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291 code_txt = g_strdup_printf(_(" (Code %s)"), code);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 if(!jm->error)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294 jm->error = g_strdup_printf("%s%s", text ? text : "",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 code_txt ? code_txt : "");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297 g_free(code_txt);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 g_free(text);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 } else if(!strcmp(child->name, "x")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300 const char *xmlns = xmlnode_get_attrib(child, "xmlns");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301 if(xmlns && !strcmp(xmlns, "jabber:x:event")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302 if(xmlnode_get_child(child, "composing"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303 jm->events |= JABBER_MESSAGE_EVENT_COMPOSING;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
304 } else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305 const char *timestamp = xmlnode_get_attrib(child, "stamp");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 if(timestamp)
8577
599d6ac9bbfe [gaim-migrate @ 9326]
Nathan Walp <nwalp@pidgin.im>
parents: 8537
diff changeset
307 jm->sent = gaim_str_to_time(timestamp, TRUE);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308 } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") &&
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309 jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310 const char *jid = xmlnode_get_attrib(child, "jid");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311 if(jid) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 g_free(jm->to);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 jm->to = g_strdup(jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316 } else if(xmlns && !strcmp(xmlns,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
317 "http://jabber.org/protocol/muc#user")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318 xmlnode *invite = xmlnode_get_child(child, "invite");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 if(invite) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 xmlnode *reason, *password;
7968
64e94b6823c3 [gaim-migrate @ 8645]
Nathan Walp <nwalp@pidgin.im>
parents: 7955
diff changeset
321 const char *jid = xmlnode_get_attrib(invite, "from");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322 g_free(jm->to);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323 jm->to = jm->from;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 jm->from = g_strdup(jid);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325 if((reason = xmlnode_get_child(invite, "reason"))) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 g_free(jm->body);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 jm->body = xmlnode_get_data(reason);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329 if((password = xmlnode_get_child(invite, "password")))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330 jm->password = xmlnode_get_data(password);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
331
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 }
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
334 } else {
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
335 jm->etc = g_list_append(jm->etc, child);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 switch(jm->type) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 case JABBER_MESSAGE_NORMAL:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 case JABBER_MESSAGE_CHAT:
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
343 handle_chat(jm);
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
344 break;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 case JABBER_MESSAGE_HEADLINE:
7145
0e4894b3e2a6 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7135
diff changeset
346 handle_headline(jm);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348 case JABBER_MESSAGE_GROUPCHAT:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
349 handle_groupchat(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
350 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
351 case JABBER_MESSAGE_GROUPCHAT_INVITE:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352 handle_groupchat_invite(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 case JABBER_MESSAGE_ERROR:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
355 handle_error(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
356 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
357 case JABBER_MESSAGE_OTHER:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358 gaim_debug(GAIM_DEBUG_INFO, "jabber",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 "Received message of unknown type: %s\n", type);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
361 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
362 jabber_message_free(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
363 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
364
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
365 void jabber_message_send(JabberMessage *jm)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
366 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
367 xmlnode *message, *child;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
368 const char *type = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
369
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
370 message = xmlnode_new("message");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
371
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
372 switch(jm->type) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
373 case JABBER_MESSAGE_NORMAL:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
374 type = "normal";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
375 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
376 case JABBER_MESSAGE_CHAT:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
377 case JABBER_MESSAGE_GROUPCHAT_INVITE:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
378 type = "chat";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
379 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
380 case JABBER_MESSAGE_HEADLINE:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
381 type = "headline";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
382 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
383 case JABBER_MESSAGE_GROUPCHAT:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
384 type = "groupchat";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
385 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
386 case JABBER_MESSAGE_ERROR:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
387 type = "error";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
388 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
389 case JABBER_MESSAGE_OTHER:
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
390 type = NULL;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
391 break;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
392 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
393
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
394 if(type)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
395 xmlnode_set_attrib(message, "type", type);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
396
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
397 xmlnode_set_attrib(message, "to", jm->to);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
398
8400
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
399 if(jm->thread_id) {
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
400 child = xmlnode_new_child(message, "thread");
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
401 xmlnode_insert_data(child, jm->thread_id, -1);
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
402 }
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
403
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
404 if(jm->events || (!jm->body && !jm->xhtml && !jm->subject)) {
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
405 child = xmlnode_new_child(message, "x");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
406 xmlnode_set_attrib(child, "xmlns", "jabber:x:event");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
407 if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
408 xmlnode_new_child(child, "composing");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
409 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
410
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
411 if(jm->subject) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
412 child = xmlnode_new_child(message, "subject");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
413 xmlnode_insert_data(child, jm->subject, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
414 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
415
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
416 if(jm->body) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
417 child = xmlnode_new_child(message, "body");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
418 xmlnode_insert_data(child, jm->body, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
419 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
420
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
421 if(jm->xhtml) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
422 child = xmlnode_from_str(jm->xhtml, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
423 if(child) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
424 xmlnode_insert_child(message, child);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
425 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
426 gaim_debug(GAIM_DEBUG_ERROR, "jabber",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
427 "XHTML translation/validation failed, returning: %s\n",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
428 jm->xhtml);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
429 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
430 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
431
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
432 jabber_send(jm->js, message);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
433
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
434 xmlnode_free(message);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
435 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
436
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
437 int jabber_message_send_im(GaimConnection *gc, const char *who, const char *msg,
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 7095
diff changeset
438 GaimConvImFlags flags)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
439 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
440 JabberMessage *jm;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
441 JabberBuddy *jb;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
442 JabberBuddyResource *jbr;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
443 char *buf;
7135
eba5f7be0bc8 [gaim-migrate @ 7702]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
444 char *xhtml;
7306
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
445 char *resource;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
446
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
447 if(!who || !msg)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
448 return 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
449
7306
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
450 resource = jabber_get_resource(who);
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
451
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
452 jb = jabber_buddy_find(gc->proto_data, who, TRUE);
7306
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
453 jbr = jabber_buddy_find_resource(jb, resource);
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
454
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
455 g_free(resource);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
456
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
457 jm = g_new0(JabberMessage, 1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
458 jm->js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
459 jm->type = JABBER_MESSAGE_CHAT;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
460 jm->events = JABBER_MESSAGE_EVENT_COMPOSING;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
461 jm->to = g_strdup(who);
8400
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
462 if(jbr && jbr->thread_id)
0383e55cd658 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
463 jm->thread_id = jbr->thread_id;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
464
7773
d9a7774b5b3c [gaim-migrate @ 8418]
Nathan Walp <nwalp@pidgin.im>
parents: 7642
diff changeset
465 buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
466
7135
eba5f7be0bc8 [gaim-migrate @ 7702]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
467 gaim_markup_html_to_xhtml(buf, &xhtml, &jm->body);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
468 g_free(buf);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
469
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
470 if(!jbr || jbr->capabilities & JABBER_CAP_XHTML)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
471 jm->xhtml = xhtml;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
472 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
473 g_free(xhtml);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
474
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
475 jabber_message_send(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
476 jabber_message_free(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
477 return 1;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
478 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
479
7345
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
480 int jabber_message_send_chat(GaimConnection *gc, int id, const char *msg)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
481 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
482 JabberChat *chat;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
483 JabberMessage *jm;
8042
7fa6ddec6e30 [gaim-migrate @ 8726]
Nathan Walp <nwalp@pidgin.im>
parents: 8016
diff changeset
484 JabberStream *js;
7345
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
485 char *buf, *xhtml;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
486
8042
7fa6ddec6e30 [gaim-migrate @ 8726]
Nathan Walp <nwalp@pidgin.im>
parents: 8016
diff changeset
487 if(!msg || !gc)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
488 return 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
489
8042
7fa6ddec6e30 [gaim-migrate @ 8726]
Nathan Walp <nwalp@pidgin.im>
parents: 8016
diff changeset
490 js = gc->proto_data;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
491 chat = jabber_chat_find_by_id(js, id);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
492
8043
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
493 if(!chat)
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
494 return 0;
9a6df4d567e0 [gaim-migrate @ 8727]
Nathan Walp <nwalp@pidgin.im>
parents: 8042
diff changeset
495
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7894
diff changeset
496 if(!strcmp(msg, "/configure") || !strcmp(msg, "/config")) {
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7894
diff changeset
497 jabber_chat_request_room_configure(chat);
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7894
diff changeset
498 return 1;
7955
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7944
diff changeset
499 } else if(!strcmp(msg, "/register")) {
119a22025818 [gaim-migrate @ 8630]
Nathan Walp <nwalp@pidgin.im>
parents: 7944
diff changeset
500 jabber_chat_register(chat);
7971
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
501 return 1;
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
502 } else if(!strncmp(msg, "/topic", 6)) {
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
503 jabber_chat_change_topic(chat, strlen(msg) > 7 ? msg+7 : NULL);
6fca0d9cc98b [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7968
diff changeset
504 return 1;
7972
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
505 } else if(!strncmp(msg, "/nick", 5)) {
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
506 if(strlen(msg) > 6)
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
507 jabber_chat_change_nick(chat, msg+6);
ac01b7d67ff9 [gaim-migrate @ 8649]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
508 return 1;
7974
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
509 } else if(!strncmp(msg, "/part", 5)) {
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
510 jabber_chat_part(chat, strlen(msg) > 6 ? msg+6 : NULL);
415df6fa0395 [gaim-migrate @ 8651]
Nathan Walp <nwalp@pidgin.im>
parents: 7972
diff changeset
511 return 1;
7923
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7894
diff changeset
512 }
e87e7d9d0132 [gaim-migrate @ 8592]
Nathan Walp <nwalp@pidgin.im>
parents: 7894
diff changeset
513
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
514 jm = g_new0(JabberMessage, 1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
515 jm->js = gc->proto_data;
7444
66945d35a7c0 [gaim-migrate @ 8049]
Nathan Walp <nwalp@pidgin.im>
parents: 7345
diff changeset
516 jm->type = JABBER_MESSAGE_GROUPCHAT;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
517 jm->to = g_strdup_printf("%s@%s", chat->room, chat->server);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
518
7773
d9a7774b5b3c [gaim-migrate @ 8418]
Nathan Walp <nwalp@pidgin.im>
parents: 7642
diff changeset
519 buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg);
7345
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
520
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
521 gaim_markup_html_to_xhtml(buf, &xhtml, &jm->body);
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
522 g_free(buf);
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
523
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
524 if(chat->xhtml)
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
525 jm->xhtml = xhtml;
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
526 else
565b5bca5e8a [gaim-migrate @ 7936]
Nathan Walp <nwalp@pidgin.im>
parents: 7332
diff changeset
527 g_free(xhtml);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
528
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
529 jabber_message_send(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
530 jabber_message_free(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
531 return 1;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
532 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
533
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
534 int jabber_send_typing(GaimConnection *gc, const char *who, int typing)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
535 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
536 JabberMessage *jm;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
537 JabberBuddy *jb;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
538 JabberBuddyResource *jbr;
7306
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
539 char *resource = jabber_get_resource(who);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
540
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
541 jb = jabber_buddy_find(gc->proto_data, who, TRUE);
7306
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
542 jbr = jabber_buddy_find_resource(jb, resource);
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
543
7c12dab8e513 [gaim-migrate @ 7890]
Nathan Walp <nwalp@pidgin.im>
parents: 7261
diff changeset
544 g_free(resource);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
545
7187
0f16c37aa472 [gaim-migrate @ 7755]
Nathan Walp <nwalp@pidgin.im>
parents: 7183
diff changeset
546 if(!jbr || !(jbr->capabilities & JABBER_CAP_COMPOSING))
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
547 return 0;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
548
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
549 jm = g_new0(JabberMessage, 1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
550 jm->js = gc->proto_data;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
551 jm->type = JABBER_MESSAGE_CHAT;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
552 jm->to = g_strdup(who);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
553
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
554 if(typing == GAIM_TYPING)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
555 jm->events = JABBER_MESSAGE_EVENT_COMPOSING;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
556
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
557 jabber_message_send(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
558 jabber_message_free(jm);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
559
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
560 return JABBER_TYPING_NOTIFY_INT;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
561 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
562