Sun, 10 Aug 2008 18:46:32 +0000
Reapplied changes that were overwritten by 91f0294f2377e3870982f3e573e0dfb4230d9c11.
applied changes from b53b1ff4bbd75647c953e5f02eaca17c85d2113e
through 586238415076c2a3a3079812de64aff5841cde39
applied changes from 918c72f0ff7f7e3c545d3baf6368ccbd2ba21427
through e8404ca19a538f5254f1a156feb894d0618588d2
applied changes from e8404ca19a538f5254f1a156feb894d0618588d2
through 398b1414aa67f63ae191264603994be045df42f5
applied changes from 398b1414aa67f63ae191264603994be045df42f5
through b53b1ff4bbd75647c953e5f02eaca17c85d2113e
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 3 | * |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 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 | 19 | * |
| 20 | */ | |
| 21 | #include "internal.h" | |
| 22 | ||
| 23 | #include "debug.h" | |
| 24 | #include "notify.h" | |
| 25 | #include "server.h" | |
|
7095
17d2b54254f8
[gaim-migrate @ 7660]
Christian Hammond <chipx86@chipx86.com>
parents:
7014
diff
changeset
|
26 | #include "util.h" |
| 7014 | 27 | |
| 28 | #include "buddy.h" | |
| 29 | #include "chat.h" | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
30 | #include "google.h" |
| 7014 | 31 | #include "message.h" |
| 32 | #include "xmlnode.h" | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
33 | #include "pep.h" |
| 7014 | 34 | |
| 35 | void jabber_message_free(JabberMessage *jm) | |
| 36 | { | |
| 15980 | 37 | g_free(jm->from); |
| 13484 | 38 | g_free(jm->to); |
| 39 | g_free(jm->id); | |
| 40 | g_free(jm->subject); | |
| 41 | g_free(jm->body); | |
| 42 | g_free(jm->xhtml); | |
| 43 | g_free(jm->password); | |
|
20057
728a7dce565e
grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents:
19917
diff
changeset
|
44 | g_free(jm->error); |
|
728a7dce565e
grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents:
19917
diff
changeset
|
45 | g_free(jm->thread_id); |
| 13484 | 46 | g_list_free(jm->etc); |
|
20057
728a7dce565e
grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
Luke Schierer <lschiere@pidgin.im>
parents:
19917
diff
changeset
|
47 | g_list_free(jm->eventitems); |
| 7014 | 48 | |
| 49 | g_free(jm); | |
| 50 | } | |
| 51 | ||
| 7145 | 52 | static void handle_chat(JabberMessage *jm) |
| 7014 | 53 | { |
| 54 | JabberID *jid = jabber_id_new(jm->from); | |
| 55 | char *from; | |
| 56 | ||
| 57 | JabberBuddy *jb; | |
| 58 | JabberBuddyResource *jbr; | |
| 59 | ||
| 7310 | 60 | if(!jid) |
| 61 | return; | |
| 62 | ||
| 7014 | 63 | jb = jabber_buddy_find(jm->js, jm->from, TRUE); |
| 7306 | 64 | jbr = jabber_buddy_find_resource(jb, jid->resource); |
| 7014 | 65 | |
| 8043 | 66 | if(jabber_find_unnormalized_conv(jm->from, jm->js->gc->account)) { |
| 7014 | 67 | from = g_strdup(jm->from); |
| 7258 | 68 | } else if(jid->node) { |
| 10490 | 69 | if(jid->resource) { |
| 15884 | 70 | PurpleConversation *conv; |
| 7258 | 71 | |
| 10490 | 72 | from = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 15884 | 73 | conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, jm->js->gc->account); |
| 10490 | 74 | if(conv) { |
| 15884 | 75 | purple_conversation_set_name(conv, jm->from); |
| 13304 | 76 | } |
| 10490 | 77 | g_free(from); |
| 78 | } | |
| 7258 | 79 | from = g_strdup(jm->from); |
| 80 | } else { | |
| 7014 | 81 | from = g_strdup(jid->domain); |
| 7258 | 82 | } |
| 7014 | 83 | |
| 84 | 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
|
85 | if(JM_STATE_COMPOSING == jm->chat_state) { |
| 15884 | 86 | 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
|
87 | } else if(JM_STATE_PAUSED == jm->chat_state) { |
| 15884 | 88 | 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
|
89 | } else if(JM_STATE_GONE == jm->chat_state) { |
| 15884 | 90 | 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
|
91 | 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
|
92 | 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
|
93 | char buf[256]; |
| 15884 | 94 | 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
|
95 | |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
96 | 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
|
97 | |
| 15884 | 98 | 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
|
99 | 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
|
100 | char *escaped; |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
101 | |
| 15884 | 102 | 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
|
103 | 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
|
104 | |
|
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
105 | g_snprintf(buf, sizeof(buf), |
| 16946 | 106 | _("%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
|
107 | 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
|
108 | |
| 15884 | 109 | /* 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
|
110 | * 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
|
111 | * user from the conversation like we do with chats now. */ |
| 15884 | 112 | purple_conversation_write(conv, "", buf, |
| 113 | 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
|
114 | } |
|
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
|
115 | } |
| 7014 | 116 | serv_got_typing_stopped(jm->js->gc, from); |
|
15710
fbc4a200c853
Receiving XEP 85 'gone' messages. Doesn't do anything because of the string freeze. This is akin to the MSN 'so-and-so has closed the conversation window' messages. Rlaager made a strong point to me that they're not altogether stalky, but can be useful.
Sean Egan <seanegan@pidgin.im>
parents:
15709
diff
changeset
|
117 | |
|
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
|
118 | } 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
|
119 | 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
|
120 | } |
| 7014 | 121 | } else { |
| 8400 | 122 | if(jbr) { |
| 13708 | 123 | if(JM_TS_JEP_0085 == (jm->typing_style & JM_TS_JEP_0085)) { |
| 124 | jbr->chat_states = JABBER_CHAT_STATES_SUPPORTED; | |
| 125 | } else { | |
| 126 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; | |
| 127 | } | |
| 128 | ||
| 129 | if(JM_TS_JEP_0022 == (jm->typing_style & JM_TS_JEP_0022)) { | |
| 8400 | 130 | jbr->capabilities |= JABBER_CAP_COMPOSING; |
| 13708 | 131 | } |
| 132 | ||
| 8400 | 133 | if(jbr->thread_id) |
| 134 | g_free(jbr->thread_id); | |
| 135 | jbr->thread_id = g_strdup(jbr->thread_id); | |
| 136 | } | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
137 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
138 | 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
|
139 | char *tmp = jm->body; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
140 | 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
|
141 | g_free(tmp); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
142 | } |
| 7014 | 143 | serv_got_im(jm->js->gc, from, jm->xhtml ? jm->xhtml : jm->body, 0, |
| 144 | jm->sent); | |
| 145 | } | |
| 146 | ||
| 13708 | 147 | |
| 7014 | 148 | g_free(from); |
| 149 | jabber_id_free(jid); | |
| 150 | } | |
| 151 | ||
| 7145 | 152 | static void handle_headline(JabberMessage *jm) |
| 153 | { | |
| 154 | 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
|
155 | GString *body; |
| 7145 | 156 | GList *etc; |
| 157 | ||
|
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
|
158 | 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
|
159 | return; /* ignore headlines without any content */ |
| 7145 | 160 | |
|
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
|
161 | body = g_string_new(""); |
| 7145 | 162 | title = g_strdup_printf(_("Message from %s"), jm->from); |
| 163 | ||
| 164 | if(jm->xhtml) | |
| 165 | g_string_append(body, jm->xhtml); | |
| 166 | else if(jm->body) | |
| 167 | g_string_append(body, jm->body); | |
| 168 | ||
| 169 | for(etc = jm->etc; etc; etc = etc->next) { | |
| 170 | xmlnode *x = etc->data; | |
| 13808 | 171 | const char *xmlns = xmlnode_get_namespace(x); |
| 7145 | 172 | if(xmlns && !strcmp(xmlns, "jabber:x:oob")) { |
| 173 | xmlnode *url, *desc; | |
| 174 | char *urltxt, *desctxt; | |
| 175 | ||
| 176 | url = xmlnode_get_child(x, "url"); | |
| 177 | desc = xmlnode_get_child(x, "desc"); | |
| 178 | ||
| 179 | if(!url || !desc) | |
| 180 | continue; | |
| 181 | ||
| 182 | urltxt = xmlnode_get_data(url); | |
| 183 | desctxt = xmlnode_get_data(desc); | |
| 184 | ||
| 185 | /* I'm all about ugly hacks */ | |
|
14790
a0226bec3707
[gaim-migrate @ 17484]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
186 | if(body->len && jm->body && !strcmp(body->str, jm->body)) |
| 7145 | 187 | g_string_printf(body, "<a href='%s'>%s</a>", |
| 188 | urltxt, desctxt); | |
| 189 | else | |
| 190 | g_string_append_printf(body, "<br/><a href='%s'>%s</a>", | |
| 191 | urltxt, desctxt); | |
| 192 | ||
| 193 | g_free(urltxt); | |
| 194 | g_free(desctxt); | |
| 195 | } | |
| 196 | } | |
| 197 | ||
| 15884 | 198 | purple_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title, |
| 7145 | 199 | NULL, body->str, NULL, NULL); |
| 200 | ||
| 201 | g_free(title); | |
| 202 | g_string_free(body, TRUE); | |
| 203 | } | |
| 204 | ||
| 205 | static void handle_groupchat(JabberMessage *jm) | |
| 7014 | 206 | { |
| 207 | JabberID *jid = jabber_id_new(jm->from); | |
| 7310 | 208 | JabberChat *chat; |
| 209 | ||
| 210 | if(!jid) | |
| 211 | return; | |
| 212 | ||
| 213 | chat = jabber_chat_find(jm->js, jid->node, jid->domain); | |
| 7014 | 214 | |
| 215 | if(!chat) | |
| 216 | return; | |
| 217 | ||
| 7971 | 218 | if(jm->subject) { |
| 15884 | 219 | purple_conv_chat_set_topic(PURPLE_CONV_CHAT(chat->conv), jid->resource, |
| 7183 | 220 | jm->subject); |
| 7971 | 221 | if(!jm->xhtml && !jm->body) { |
| 9762 | 222 | char *msg, *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10607
diff
changeset
|
223 | tmp = g_markup_escape_text(jm->subject, -1); |
| 15884 | 224 | tmp2 = purple_markup_linkify(tmp); |
| 7971 | 225 | if(jid->resource) |
| 9762 | 226 | msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, tmp2); |
| 7971 | 227 | else |
| 9762 | 228 | msg = g_strdup_printf(_("The topic is: %s"), tmp2); |
| 15884 | 229 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", msg, PURPLE_MESSAGE_SYSTEM, jm->sent); |
| 9762 | 230 | g_free(tmp); |
| 231 | g_free(tmp2); | |
| 7971 | 232 | g_free(msg); |
| 233 | } | |
| 234 | } | |
| 7014 | 235 | |
| 7630 | 236 | if(jm->xhtml || jm->body) { |
| 237 | if(jid->resource) | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
238 | serv_got_chat_in(jm->js->gc, chat->id, jid->resource, |
| 15884 | 239 | jm->delayed ? PURPLE_MESSAGE_DELAYED : 0, |
| 7630 | 240 | jm->xhtml ? jm->xhtml : jm->body, jm->sent); |
| 241 | else if(chat->muc) | |
| 15884 | 242 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", |
| 7630 | 243 | jm->xhtml ? jm->xhtml : jm->body, |
| 15884 | 244 | PURPLE_MESSAGE_SYSTEM, jm->sent); |
| 7630 | 245 | } |
| 246 | ||
| 7014 | 247 | jabber_id_free(jid); |
| 248 | } | |
| 249 | ||
| 7145 | 250 | static void handle_groupchat_invite(JabberMessage *jm) |
| 7014 | 251 | { |
| 7310 | 252 | GHashTable *components; |
| 7014 | 253 | JabberID *jid = jabber_id_new(jm->to); |
| 254 | ||
| 7310 | 255 | if(!jid) |
| 256 | return; | |
| 257 | ||
|
15598
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
258 | components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); |
| 7310 | 259 | |
|
15598
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
260 | 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
|
261 | 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
|
262 | 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
|
263 | g_hash_table_replace(components, "password", g_strdup(jm->password)); |
| 7014 | 264 | |
| 265 | jabber_id_free(jid); | |
|
10774
f4238d6312ff
[gaim-migrate @ 12383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
266 | serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components); |
| 7014 | 267 | } |
| 268 | ||
| 7145 | 269 | static void handle_error(JabberMessage *jm) |
| 7014 | 270 | { |
| 271 | char *buf; | |
| 272 | ||
| 273 | if(!jm->body) | |
| 274 | return; | |
| 275 | ||
| 276 | buf = g_strdup_printf(_("Message delivery to %s failed: %s"), | |
|
13766
6b92ce47f7e5
[gaim-migrate @ 16176]
Daniel Atallah <datallah@pidgin.im>
parents:
13708
diff
changeset
|
277 | jm->from, jm->error ? jm->error : ""); |
| 7014 | 278 | |
|
16961
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16946
diff
changeset
|
279 | purple_notify_formatted(jm->js->gc, _("XMPP Message Error"), _("XMPP Message Error"), buf, |
| 7944 | 280 | jm->xhtml ? jm->xhtml : jm->body, NULL, NULL); |
| 7014 | 281 | |
| 282 | g_free(buf); | |
| 283 | } | |
| 284 | ||
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
285 | static void handle_buzz(JabberMessage *jm) { |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
286 | PurpleBuddy *buddy; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
287 | PurpleAccount *account; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
288 | PurpleConversation *c; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
289 | char *username, *str; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
290 | |
|
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
|
291 | /* 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
|
292 | 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
|
293 | return; |
|
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 | |
|
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
|
295 | /* 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
|
296 | 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
|
297 | return; |
|
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 | |
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
299 | account = purple_connection_get_account(jm->js->gc); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
300 | |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
301 | if ((buddy = purple_find_buddy(account, jm->from)) != NULL) |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
302 | username = g_markup_escape_text(purple_buddy_get_alias(buddy), -1); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
303 | else |
|
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
|
304 | 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
|
305 | |
|
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 | c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, jm->from); |
|
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
|
307 | |
|
19917
7b4afc4cb984
Make the XMPP buzz string match the Yahoo one to help the translators.
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
308 | str = g_strdup_printf(_("%s has buzzed you!"), username); |
|
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 | purple_conversation_write(c, NULL, str, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL)); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
311 | g_free(username); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
312 | g_free(str); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
313 | } |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
314 | |
| 7014 | 315 | void jabber_message_parse(JabberStream *js, xmlnode *packet) |
| 316 | { | |
| 317 | JabberMessage *jm; | |
| 318 | const char *type; | |
| 319 | xmlnode *child; | |
| 320 | ||
| 321 | jm = g_new0(JabberMessage, 1); | |
| 322 | jm->js = js; | |
| 323 | jm->sent = time(NULL); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
324 | jm->delayed = FALSE; |
| 7014 | 325 | |
| 326 | type = xmlnode_get_attrib(packet, "type"); | |
| 327 | ||
| 328 | if(type) { | |
| 329 | if(!strcmp(type, "normal")) | |
| 330 | jm->type = JABBER_MESSAGE_NORMAL; | |
|
20169
497e1cd1e059
Merged xmpp leak fixes
Evan Schoenberg <evands@pidgin.im>
parents:
20057
diff
changeset
|
331 | else if(!strcmp(type, "chat")) |
| 7014 | 332 | jm->type = JABBER_MESSAGE_CHAT; |
| 333 | else if(!strcmp(type, "groupchat")) | |
| 334 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 335 | else if(!strcmp(type, "headline")) | |
| 336 | jm->type = JABBER_MESSAGE_HEADLINE; | |
| 337 | else if(!strcmp(type, "error")) | |
| 338 | jm->type = JABBER_MESSAGE_ERROR; | |
| 339 | else | |
| 340 | jm->type = JABBER_MESSAGE_OTHER; | |
| 341 | } else { | |
| 342 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 343 | } | |
| 344 | ||
| 345 | jm->from = g_strdup(xmlnode_get_attrib(packet, "from")); | |
| 346 | jm->to = g_strdup(xmlnode_get_attrib(packet, "to")); | |
| 13484 | 347 | jm->id = g_strdup(xmlnode_get_attrib(packet, "id")); |
| 7014 | 348 | |
| 349 | 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
|
350 | const char *xmlns = xmlnode_get_namespace(child); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
351 | if(!xmlns) |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
352 | xmlns = ""; |
| 8135 | 353 | if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 354 | continue; |
| 355 | ||
|
17792
d2023e27affd
Fixed a bug that resulted in not being able to receive any messages.
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
356 | if(!strcmp(child->name, "subject") && !strcmp(xmlns,"jabber:client")) { |
| 7014 | 357 | if(!jm->subject) |
| 358 | jm->subject = 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
|
359 | } else if(!strcmp(child->name, "thread") && !strcmp(xmlns,"jabber:client")) { |
| 8400 | 360 | if(!jm->thread_id) |
| 361 | 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
|
362 | } else if(!strcmp(child->name, "body") && !strcmp(xmlns,"jabber:client")) { |
| 13385 | 363 | if(!jm->body) { |
| 364 | char *msg = xmlnode_to_str(child, NULL); | |
| 15884 | 365 | jm->body = purple_strdup_withhtml(msg); |
| 13385 | 366 | g_free(msg); |
| 367 | } | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
368 | } 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
|
369 | 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
|
370 | char *c; |
| 7642 | 371 | jm->xhtml = xmlnode_to_str(child, NULL); |
|
17328
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
372 | /* Convert all newlines to whitespace. Technically, even regular, non-XML HTML is supposed to ignore newlines, but Pidgin has, as convention |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
373 | * treated \n as a newline for compatibility with other protocols |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
374 | */ |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
375 | for (c = jm->xhtml; *c != '\0'; c++) { |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
376 | if (*c == '\n') |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
377 | *c = ' '; |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
378 | } |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
379 | } |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
380 | } else if(!strcmp(child->name, "active") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 381 | jm->chat_state = JM_STATE_ACTIVE; |
| 382 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
383 | } else if(!strcmp(child->name, "composing") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 384 | jm->chat_state = JM_STATE_COMPOSING; |
| 385 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
386 | } else if(!strcmp(child->name, "paused") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 387 | jm->chat_state = JM_STATE_PAUSED; |
| 388 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
389 | } else if(!strcmp(child->name, "inactive") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 390 | jm->chat_state = JM_STATE_INACTIVE; |
| 391 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
392 | } else if(!strcmp(child->name, "gone") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 393 | jm->chat_state = JM_STATE_GONE; |
| 394 | 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
|
395 | } 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
|
396 | xmlnode *items; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
397 | 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
|
398 | 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
|
399 | jm->eventitems = g_list_append(jm->eventitems, items); |
|
18996
9c15c80fec2a
Updated attention namespace to adhere to my new XEP-0224: Attention
Andreas Monitzer <am@adiumx.com>
parents:
17824
diff
changeset
|
400 | } else if(!strcmp(child->name, "attention") && !strcmp(xmlns,"http://www.xmpp.org/extensions/xep-0224.html#ns")) { |
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
401 | jm->hasBuzz = TRUE; |
| 7014 | 402 | } else if(!strcmp(child->name, "error")) { |
| 403 | const char *code = xmlnode_get_attrib(child, "code"); | |
| 404 | char *code_txt = NULL; | |
| 405 | char *text = xmlnode_get_data(child); | |
|
23240
e8e5763bfe8e
If we receive a "text" child for an error, include it as the message text
Evan Schoenberg <evands@pidgin.im>
parents:
21453
diff
changeset
|
406 | if (!text) { |
|
e8e5763bfe8e
If we receive a "text" child for an error, include it as the message text
Evan Schoenberg <evands@pidgin.im>
parents:
21453
diff
changeset
|
407 | xmlnode *enclosed_text_node; |
|
e8e5763bfe8e
If we receive a "text" child for an error, include it as the message text
Evan Schoenberg <evands@pidgin.im>
parents:
21453
diff
changeset
|
408 | |
|
e8e5763bfe8e
If we receive a "text" child for an error, include it as the message text
Evan Schoenberg <evands@pidgin.im>
parents:
21453
diff
changeset
|
409 | if ((enclosed_text_node = xmlnode_get_child(child, "text"))) |
|
e8e5763bfe8e
If we receive a "text" child for an error, include it as the message text
Evan Schoenberg <evands@pidgin.im>
parents:
21453
diff
changeset
|
410 | text = xmlnode_get_data(enclosed_text_node); |
|
e8e5763bfe8e
If we receive a "text" child for an error, include it as the message text
Evan Schoenberg <evands@pidgin.im>
parents:
21453
diff
changeset
|
411 | } |
| 7014 | 412 | |
| 413 | if(code) | |
|
23244
b785fbd09111
Don't include the space in the localized text at all for the text/code error separation
Evan Schoenberg <evands@pidgin.im>
parents:
23243
diff
changeset
|
414 | code_txt = g_strdup_printf(_("(Code %s)"), code); |
| 7014 | 415 | |
| 416 | if(!jm->error) | |
|
23244
b785fbd09111
Don't include the space in the localized text at all for the text/code error separation
Evan Schoenberg <evands@pidgin.im>
parents:
23243
diff
changeset
|
417 | jm->error = g_strdup_printf("%s%s%s", |
|
b785fbd09111
Don't include the space in the localized text at all for the text/code error separation
Evan Schoenberg <evands@pidgin.im>
parents:
23243
diff
changeset
|
418 | text ? text : "", |
| 23249 | 419 | text && code_txt ? " " : "", |
| 7014 | 420 | code_txt ? code_txt : ""); |
| 421 | ||
| 422 | g_free(code_txt); | |
| 423 | g_free(text); | |
|
17811
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
424 | } else if(!strcmp(child->name, "delay") && xmlns && !strcmp(xmlns,"urn:xmpp:delay")) { |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
425 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
426 | jm->delayed = TRUE; |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
427 | if(timestamp) |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
428 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 429 | } else if(!strcmp(child->name, "x")) { |
| 430 | if(xmlns && !strcmp(xmlns, "jabber:x:event")) { | |
| 13708 | 431 | if(xmlnode_get_child(child, "composing")) { |
| 432 | if(jm->chat_state == JM_STATE_ACTIVE) | |
| 433 | jm->chat_state = JM_STATE_COMPOSING; | |
| 434 | jm->typing_style |= JM_TS_JEP_0022; | |
| 435 | } | |
| 7014 | 436 | } else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 437 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
438 | jm->delayed = TRUE; |
| 7014 | 439 | if(timestamp) |
| 15884 | 440 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 441 | } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") && |
| 11230 | 442 | jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE && |
| 443 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 444 | const char *jid = xmlnode_get_attrib(child, "jid"); |
| 445 | if(jid) { | |
| 446 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 447 | g_free(jm->to); | |
| 448 | jm->to = g_strdup(jid); | |
| 449 | } | |
| 450 | } else if(xmlns && !strcmp(xmlns, | |
| 11230 | 451 | "http://jabber.org/protocol/muc#user") && |
| 452 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 453 | xmlnode *invite = xmlnode_get_child(child, "invite"); |
| 454 | if(invite) { | |
| 455 | xmlnode *reason, *password; | |
| 7968 | 456 | const char *jid = xmlnode_get_attrib(invite, "from"); |
| 7014 | 457 | g_free(jm->to); |
| 458 | jm->to = jm->from; | |
| 459 | jm->from = g_strdup(jid); | |
| 460 | if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 461 | g_free(jm->body); | |
| 462 | jm->body = xmlnode_get_data(reason); | |
| 463 | } | |
| 11576 | 464 | if((password = xmlnode_get_child(child, "password"))) |
| 7014 | 465 | jm->password = xmlnode_get_data(password); |
| 466 | ||
| 467 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 468 | } | |
| 7145 | 469 | } else { |
| 470 | jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 471 | } |
| 472 | } | |
| 473 | } | |
| 474 | ||
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
475 | if(jm->hasBuzz) |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
476 | handle_buzz(jm); |
| 7014 | 477 | |
| 478 | switch(jm->type) { | |
| 479 | case JABBER_MESSAGE_NORMAL: | |
| 480 | case JABBER_MESSAGE_CHAT: | |
| 7145 | 481 | handle_chat(jm); |
| 482 | break; | |
| 7014 | 483 | case JABBER_MESSAGE_HEADLINE: |
| 7145 | 484 | handle_headline(jm); |
| 7014 | 485 | break; |
| 486 | case JABBER_MESSAGE_GROUPCHAT: | |
| 487 | handle_groupchat(jm); | |
| 488 | break; | |
| 489 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 490 | handle_groupchat_invite(jm); | |
| 491 | break; | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
492 | case JABBER_MESSAGE_EVENT: |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
493 | jabber_handle_event(jm); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
494 | break; |
| 7014 | 495 | case JABBER_MESSAGE_ERROR: |
| 496 | handle_error(jm); | |
| 497 | break; | |
| 498 | case JABBER_MESSAGE_OTHER: | |
| 15884 | 499 | purple_debug(PURPLE_DEBUG_INFO, "jabber", |
| 7014 | 500 | "Received message of unknown type: %s\n", type); |
| 501 | break; | |
| 502 | } | |
| 503 | jabber_message_free(jm); | |
| 504 | } | |
| 505 | ||
| 506 | void jabber_message_send(JabberMessage *jm) | |
| 507 | { | |
| 508 | xmlnode *message, *child; | |
| 509 | const char *type = NULL; | |
| 510 | ||
| 511 | message = xmlnode_new("message"); | |
| 512 | ||
| 513 | switch(jm->type) { | |
| 514 | case JABBER_MESSAGE_NORMAL: | |
| 515 | type = "normal"; | |
| 516 | break; | |
| 517 | case JABBER_MESSAGE_CHAT: | |
| 518 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 519 | type = "chat"; | |
| 520 | break; | |
| 521 | case JABBER_MESSAGE_HEADLINE: | |
| 522 | type = "headline"; | |
| 523 | break; | |
| 524 | case JABBER_MESSAGE_GROUPCHAT: | |
| 525 | type = "groupchat"; | |
| 526 | break; | |
| 527 | case JABBER_MESSAGE_ERROR: | |
| 528 | type = "error"; | |
| 529 | break; | |
| 530 | 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
|
531 | default: |
| 7014 | 532 | type = NULL; |
| 533 | break; | |
| 534 | } | |
| 535 | ||
| 536 | if(type) | |
| 537 | xmlnode_set_attrib(message, "type", type); | |
| 13484 | 538 | |
| 539 | if (jm->id) | |
| 540 | xmlnode_set_attrib(message, "id", jm->id); | |
| 7014 | 541 | |
| 542 | xmlnode_set_attrib(message, "to", jm->to); | |
| 543 | ||
| 8400 | 544 | if(jm->thread_id) { |
| 545 | child = xmlnode_new_child(message, "thread"); | |
| 546 | xmlnode_insert_data(child, jm->thread_id, -1); | |
| 547 | } | |
| 548 | ||
| 13708 | 549 | if(JM_TS_JEP_0022 == (jm->typing_style & JM_TS_JEP_0022)) { |
| 7014 | 550 | child = xmlnode_new_child(message, "x"); |
| 13808 | 551 | xmlnode_set_namespace(child, "jabber:x:event"); |
| 13708 | 552 | if(jm->chat_state == JM_STATE_COMPOSING || jm->body) |
| 7014 | 553 | xmlnode_new_child(child, "composing"); |
| 554 | } | |
| 555 | ||
| 13708 | 556 | if(JM_TS_JEP_0085 == (jm->typing_style & JM_TS_JEP_0085)) { |
| 557 | child = NULL; | |
| 558 | switch(jm->chat_state) | |
| 559 | { | |
| 560 | case JM_STATE_ACTIVE: | |
| 561 | child = xmlnode_new_child(message, "active"); | |
| 562 | break; | |
| 563 | case JM_STATE_COMPOSING: | |
| 564 | child = xmlnode_new_child(message, "composing"); | |
| 565 | break; | |
| 566 | case JM_STATE_PAUSED: | |
| 567 | child = xmlnode_new_child(message, "paused"); | |
| 568 | break; | |
| 569 | case JM_STATE_INACTIVE: | |
| 570 | child = xmlnode_new_child(message, "inactive"); | |
| 571 | break; | |
| 572 | case JM_STATE_GONE: | |
| 573 | child = xmlnode_new_child(message, "gone"); | |
| 574 | break; | |
| 575 | } | |
| 576 | if(child) | |
| 13808 | 577 | xmlnode_set_namespace(child, "http://jabber.org/protocol/chatstates"); |
| 13708 | 578 | } |
| 579 | ||
| 7014 | 580 | if(jm->subject) { |
| 581 | child = xmlnode_new_child(message, "subject"); | |
| 582 | xmlnode_insert_data(child, jm->subject, -1); | |
| 583 | } | |
| 584 | ||
| 585 | if(jm->body) { | |
| 586 | child = xmlnode_new_child(message, "body"); | |
| 587 | xmlnode_insert_data(child, jm->body, -1); | |
| 588 | } | |
| 589 | ||
| 590 | if(jm->xhtml) { | |
| 591 | child = xmlnode_from_str(jm->xhtml, -1); | |
| 592 | if(child) { | |
| 593 | xmlnode_insert_child(message, child); | |
| 594 | } else { | |
| 15884 | 595 | purple_debug(PURPLE_DEBUG_ERROR, "jabber", |
| 7014 | 596 | "XHTML translation/validation failed, returning: %s\n", |
| 597 | jm->xhtml); | |
| 598 | } | |
| 599 | } | |
| 600 | ||
| 601 | jabber_send(jm->js, message); | |
| 602 | ||
| 603 | xmlnode_free(message); | |
| 604 | } | |
| 605 | ||
| 15884 | 606 | int jabber_message_send_im(PurpleConnection *gc, const char *who, const char *msg, |
| 607 | PurpleMessageFlags flags) | |
| 7014 | 608 | { |
| 609 | JabberMessage *jm; | |
| 610 | JabberBuddy *jb; | |
| 611 | JabberBuddyResource *jbr; | |
| 612 | char *buf; | |
| 7135 | 613 | char *xhtml; |
| 7306 | 614 | char *resource; |
| 7014 | 615 | |
| 616 | if(!who || !msg) | |
| 617 | return 0; | |
| 618 | ||
| 7306 | 619 | resource = jabber_get_resource(who); |
| 620 | ||
| 7014 | 621 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); |
| 7306 | 622 | jbr = jabber_buddy_find_resource(jb, resource); |
| 623 | ||
| 624 | g_free(resource); | |
| 7014 | 625 | |
| 626 | jm = g_new0(JabberMessage, 1); | |
| 627 | jm->js = gc->proto_data; | |
| 628 | jm->type = JABBER_MESSAGE_CHAT; | |
| 13708 | 629 | jm->chat_state = JM_STATE_ACTIVE; |
| 7014 | 630 | jm->to = g_strdup(who); |
| 13484 | 631 | jm->id = jabber_get_next_id(jm->js); |
| 13708 | 632 | jm->chat_state = JM_STATE_ACTIVE; |
| 633 | ||
| 634 | if(jbr) { | |
| 635 | if(jbr->thread_id) | |
| 636 | jm->thread_id = jbr->thread_id; | |
| 637 | ||
| 638 | if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) { | |
| 639 | jm->typing_style |= JM_TS_JEP_0085; | |
| 640 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) | |
| 641 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ | |
| 642 | } | |
| 643 | ||
| 644 | if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED) | |
| 645 | jm->typing_style |= JM_TS_JEP_0022; | |
| 646 | } | |
| 7014 | 647 | |
| 7773 | 648 | buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg); |
|
17328
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
649 | |
| 15884 | 650 | purple_markup_html_to_xhtml(buf, &xhtml, &jm->body); |
| 7014 | 651 | g_free(buf); |
| 652 | ||
| 653 | if(!jbr || jbr->capabilities & JABBER_CAP_XHTML) | |
| 654 | jm->xhtml = xhtml; | |
| 655 | else | |
| 656 | g_free(xhtml); | |
| 657 | ||
| 658 | jabber_message_send(jm); | |
| 659 | jabber_message_free(jm); | |
| 660 | return 1; | |
| 661 | } | |
| 662 | ||
| 15884 | 663 | int jabber_message_send_chat(PurpleConnection *gc, int id, const char *msg, PurpleMessageFlags flags) |
| 7014 | 664 | { |
| 665 | JabberChat *chat; | |
| 666 | JabberMessage *jm; | |
| 8042 | 667 | JabberStream *js; |
| 9130 | 668 | char *buf; |
| 7014 | 669 | |
| 8042 | 670 | if(!msg || !gc) |
| 7014 | 671 | return 0; |
| 672 | ||
| 8042 | 673 | js = gc->proto_data; |
| 7014 | 674 | chat = jabber_chat_find_by_id(js, id); |
| 675 | ||
| 8043 | 676 | if(!chat) |
| 677 | return 0; | |
| 678 | ||
| 9130 | 679 | jm = g_new0(JabberMessage, 1); |
| 680 | jm->js = gc->proto_data; | |
| 681 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 682 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 13484 | 683 | jm->id = jabber_get_next_id(jm->js); |
| 9130 | 684 | |
| 8858 | 685 | 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 | 686 | purple_markup_html_to_xhtml(buf, &jm->xhtml, &jm->body); |
| 8858 | 687 | g_free(buf); |
| 688 | ||
| 9130 | 689 | if(!chat->xhtml) { |
| 690 | g_free(jm->xhtml); | |
| 691 | jm->xhtml = NULL; | |
| 7923 | 692 | } |
| 693 | ||
| 9130 | 694 | jabber_message_send(jm); |
| 695 | jabber_message_free(jm); | |
| 696 | ||
| 7014 | 697 | return 1; |
| 698 | } | |
| 699 | ||
| 15884 | 700 | unsigned int jabber_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) |
| 7014 | 701 | { |
| 702 | JabberMessage *jm; | |
| 703 | JabberBuddy *jb; | |
| 704 | JabberBuddyResource *jbr; | |
| 7306 | 705 | char *resource = jabber_get_resource(who); |
| 7014 | 706 | |
| 707 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); | |
| 7306 | 708 | jbr = jabber_buddy_find_resource(jb, resource); |
| 709 | ||
| 710 | g_free(resource); | |
| 7014 | 711 | |
| 13708 | 712 | if(!jbr || !((jbr->capabilities & JABBER_CAP_COMPOSING) || (jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED))) |
| 7014 | 713 | return 0; |
| 714 | ||
| 13708 | 715 | /* TODO: figure out threading */ |
| 7014 | 716 | jm = g_new0(JabberMessage, 1); |
| 717 | jm->js = gc->proto_data; | |
| 718 | jm->type = JABBER_MESSAGE_CHAT; | |
| 719 | jm->to = g_strdup(who); | |
| 13484 | 720 | jm->id = jabber_get_next_id(jm->js); |
| 7014 | 721 | |
| 15884 | 722 | if(PURPLE_TYPING == state) |
| 13708 | 723 | jm->chat_state = JM_STATE_COMPOSING; |
| 15884 | 724 | else if(PURPLE_TYPED == state) |
| 13708 | 725 | jm->chat_state = JM_STATE_PAUSED; |
| 726 | else | |
| 727 | jm->chat_state = JM_STATE_ACTIVE; | |
| 728 | ||
| 729 | if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) { | |
| 730 | jm->typing_style |= JM_TS_JEP_0085; | |
| 731 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) | |
| 732 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ | |
| 733 | } | |
| 734 | ||
| 735 | if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED) | |
| 736 | jm->typing_style |= JM_TS_JEP_0022; | |
| 7014 | 737 | |
| 738 | jabber_message_send(jm); | |
| 739 | jabber_message_free(jm); | |
| 740 | ||
| 13708 | 741 | return 0; |
| 7014 | 742 | } |
| 743 | ||
|
15709
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
744 | void jabber_message_conv_closed(JabberStream *js, const char *who) |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
745 | { |
|
19419
c4d5b0a8507f
Only send conversation close notices on XMPP when the typing notification preference is turned on
Sean Egan <seanegan@pidgin.im>
parents:
17351
diff
changeset
|
746 | JabberMessage *jm; |
|
c4d5b0a8507f
Only send conversation close notices on XMPP when the typing notification preference is turned on
Sean Egan <seanegan@pidgin.im>
parents:
17351
diff
changeset
|
747 | if (!purple_prefs_get_bool("/purple/conversations/im/send_typing")) |
|
c4d5b0a8507f
Only send conversation close notices on XMPP when the typing notification preference is turned on
Sean Egan <seanegan@pidgin.im>
parents:
17351
diff
changeset
|
748 | return; |
|
c4d5b0a8507f
Only send conversation close notices on XMPP when the typing notification preference is turned on
Sean Egan <seanegan@pidgin.im>
parents:
17351
diff
changeset
|
749 | |
|
c4d5b0a8507f
Only send conversation close notices on XMPP when the typing notification preference is turned on
Sean Egan <seanegan@pidgin.im>
parents:
17351
diff
changeset
|
750 | jm = g_new0(JabberMessage, 1); |
|
15709
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
751 | jm->js = js; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
752 | jm->type = JABBER_MESSAGE_CHAT; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
753 | jm->to = g_strdup(who); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
754 | jm->id = jabber_get_next_id(jm->js); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
755 | jm->typing_style = JM_TS_JEP_0085; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
756 | jm->chat_state = JM_STATE_GONE; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
757 | jabber_message_send(jm); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
758 | jabber_message_free(jm); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
759 | } |
|
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
|
760 | |
|
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
|
761 | gboolean jabber_buzz_isenabled(JabberStream *js, const gchar *shortname, const gchar *namespace) { |
|
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
|
762 | 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
|
763 | } |
|
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
|
764 |