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