Thu, 20 Mar 2008 02:59:50 +0000
If the default value of a list-single or list-multi data forms field is NULL
(<value/> or <value></value>) don't stick NULL in the selected list (this will
crash in the g_list_find_custom call later).
| 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); | |
| 406 | ||
| 407 | if(code) | |
| 408 | code_txt = g_strdup_printf(_(" (Code %s)"), code); | |
| 409 | ||
| 410 | if(!jm->error) | |
| 411 | jm->error = g_strdup_printf("%s%s", text ? text : "", | |
| 412 | code_txt ? code_txt : ""); | |
| 413 | ||
| 414 | g_free(code_txt); | |
| 415 | g_free(text); | |
|
17811
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
416 | } 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
|
417 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
418 | jm->delayed = TRUE; |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
419 | if(timestamp) |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
420 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 421 | } else if(!strcmp(child->name, "x")) { |
| 422 | if(xmlns && !strcmp(xmlns, "jabber:x:event")) { | |
| 13708 | 423 | if(xmlnode_get_child(child, "composing")) { |
| 424 | if(jm->chat_state == JM_STATE_ACTIVE) | |
| 425 | jm->chat_state = JM_STATE_COMPOSING; | |
| 426 | jm->typing_style |= JM_TS_JEP_0022; | |
| 427 | } | |
| 7014 | 428 | } else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 429 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
430 | jm->delayed = TRUE; |
| 7014 | 431 | if(timestamp) |
| 15884 | 432 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 433 | } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") && |
| 11230 | 434 | jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE && |
| 435 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 436 | const char *jid = xmlnode_get_attrib(child, "jid"); |
| 437 | if(jid) { | |
| 438 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 439 | g_free(jm->to); | |
| 440 | jm->to = g_strdup(jid); | |
| 441 | } | |
| 442 | } else if(xmlns && !strcmp(xmlns, | |
| 11230 | 443 | "http://jabber.org/protocol/muc#user") && |
| 444 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 445 | xmlnode *invite = xmlnode_get_child(child, "invite"); |
| 446 | if(invite) { | |
| 447 | xmlnode *reason, *password; | |
| 7968 | 448 | const char *jid = xmlnode_get_attrib(invite, "from"); |
| 7014 | 449 | g_free(jm->to); |
| 450 | jm->to = jm->from; | |
| 451 | jm->from = g_strdup(jid); | |
| 452 | if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 453 | g_free(jm->body); | |
| 454 | jm->body = xmlnode_get_data(reason); | |
| 455 | } | |
| 11576 | 456 | if((password = xmlnode_get_child(child, "password"))) |
| 7014 | 457 | jm->password = xmlnode_get_data(password); |
| 458 | ||
| 459 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 460 | } | |
| 7145 | 461 | } else { |
| 462 | jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 463 | } |
| 464 | } | |
| 465 | } | |
| 466 | ||
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
467 | if(jm->hasBuzz) |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
468 | handle_buzz(jm); |
| 7014 | 469 | |
| 470 | switch(jm->type) { | |
| 471 | case JABBER_MESSAGE_NORMAL: | |
| 472 | case JABBER_MESSAGE_CHAT: | |
| 7145 | 473 | handle_chat(jm); |
| 474 | break; | |
| 7014 | 475 | case JABBER_MESSAGE_HEADLINE: |
| 7145 | 476 | handle_headline(jm); |
| 7014 | 477 | break; |
| 478 | case JABBER_MESSAGE_GROUPCHAT: | |
| 479 | handle_groupchat(jm); | |
| 480 | break; | |
| 481 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 482 | handle_groupchat_invite(jm); | |
| 483 | break; | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
484 | case JABBER_MESSAGE_EVENT: |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
485 | jabber_handle_event(jm); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
486 | break; |
| 7014 | 487 | case JABBER_MESSAGE_ERROR: |
| 488 | handle_error(jm); | |
| 489 | break; | |
| 490 | case JABBER_MESSAGE_OTHER: | |
| 15884 | 491 | purple_debug(PURPLE_DEBUG_INFO, "jabber", |
| 7014 | 492 | "Received message of unknown type: %s\n", type); |
| 493 | break; | |
| 494 | } | |
| 495 | jabber_message_free(jm); | |
| 496 | } | |
| 497 | ||
| 498 | void jabber_message_send(JabberMessage *jm) | |
| 499 | { | |
| 500 | xmlnode *message, *child; | |
| 501 | const char *type = NULL; | |
| 502 | ||
| 503 | message = xmlnode_new("message"); | |
| 504 | ||
| 505 | switch(jm->type) { | |
| 506 | case JABBER_MESSAGE_NORMAL: | |
| 507 | type = "normal"; | |
| 508 | break; | |
| 509 | case JABBER_MESSAGE_CHAT: | |
| 510 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 511 | type = "chat"; | |
| 512 | break; | |
| 513 | case JABBER_MESSAGE_HEADLINE: | |
| 514 | type = "headline"; | |
| 515 | break; | |
| 516 | case JABBER_MESSAGE_GROUPCHAT: | |
| 517 | type = "groupchat"; | |
| 518 | break; | |
| 519 | case JABBER_MESSAGE_ERROR: | |
| 520 | type = "error"; | |
| 521 | break; | |
| 522 | 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
|
523 | default: |
| 7014 | 524 | type = NULL; |
| 525 | break; | |
| 526 | } | |
| 527 | ||
| 528 | if(type) | |
| 529 | xmlnode_set_attrib(message, "type", type); | |
| 13484 | 530 | |
| 531 | if (jm->id) | |
| 532 | xmlnode_set_attrib(message, "id", jm->id); | |
| 7014 | 533 | |
| 534 | xmlnode_set_attrib(message, "to", jm->to); | |
| 535 | ||
| 8400 | 536 | if(jm->thread_id) { |
| 537 | child = xmlnode_new_child(message, "thread"); | |
| 538 | xmlnode_insert_data(child, jm->thread_id, -1); | |
| 539 | } | |
| 540 | ||
| 13708 | 541 | if(JM_TS_JEP_0022 == (jm->typing_style & JM_TS_JEP_0022)) { |
| 7014 | 542 | child = xmlnode_new_child(message, "x"); |
| 13808 | 543 | xmlnode_set_namespace(child, "jabber:x:event"); |
| 13708 | 544 | if(jm->chat_state == JM_STATE_COMPOSING || jm->body) |
| 7014 | 545 | xmlnode_new_child(child, "composing"); |
| 546 | } | |
| 547 | ||
| 13708 | 548 | if(JM_TS_JEP_0085 == (jm->typing_style & JM_TS_JEP_0085)) { |
| 549 | child = NULL; | |
| 550 | switch(jm->chat_state) | |
| 551 | { | |
| 552 | case JM_STATE_ACTIVE: | |
| 553 | child = xmlnode_new_child(message, "active"); | |
| 554 | break; | |
| 555 | case JM_STATE_COMPOSING: | |
| 556 | child = xmlnode_new_child(message, "composing"); | |
| 557 | break; | |
| 558 | case JM_STATE_PAUSED: | |
| 559 | child = xmlnode_new_child(message, "paused"); | |
| 560 | break; | |
| 561 | case JM_STATE_INACTIVE: | |
| 562 | child = xmlnode_new_child(message, "inactive"); | |
| 563 | break; | |
| 564 | case JM_STATE_GONE: | |
| 565 | child = xmlnode_new_child(message, "gone"); | |
| 566 | break; | |
| 567 | } | |
| 568 | if(child) | |
| 13808 | 569 | xmlnode_set_namespace(child, "http://jabber.org/protocol/chatstates"); |
| 13708 | 570 | } |
| 571 | ||
| 7014 | 572 | if(jm->subject) { |
| 573 | child = xmlnode_new_child(message, "subject"); | |
| 574 | xmlnode_insert_data(child, jm->subject, -1); | |
| 575 | } | |
| 576 | ||
| 577 | if(jm->body) { | |
| 578 | child = xmlnode_new_child(message, "body"); | |
| 579 | xmlnode_insert_data(child, jm->body, -1); | |
| 580 | } | |
| 581 | ||
| 582 | if(jm->xhtml) { | |
| 583 | child = xmlnode_from_str(jm->xhtml, -1); | |
| 584 | if(child) { | |
| 585 | xmlnode_insert_child(message, child); | |
| 586 | } else { | |
| 15884 | 587 | purple_debug(PURPLE_DEBUG_ERROR, "jabber", |
| 7014 | 588 | "XHTML translation/validation failed, returning: %s\n", |
| 589 | jm->xhtml); | |
| 590 | } | |
| 591 | } | |
| 592 | ||
| 593 | jabber_send(jm->js, message); | |
| 594 | ||
| 595 | xmlnode_free(message); | |
| 596 | } | |
| 597 | ||
| 15884 | 598 | int jabber_message_send_im(PurpleConnection *gc, const char *who, const char *msg, |
| 599 | PurpleMessageFlags flags) | |
| 7014 | 600 | { |
| 601 | JabberMessage *jm; | |
| 602 | JabberBuddy *jb; | |
| 603 | JabberBuddyResource *jbr; | |
| 604 | char *buf; | |
| 7135 | 605 | char *xhtml; |
| 7306 | 606 | char *resource; |
| 7014 | 607 | |
| 608 | if(!who || !msg) | |
| 609 | return 0; | |
| 610 | ||
| 7306 | 611 | resource = jabber_get_resource(who); |
| 612 | ||
| 7014 | 613 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); |
| 7306 | 614 | jbr = jabber_buddy_find_resource(jb, resource); |
| 615 | ||
| 616 | g_free(resource); | |
| 7014 | 617 | |
| 618 | jm = g_new0(JabberMessage, 1); | |
| 619 | jm->js = gc->proto_data; | |
| 620 | jm->type = JABBER_MESSAGE_CHAT; | |
| 13708 | 621 | jm->chat_state = JM_STATE_ACTIVE; |
| 7014 | 622 | jm->to = g_strdup(who); |
| 13484 | 623 | jm->id = jabber_get_next_id(jm->js); |
| 13708 | 624 | jm->chat_state = JM_STATE_ACTIVE; |
| 625 | ||
| 626 | if(jbr) { | |
| 627 | if(jbr->thread_id) | |
| 628 | jm->thread_id = jbr->thread_id; | |
| 629 | ||
| 630 | if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) { | |
| 631 | jm->typing_style |= JM_TS_JEP_0085; | |
| 632 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) | |
| 633 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ | |
| 634 | } | |
| 635 | ||
| 636 | if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED) | |
| 637 | jm->typing_style |= JM_TS_JEP_0022; | |
| 638 | } | |
| 7014 | 639 | |
| 7773 | 640 | 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
|
641 | |
| 15884 | 642 | purple_markup_html_to_xhtml(buf, &xhtml, &jm->body); |
| 7014 | 643 | g_free(buf); |
| 644 | ||
| 645 | if(!jbr || jbr->capabilities & JABBER_CAP_XHTML) | |
| 646 | jm->xhtml = xhtml; | |
| 647 | else | |
| 648 | g_free(xhtml); | |
| 649 | ||
| 650 | jabber_message_send(jm); | |
| 651 | jabber_message_free(jm); | |
| 652 | return 1; | |
| 653 | } | |
| 654 | ||
| 15884 | 655 | int jabber_message_send_chat(PurpleConnection *gc, int id, const char *msg, PurpleMessageFlags flags) |
| 7014 | 656 | { |
| 657 | JabberChat *chat; | |
| 658 | JabberMessage *jm; | |
| 8042 | 659 | JabberStream *js; |
| 9130 | 660 | char *buf; |
| 7014 | 661 | |
| 8042 | 662 | if(!msg || !gc) |
| 7014 | 663 | return 0; |
| 664 | ||
| 8042 | 665 | js = gc->proto_data; |
| 7014 | 666 | chat = jabber_chat_find_by_id(js, id); |
| 667 | ||
| 8043 | 668 | if(!chat) |
| 669 | return 0; | |
| 670 | ||
| 9130 | 671 | jm = g_new0(JabberMessage, 1); |
| 672 | jm->js = gc->proto_data; | |
| 673 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 674 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 13484 | 675 | jm->id = jabber_get_next_id(jm->js); |
| 9130 | 676 | |
| 8858 | 677 | 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 | 678 | purple_markup_html_to_xhtml(buf, &jm->xhtml, &jm->body); |
| 8858 | 679 | g_free(buf); |
| 680 | ||
| 9130 | 681 | if(!chat->xhtml) { |
| 682 | g_free(jm->xhtml); | |
| 683 | jm->xhtml = NULL; | |
| 7923 | 684 | } |
| 685 | ||
| 9130 | 686 | jabber_message_send(jm); |
| 687 | jabber_message_free(jm); | |
| 688 | ||
| 7014 | 689 | return 1; |
| 690 | } | |
| 691 | ||
| 15884 | 692 | unsigned int jabber_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) |
| 7014 | 693 | { |
| 694 | JabberMessage *jm; | |
| 695 | JabberBuddy *jb; | |
| 696 | JabberBuddyResource *jbr; | |
| 7306 | 697 | char *resource = jabber_get_resource(who); |
| 7014 | 698 | |
| 699 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); | |
| 7306 | 700 | jbr = jabber_buddy_find_resource(jb, resource); |
| 701 | ||
| 702 | g_free(resource); | |
| 7014 | 703 | |
| 13708 | 704 | if(!jbr || !((jbr->capabilities & JABBER_CAP_COMPOSING) || (jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED))) |
| 7014 | 705 | return 0; |
| 706 | ||
| 13708 | 707 | /* TODO: figure out threading */ |
| 7014 | 708 | jm = g_new0(JabberMessage, 1); |
| 709 | jm->js = gc->proto_data; | |
| 710 | jm->type = JABBER_MESSAGE_CHAT; | |
| 711 | jm->to = g_strdup(who); | |
| 13484 | 712 | jm->id = jabber_get_next_id(jm->js); |
| 7014 | 713 | |
| 15884 | 714 | if(PURPLE_TYPING == state) |
| 13708 | 715 | jm->chat_state = JM_STATE_COMPOSING; |
| 15884 | 716 | else if(PURPLE_TYPED == state) |
| 13708 | 717 | jm->chat_state = JM_STATE_PAUSED; |
| 718 | else | |
| 719 | jm->chat_state = JM_STATE_ACTIVE; | |
| 720 | ||
| 721 | if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) { | |
| 722 | jm->typing_style |= JM_TS_JEP_0085; | |
| 723 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) | |
| 724 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ | |
| 725 | } | |
| 726 | ||
| 727 | if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED) | |
| 728 | jm->typing_style |= JM_TS_JEP_0022; | |
| 7014 | 729 | |
| 730 | jabber_message_send(jm); | |
| 731 | jabber_message_free(jm); | |
| 732 | ||
| 13708 | 733 | return 0; |
| 7014 | 734 | } |
| 735 | ||
|
15709
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
736 | 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
|
737 | { |
|
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
|
738 | 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
|
739 | 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
|
740 | 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
|
741 | |
|
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
|
742 | jm = g_new0(JabberMessage, 1); |
|
15709
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
743 | jm->js = js; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
744 | jm->type = JABBER_MESSAGE_CHAT; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
745 | jm->to = g_strdup(who); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
746 | jm->id = jabber_get_next_id(jm->js); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
747 | jm->typing_style = JM_TS_JEP_0085; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
748 | jm->chat_state = JM_STATE_GONE; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
749 | jabber_message_send(jm); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
750 | jabber_message_free(jm); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
751 | } |
|
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
|
752 | |
|
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
|
753 | 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
|
754 | 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
|
755 | } |
|
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
|
756 |