Fri, 28 Sep 2007 15:45:10 +0000
grab revision 41389df89a4a6a007d41cec33e33043cd41ea159
more leak fixes
| 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); |
|
15721
8b054202d398
Include the user's name/alias in the XEP 85 "gone" messages.
Richard Laager <rlaager@pidgin.im>
parents:
15710
diff
changeset
|
107 | |
| 15884 | 108 | /* 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
|
109 | * 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
|
110 | * user from the conversation like we do with chats now. */ |
| 15884 | 111 | purple_conversation_write(conv, "", buf, |
| 112 | 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
|
113 | } |
|
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
|
114 | } |
| 7014 | 115 | 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
|
116 | |
|
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 | } 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
|
118 | 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
|
119 | } |
| 7014 | 120 | } else { |
| 8400 | 121 | if(jbr) { |
| 13708 | 122 | if(JM_TS_JEP_0085 == (jm->typing_style & JM_TS_JEP_0085)) { |
| 123 | jbr->chat_states = JABBER_CHAT_STATES_SUPPORTED; | |
| 124 | } else { | |
| 125 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; | |
| 126 | } | |
| 127 | ||
| 128 | if(JM_TS_JEP_0022 == (jm->typing_style & JM_TS_JEP_0022)) { | |
| 8400 | 129 | jbr->capabilities |= JABBER_CAP_COMPOSING; |
| 13708 | 130 | } |
| 131 | ||
| 8400 | 132 | if(jbr->thread_id) |
| 133 | g_free(jbr->thread_id); | |
| 134 | jbr->thread_id = g_strdup(jbr->thread_id); | |
| 135 | } | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
136 | |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
137 | 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
|
138 | char *tmp = jm->body; |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
139 | 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
|
140 | g_free(tmp); |
|
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
141 | } |
| 7014 | 142 | serv_got_im(jm->js->gc, from, jm->xhtml ? jm->xhtml : jm->body, 0, |
| 143 | jm->sent); | |
| 144 | } | |
| 145 | ||
| 13708 | 146 | |
| 7014 | 147 | g_free(from); |
| 148 | jabber_id_free(jid); | |
| 149 | } | |
| 150 | ||
| 7145 | 151 | static void handle_headline(JabberMessage *jm) |
| 152 | { | |
| 153 | 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
|
154 | GString *body; |
| 7145 | 155 | GList *etc; |
| 156 | ||
|
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
|
157 | 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
|
158 | return; /* ignore headlines without any content */ |
| 7145 | 159 | |
|
17819
862fe0f947a9
Added buzz support using a private extension. Maybe I should write a XEP about that.
Andreas Monitzer <am@adiumx.com>
parents:
17811
diff
changeset
|
160 | body = g_string_new(""); |
| 7145 | 161 | title = g_strdup_printf(_("Message from %s"), jm->from); |
| 162 | ||
| 163 | if(jm->xhtml) | |
| 164 | g_string_append(body, jm->xhtml); | |
| 165 | else if(jm->body) | |
| 166 | g_string_append(body, jm->body); | |
| 167 | ||
| 168 | for(etc = jm->etc; etc; etc = etc->next) { | |
| 169 | xmlnode *x = etc->data; | |
| 13808 | 170 | const char *xmlns = xmlnode_get_namespace(x); |
| 7145 | 171 | if(xmlns && !strcmp(xmlns, "jabber:x:oob")) { |
| 172 | xmlnode *url, *desc; | |
| 173 | char *urltxt, *desctxt; | |
| 174 | ||
| 175 | url = xmlnode_get_child(x, "url"); | |
| 176 | desc = xmlnode_get_child(x, "desc"); | |
| 177 | ||
| 178 | if(!url || !desc) | |
| 179 | continue; | |
| 180 | ||
| 181 | urltxt = xmlnode_get_data(url); | |
| 182 | desctxt = xmlnode_get_data(desc); | |
| 183 | ||
| 184 | /* I'm all about ugly hacks */ | |
|
14790
a0226bec3707
[gaim-migrate @ 17484]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
185 | if(body->len && jm->body && !strcmp(body->str, jm->body)) |
| 7145 | 186 | g_string_printf(body, "<a href='%s'>%s</a>", |
| 187 | urltxt, desctxt); | |
| 188 | else | |
| 189 | g_string_append_printf(body, "<br/><a href='%s'>%s</a>", | |
| 190 | urltxt, desctxt); | |
| 191 | ||
| 192 | g_free(urltxt); | |
| 193 | g_free(desctxt); | |
| 194 | } | |
| 195 | } | |
| 196 | ||
| 15884 | 197 | purple_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title, |
| 7145 | 198 | NULL, body->str, NULL, NULL); |
| 199 | ||
| 200 | g_free(title); | |
| 201 | g_string_free(body, TRUE); | |
| 202 | } | |
| 203 | ||
| 204 | static void handle_groupchat(JabberMessage *jm) | |
| 7014 | 205 | { |
| 206 | JabberID *jid = jabber_id_new(jm->from); | |
| 7310 | 207 | JabberChat *chat; |
| 208 | ||
| 209 | if(!jid) | |
| 210 | return; | |
| 211 | ||
| 212 | chat = jabber_chat_find(jm->js, jid->node, jid->domain); | |
| 7014 | 213 | |
| 214 | if(!chat) | |
| 215 | return; | |
| 216 | ||
| 7971 | 217 | if(jm->subject) { |
| 15884 | 218 | purple_conv_chat_set_topic(PURPLE_CONV_CHAT(chat->conv), jid->resource, |
| 7183 | 219 | jm->subject); |
| 7971 | 220 | if(!jm->xhtml && !jm->body) { |
| 9762 | 221 | char *msg, *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10607
diff
changeset
|
222 | tmp = g_markup_escape_text(jm->subject, -1); |
| 15884 | 223 | tmp2 = purple_markup_linkify(tmp); |
| 7971 | 224 | if(jid->resource) |
| 9762 | 225 | msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, tmp2); |
| 7971 | 226 | else |
| 9762 | 227 | msg = g_strdup_printf(_("The topic is: %s"), tmp2); |
| 15884 | 228 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", msg, PURPLE_MESSAGE_SYSTEM, jm->sent); |
| 9762 | 229 | g_free(tmp); |
| 230 | g_free(tmp2); | |
| 7971 | 231 | g_free(msg); |
| 232 | } | |
| 233 | } | |
| 7014 | 234 | |
| 7630 | 235 | if(jm->xhtml || jm->body) { |
| 236 | if(jid->resource) | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
237 | serv_got_chat_in(jm->js->gc, chat->id, jid->resource, |
| 15884 | 238 | jm->delayed ? PURPLE_MESSAGE_DELAYED : 0, |
| 7630 | 239 | jm->xhtml ? jm->xhtml : jm->body, jm->sent); |
| 240 | else if(chat->muc) | |
| 15884 | 241 | purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", |
| 7630 | 242 | jm->xhtml ? jm->xhtml : jm->body, |
| 15884 | 243 | PURPLE_MESSAGE_SYSTEM, jm->sent); |
| 7630 | 244 | } |
| 245 | ||
| 7014 | 246 | jabber_id_free(jid); |
| 247 | } | |
| 248 | ||
| 7145 | 249 | static void handle_groupchat_invite(JabberMessage *jm) |
| 7014 | 250 | { |
| 7310 | 251 | GHashTable *components; |
| 7014 | 252 | JabberID *jid = jabber_id_new(jm->to); |
| 253 | ||
| 7310 | 254 | if(!jid) |
| 255 | return; | |
| 256 | ||
|
15598
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
257 | components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); |
| 7310 | 258 | |
|
15598
834a88c83e95
Get rid of some unnecessary string duping
Mark Doliner <markdoliner@pidgin.im>
parents:
15587
diff
changeset
|
259 | 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
|
260 | 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
|
261 | 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
|
262 | g_hash_table_replace(components, "password", g_strdup(jm->password)); |
| 7014 | 263 | |
| 264 | jabber_id_free(jid); | |
|
10774
f4238d6312ff
[gaim-migrate @ 12383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
265 | serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components); |
| 7014 | 266 | } |
| 267 | ||
| 7145 | 268 | static void handle_error(JabberMessage *jm) |
| 7014 | 269 | { |
| 270 | char *buf; | |
| 271 | ||
| 272 | if(!jm->body) | |
| 273 | return; | |
| 274 | ||
| 275 | buf = g_strdup_printf(_("Message delivery to %s failed: %s"), | |
|
13766
6b92ce47f7e5
[gaim-migrate @ 16176]
Daniel Atallah <datallah@pidgin.im>
parents:
13708
diff
changeset
|
276 | jm->from, jm->error ? jm->error : ""); |
| 7014 | 277 | |
|
16961
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16946
diff
changeset
|
278 | purple_notify_formatted(jm->js->gc, _("XMPP Message Error"), _("XMPP Message Error"), buf, |
| 7944 | 279 | jm->xhtml ? jm->xhtml : jm->body, NULL, NULL); |
| 7014 | 280 | |
| 281 | g_free(buf); | |
| 282 | } | |
| 283 | ||
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
284 | static void handle_buzz(JabberMessage *jm) { |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
285 | PurpleBuddy *buddy; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
286 | PurpleAccount *account; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
287 | PurpleConversation *c; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
288 | char *username, *str; |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
289 | |
|
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
|
290 | /* 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
|
291 | 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
|
292 | 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
|
293 | |
|
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
|
294 | /* 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
|
295 | 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
|
296 | 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
|
297 | |
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
298 | account = purple_connection_get_account(jm->js->gc); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
299 | |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
300 | if ((buddy = purple_find_buddy(account, jm->from)) != NULL) |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
301 | 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
|
302 | 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
|
303 | 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
|
304 | |
|
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 | 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
|
306 | |
|
19917
7b4afc4cb984
Make the XMPP buzz string match the Yahoo one to help the translators.
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
307 | str = g_strdup_printf(_("%s has buzzed you!"), username); |
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
308 | |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
309 | 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
|
310 | g_free(username); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
311 | g_free(str); |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
312 | } |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
313 | |
| 7014 | 314 | void jabber_message_parse(JabberStream *js, xmlnode *packet) |
| 315 | { | |
| 316 | JabberMessage *jm; | |
| 317 | const char *type; | |
| 318 | xmlnode *child; | |
| 319 | ||
| 320 | jm = g_new0(JabberMessage, 1); | |
| 321 | jm->js = js; | |
| 322 | jm->sent = time(NULL); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
323 | jm->delayed = FALSE; |
| 7014 | 324 | |
| 325 | type = xmlnode_get_attrib(packet, "type"); | |
| 326 | ||
| 327 | if(type) { | |
| 328 | if(!strcmp(type, "normal")) | |
| 329 | jm->type = JABBER_MESSAGE_NORMAL; | |
|
15587
cbedd543bfae
Google Talk uses structured text formatting where *this* is bold
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
330 | else if(!strcmp(type, "chat")) |
| 7014 | 331 | jm->type = JABBER_MESSAGE_CHAT; |
| 332 | else if(!strcmp(type, "groupchat")) | |
| 333 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 334 | else if(!strcmp(type, "headline")) | |
| 335 | jm->type = JABBER_MESSAGE_HEADLINE; | |
| 336 | else if(!strcmp(type, "error")) | |
| 337 | jm->type = JABBER_MESSAGE_ERROR; | |
| 338 | else | |
| 339 | jm->type = JABBER_MESSAGE_OTHER; | |
| 340 | } else { | |
| 341 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 342 | } | |
| 343 | ||
| 344 | jm->from = g_strdup(xmlnode_get_attrib(packet, "from")); | |
| 345 | jm->to = g_strdup(xmlnode_get_attrib(packet, "to")); | |
| 13484 | 346 | jm->id = g_strdup(xmlnode_get_attrib(packet, "id")); |
| 7014 | 347 | |
| 348 | 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
|
349 | 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
|
350 | if(!xmlns) |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
351 | xmlns = ""; |
| 8135 | 352 | if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 353 | continue; |
| 354 | ||
|
17792
d2023e27affd
Fixed a bug that resulted in not being able to receive any messages.
Andreas Monitzer <am@adiumx.com>
parents:
17780
diff
changeset
|
355 | if(!strcmp(child->name, "subject") && !strcmp(xmlns,"jabber:client")) { |
| 7014 | 356 | if(!jm->subject) |
| 357 | 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
|
358 | } else if(!strcmp(child->name, "thread") && !strcmp(xmlns,"jabber:client")) { |
| 8400 | 359 | if(!jm->thread_id) |
| 360 | 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
|
361 | } else if(!strcmp(child->name, "body") && !strcmp(xmlns,"jabber:client")) { |
| 13385 | 362 | if(!jm->body) { |
| 363 | char *msg = xmlnode_to_str(child, NULL); | |
| 15884 | 364 | jm->body = purple_strdup_withhtml(msg); |
| 13385 | 365 | g_free(msg); |
| 366 | } | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
367 | } 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
|
368 | 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
|
369 | char *c; |
| 7642 | 370 | 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
|
371 | /* 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
|
372 | * 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
|
373 | */ |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
374 | 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
|
375 | if (*c == '\n') |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
376 | *c = ' '; |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
377 | } |
|
7a5668fb7bad
Convert newlines to ' ' when receiving XHTML from Jabber
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
378 | } |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
379 | } else if(!strcmp(child->name, "active") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 380 | jm->chat_state = JM_STATE_ACTIVE; |
| 381 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
382 | } else if(!strcmp(child->name, "composing") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 383 | jm->chat_state = JM_STATE_COMPOSING; |
| 384 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
385 | } else if(!strcmp(child->name, "paused") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 386 | jm->chat_state = JM_STATE_PAUSED; |
| 387 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
388 | } else if(!strcmp(child->name, "inactive") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 389 | jm->chat_state = JM_STATE_INACTIVE; |
| 390 | jm->typing_style |= JM_TS_JEP_0085; | |
|
17768
7be011945a1b
added preliminary frame for pep-support
Andreas Monitzer <am@adiumx.com>
parents:
17351
diff
changeset
|
391 | } else if(!strcmp(child->name, "gone") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) { |
| 13708 | 392 | jm->chat_state = JM_STATE_GONE; |
| 393 | 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
|
394 | } 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
|
395 | xmlnode *items; |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
396 | 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
|
397 | 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
|
398 | 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
|
399 | } 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
|
400 | jm->hasBuzz = TRUE; |
| 7014 | 401 | } else if(!strcmp(child->name, "error")) { |
| 402 | const char *code = xmlnode_get_attrib(child, "code"); | |
| 403 | char *code_txt = NULL; | |
| 404 | char *text = xmlnode_get_data(child); | |
| 405 | ||
| 406 | if(code) | |
| 407 | code_txt = g_strdup_printf(_(" (Code %s)"), code); | |
| 408 | ||
| 409 | if(!jm->error) | |
| 410 | jm->error = g_strdup_printf("%s%s", text ? text : "", | |
| 411 | code_txt ? code_txt : ""); | |
| 412 | ||
| 413 | g_free(code_txt); | |
| 414 | g_free(text); | |
|
17811
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
415 | } 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
|
416 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
417 | jm->delayed = TRUE; |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
418 | if(timestamp) |
|
d9a7ec9277f6
Implemented XEP-0203: Delayed Delivery
Andreas Monitzer <am@adiumx.com>
parents:
17792
diff
changeset
|
419 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 420 | } else if(!strcmp(child->name, "x")) { |
| 421 | if(xmlns && !strcmp(xmlns, "jabber:x:event")) { | |
| 13708 | 422 | if(xmlnode_get_child(child, "composing")) { |
| 423 | if(jm->chat_state == JM_STATE_ACTIVE) | |
| 424 | jm->chat_state = JM_STATE_COMPOSING; | |
| 425 | jm->typing_style |= JM_TS_JEP_0022; | |
| 426 | } | |
| 7014 | 427 | } else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { |
| 428 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
429 | jm->delayed = TRUE; |
| 7014 | 430 | if(timestamp) |
| 15884 | 431 | jm->sent = purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 432 | } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") && |
| 11230 | 433 | jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE && |
| 434 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 435 | const char *jid = xmlnode_get_attrib(child, "jid"); |
| 436 | if(jid) { | |
| 437 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 438 | g_free(jm->to); | |
| 439 | jm->to = g_strdup(jid); | |
| 440 | } | |
| 441 | } else if(xmlns && !strcmp(xmlns, | |
| 11230 | 442 | "http://jabber.org/protocol/muc#user") && |
| 443 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 444 | xmlnode *invite = xmlnode_get_child(child, "invite"); |
| 445 | if(invite) { | |
| 446 | xmlnode *reason, *password; | |
| 7968 | 447 | const char *jid = xmlnode_get_attrib(invite, "from"); |
| 7014 | 448 | g_free(jm->to); |
| 449 | jm->to = jm->from; | |
| 450 | jm->from = g_strdup(jid); | |
| 451 | if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 452 | g_free(jm->body); | |
| 453 | jm->body = xmlnode_get_data(reason); | |
| 454 | } | |
| 11576 | 455 | if((password = xmlnode_get_child(child, "password"))) |
| 7014 | 456 | jm->password = xmlnode_get_data(password); |
| 457 | ||
| 458 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 459 | } | |
| 7145 | 460 | } else { |
| 461 | jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 462 | } |
| 463 | } | |
| 464 | } | |
| 465 | ||
|
17822
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
466 | if(jm->hasBuzz) |
|
1a183f3fa9d7
disapproval of revision 'd52c12703a8e67c41c7f95a2cae7f16ab426ad76'
Andreas Monitzer <am@adiumx.com>
parents:
17821
diff
changeset
|
467 | handle_buzz(jm); |
| 7014 | 468 | |
| 469 | switch(jm->type) { | |
| 470 | case JABBER_MESSAGE_NORMAL: | |
| 471 | case JABBER_MESSAGE_CHAT: | |
| 7145 | 472 | handle_chat(jm); |
| 473 | break; | |
| 7014 | 474 | case JABBER_MESSAGE_HEADLINE: |
| 7145 | 475 | handle_headline(jm); |
| 7014 | 476 | break; |
| 477 | case JABBER_MESSAGE_GROUPCHAT: | |
| 478 | handle_groupchat(jm); | |
| 479 | break; | |
| 480 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 481 | handle_groupchat_invite(jm); | |
| 482 | break; | |
|
17779
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
483 | case JABBER_MESSAGE_EVENT: |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
484 | jabber_handle_event(jm); |
|
773326802e26
Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents:
17776
diff
changeset
|
485 | break; |
| 7014 | 486 | case JABBER_MESSAGE_ERROR: |
| 487 | handle_error(jm); | |
| 488 | break; | |
| 489 | case JABBER_MESSAGE_OTHER: | |
| 15884 | 490 | purple_debug(PURPLE_DEBUG_INFO, "jabber", |
| 7014 | 491 | "Received message of unknown type: %s\n", type); |
| 492 | break; | |
| 493 | } | |
| 494 | jabber_message_free(jm); | |
| 495 | } | |
| 496 | ||
| 497 | void jabber_message_send(JabberMessage *jm) | |
| 498 | { | |
| 499 | xmlnode *message, *child; | |
| 500 | const char *type = NULL; | |
| 501 | ||
| 502 | message = xmlnode_new("message"); | |
| 503 | ||
| 504 | switch(jm->type) { | |
| 505 | case JABBER_MESSAGE_NORMAL: | |
| 506 | type = "normal"; | |
| 507 | break; | |
| 508 | case JABBER_MESSAGE_CHAT: | |
| 509 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 510 | type = "chat"; | |
| 511 | break; | |
| 512 | case JABBER_MESSAGE_HEADLINE: | |
| 513 | type = "headline"; | |
| 514 | break; | |
| 515 | case JABBER_MESSAGE_GROUPCHAT: | |
| 516 | type = "groupchat"; | |
| 517 | break; | |
| 518 | case JABBER_MESSAGE_ERROR: | |
| 519 | type = "error"; | |
| 520 | break; | |
| 521 | 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
|
522 | default: |
| 7014 | 523 | type = NULL; |
| 524 | break; | |
| 525 | } | |
| 526 | ||
| 527 | if(type) | |
| 528 | xmlnode_set_attrib(message, "type", type); | |
| 13484 | 529 | |
| 530 | if (jm->id) | |
| 531 | xmlnode_set_attrib(message, "id", jm->id); | |
| 7014 | 532 | |
| 533 | xmlnode_set_attrib(message, "to", jm->to); | |
| 534 | ||
| 8400 | 535 | if(jm->thread_id) { |
| 536 | child = xmlnode_new_child(message, "thread"); | |
| 537 | xmlnode_insert_data(child, jm->thread_id, -1); | |
| 538 | } | |
| 539 | ||
| 13708 | 540 | if(JM_TS_JEP_0022 == (jm->typing_style & JM_TS_JEP_0022)) { |
| 7014 | 541 | child = xmlnode_new_child(message, "x"); |
| 13808 | 542 | xmlnode_set_namespace(child, "jabber:x:event"); |
| 13708 | 543 | if(jm->chat_state == JM_STATE_COMPOSING || jm->body) |
| 7014 | 544 | xmlnode_new_child(child, "composing"); |
| 545 | } | |
| 546 | ||
| 13708 | 547 | if(JM_TS_JEP_0085 == (jm->typing_style & JM_TS_JEP_0085)) { |
| 548 | child = NULL; | |
| 549 | switch(jm->chat_state) | |
| 550 | { | |
| 551 | case JM_STATE_ACTIVE: | |
| 552 | child = xmlnode_new_child(message, "active"); | |
| 553 | break; | |
| 554 | case JM_STATE_COMPOSING: | |
| 555 | child = xmlnode_new_child(message, "composing"); | |
| 556 | break; | |
| 557 | case JM_STATE_PAUSED: | |
| 558 | child = xmlnode_new_child(message, "paused"); | |
| 559 | break; | |
| 560 | case JM_STATE_INACTIVE: | |
| 561 | child = xmlnode_new_child(message, "inactive"); | |
| 562 | break; | |
| 563 | case JM_STATE_GONE: | |
| 564 | child = xmlnode_new_child(message, "gone"); | |
| 565 | break; | |
| 566 | } | |
| 567 | if(child) | |
| 13808 | 568 | xmlnode_set_namespace(child, "http://jabber.org/protocol/chatstates"); |
| 13708 | 569 | } |
| 570 | ||
| 7014 | 571 | if(jm->subject) { |
| 572 | child = xmlnode_new_child(message, "subject"); | |
| 573 | xmlnode_insert_data(child, jm->subject, -1); | |
| 574 | } | |
| 575 | ||
| 576 | if(jm->body) { | |
| 577 | child = xmlnode_new_child(message, "body"); | |
| 578 | xmlnode_insert_data(child, jm->body, -1); | |
| 579 | } | |
| 580 | ||
| 581 | if(jm->xhtml) { | |
| 582 | child = xmlnode_from_str(jm->xhtml, -1); | |
| 583 | if(child) { | |
| 584 | xmlnode_insert_child(message, child); | |
| 585 | } else { | |
| 15884 | 586 | purple_debug(PURPLE_DEBUG_ERROR, "jabber", |
| 7014 | 587 | "XHTML translation/validation failed, returning: %s\n", |
| 588 | jm->xhtml); | |
| 589 | } | |
| 590 | } | |
| 591 | ||
| 592 | jabber_send(jm->js, message); | |
| 593 | ||
| 594 | xmlnode_free(message); | |
| 595 | } | |
| 596 | ||
| 15884 | 597 | int jabber_message_send_im(PurpleConnection *gc, const char *who, const char *msg, |
| 598 | PurpleMessageFlags flags) | |
| 7014 | 599 | { |
| 600 | JabberMessage *jm; | |
| 601 | JabberBuddy *jb; | |
| 602 | JabberBuddyResource *jbr; | |
| 603 | char *buf; | |
| 7135 | 604 | char *xhtml; |
| 7306 | 605 | char *resource; |
| 7014 | 606 | |
| 607 | if(!who || !msg) | |
| 608 | return 0; | |
| 609 | ||
| 7306 | 610 | resource = jabber_get_resource(who); |
| 611 | ||
| 7014 | 612 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); |
| 7306 | 613 | jbr = jabber_buddy_find_resource(jb, resource); |
| 614 | ||
| 615 | g_free(resource); | |
| 7014 | 616 | |
| 617 | jm = g_new0(JabberMessage, 1); | |
| 618 | jm->js = gc->proto_data; | |
| 619 | jm->type = JABBER_MESSAGE_CHAT; | |
| 13708 | 620 | jm->chat_state = JM_STATE_ACTIVE; |
| 7014 | 621 | jm->to = g_strdup(who); |
| 13484 | 622 | jm->id = jabber_get_next_id(jm->js); |
| 13708 | 623 | jm->chat_state = JM_STATE_ACTIVE; |
| 624 | ||
| 625 | if(jbr) { | |
| 626 | if(jbr->thread_id) | |
| 627 | jm->thread_id = jbr->thread_id; | |
| 628 | ||
| 629 | if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) { | |
| 630 | jm->typing_style |= JM_TS_JEP_0085; | |
| 631 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) | |
| 632 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ | |
| 633 | } | |
| 634 | ||
| 635 | if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED) | |
| 636 | jm->typing_style |= JM_TS_JEP_0022; | |
| 637 | } | |
| 7014 | 638 | |
| 7773 | 639 | 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
|
640 | |
| 15884 | 641 | purple_markup_html_to_xhtml(buf, &xhtml, &jm->body); |
| 7014 | 642 | g_free(buf); |
| 643 | ||
| 644 | if(!jbr || jbr->capabilities & JABBER_CAP_XHTML) | |
| 645 | jm->xhtml = xhtml; | |
| 646 | else | |
| 647 | g_free(xhtml); | |
| 648 | ||
| 649 | jabber_message_send(jm); | |
| 650 | jabber_message_free(jm); | |
| 651 | return 1; | |
| 652 | } | |
| 653 | ||
| 15884 | 654 | int jabber_message_send_chat(PurpleConnection *gc, int id, const char *msg, PurpleMessageFlags flags) |
| 7014 | 655 | { |
| 656 | JabberChat *chat; | |
| 657 | JabberMessage *jm; | |
| 8042 | 658 | JabberStream *js; |
| 9130 | 659 | char *buf; |
| 7014 | 660 | |
| 8042 | 661 | if(!msg || !gc) |
| 7014 | 662 | return 0; |
| 663 | ||
| 8042 | 664 | js = gc->proto_data; |
| 7014 | 665 | chat = jabber_chat_find_by_id(js, id); |
| 666 | ||
| 8043 | 667 | if(!chat) |
| 668 | return 0; | |
| 669 | ||
| 9130 | 670 | jm = g_new0(JabberMessage, 1); |
| 671 | jm->js = gc->proto_data; | |
| 672 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 673 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 13484 | 674 | jm->id = jabber_get_next_id(jm->js); |
| 9130 | 675 | |
| 8858 | 676 | 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 | 677 | purple_markup_html_to_xhtml(buf, &jm->xhtml, &jm->body); |
| 8858 | 678 | g_free(buf); |
| 679 | ||
| 9130 | 680 | if(!chat->xhtml) { |
| 681 | g_free(jm->xhtml); | |
| 682 | jm->xhtml = NULL; | |
| 7923 | 683 | } |
| 684 | ||
| 9130 | 685 | jabber_message_send(jm); |
| 686 | jabber_message_free(jm); | |
| 687 | ||
| 7014 | 688 | return 1; |
| 689 | } | |
| 690 | ||
| 15884 | 691 | unsigned int jabber_send_typing(PurpleConnection *gc, const char *who, PurpleTypingState state) |
| 7014 | 692 | { |
| 693 | JabberMessage *jm; | |
| 694 | JabberBuddy *jb; | |
| 695 | JabberBuddyResource *jbr; | |
| 7306 | 696 | char *resource = jabber_get_resource(who); |
| 7014 | 697 | |
| 698 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); | |
| 7306 | 699 | jbr = jabber_buddy_find_resource(jb, resource); |
| 700 | ||
| 701 | g_free(resource); | |
| 7014 | 702 | |
| 13708 | 703 | if(!jbr || !((jbr->capabilities & JABBER_CAP_COMPOSING) || (jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED))) |
| 7014 | 704 | return 0; |
| 705 | ||
| 13708 | 706 | /* TODO: figure out threading */ |
| 7014 | 707 | jm = g_new0(JabberMessage, 1); |
| 708 | jm->js = gc->proto_data; | |
| 709 | jm->type = JABBER_MESSAGE_CHAT; | |
| 710 | jm->to = g_strdup(who); | |
| 13484 | 711 | jm->id = jabber_get_next_id(jm->js); |
| 7014 | 712 | |
| 15884 | 713 | if(PURPLE_TYPING == state) |
| 13708 | 714 | jm->chat_state = JM_STATE_COMPOSING; |
| 15884 | 715 | else if(PURPLE_TYPED == state) |
| 13708 | 716 | jm->chat_state = JM_STATE_PAUSED; |
| 717 | else | |
| 718 | jm->chat_state = JM_STATE_ACTIVE; | |
| 719 | ||
| 720 | if(jbr->chat_states != JABBER_CHAT_STATES_UNSUPPORTED) { | |
| 721 | jm->typing_style |= JM_TS_JEP_0085; | |
| 722 | /* if(JABBER_CHAT_STATES_UNKNOWN == jbr->chat_states) | |
| 723 | jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED; */ | |
| 724 | } | |
| 725 | ||
| 726 | if(jbr->chat_states != JABBER_CHAT_STATES_SUPPORTED) | |
| 727 | jm->typing_style |= JM_TS_JEP_0022; | |
| 7014 | 728 | |
| 729 | jabber_message_send(jm); | |
| 730 | jabber_message_free(jm); | |
| 731 | ||
| 13708 | 732 | return 0; |
| 7014 | 733 | } |
| 734 | ||
|
15709
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
735 | 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
|
736 | { |
|
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
|
737 | 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
|
738 | 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
|
739 | 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
|
740 | |
|
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 | jm = g_new0(JabberMessage, 1); |
|
15709
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
742 | jm->js = js; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
743 | jm->type = JABBER_MESSAGE_CHAT; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
744 | jm->to = g_strdup(who); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
745 | jm->id = jabber_get_next_id(jm->js); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
746 | jm->typing_style = JM_TS_JEP_0085; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
747 | jm->chat_state = JM_STATE_GONE; |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
748 | jabber_message_send(jm); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
749 | jabber_message_free(jm); |
|
b58646e3ce63
Sending XEP 85 'gone' messages
Sean Egan <seanegan@pidgin.im>
parents:
15598
diff
changeset
|
750 | } |
|
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
|
751 | |
|
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 | 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
|
753 | 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
|
754 | } |
|
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 |