Fri, 03 Mar 2006 03:38:36 +0000
[gaim-migrate @ 15757]
jabber updates, including the first half of JEP-0115 support, and maybe the
fix for jabber plaintext messages not having their line-endings preserved
| 7014 | 1 | /* |
| 2 | * gaim - Jabber Protocol Plugin | |
| 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" | |
| 30 | #include "message.h" | |
| 31 | #include "xmlnode.h" | |
| 32 | ||
| 33 | #define JABBER_TYPING_NOTIFY_INT 15 | |
| 34 | ||
| 35 | void jabber_message_free(JabberMessage *jm) | |
| 36 | { | |
| 37 | if(jm->from) | |
| 38 | g_free(jm->from); | |
| 39 | if(jm->to) | |
| 40 | g_free(jm->to); | |
| 41 | if(jm->subject) | |
| 42 | g_free(jm->subject); | |
| 43 | if(jm->body) | |
| 44 | g_free(jm->body); | |
| 45 | if(jm->xhtml) | |
| 46 | g_free(jm->xhtml); | |
| 47 | if(jm->password) | |
| 48 | g_free(jm->password); | |
| 7145 | 49 | if(jm->etc) |
| 50 | g_list_free(jm->etc); | |
| 7014 | 51 | |
| 52 | g_free(jm); | |
| 53 | } | |
| 54 | ||
| 7145 | 55 | static void handle_chat(JabberMessage *jm) |
| 7014 | 56 | { |
| 57 | JabberID *jid = jabber_id_new(jm->from); | |
| 58 | char *from; | |
| 59 | ||
| 60 | JabberBuddy *jb; | |
| 61 | JabberBuddyResource *jbr; | |
| 62 | ||
| 7310 | 63 | if(!jid) |
| 64 | return; | |
| 65 | ||
| 7014 | 66 | jb = jabber_buddy_find(jm->js, jm->from, TRUE); |
| 7306 | 67 | jbr = jabber_buddy_find_resource(jb, jid->resource); |
| 7014 | 68 | |
| 8043 | 69 | if(jabber_find_unnormalized_conv(jm->from, jm->js->gc->account)) { |
| 7014 | 70 | from = g_strdup(jm->from); |
| 7258 | 71 | } else if(jid->node) { |
| 10490 | 72 | if(jid->resource) { |
| 73 | GaimConversation *conv; | |
| 7258 | 74 | |
| 10490 | 75 | from = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 13304 | 76 | conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, from, jm->js->gc->account); |
| 10490 | 77 | if(conv) { |
| 78 | gaim_conversation_set_name(conv, jm->from); | |
| 13304 | 79 | } |
| 10490 | 80 | g_free(from); |
| 81 | } | |
| 7258 | 82 | from = g_strdup(jm->from); |
| 83 | } else { | |
| 7014 | 84 | from = g_strdup(jid->domain); |
| 7258 | 85 | } |
| 7014 | 86 | |
| 87 | if(!jm->xhtml && !jm->body) { | |
| 88 | if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 89 | serv_got_typing(jm->js->gc, from, 0, GAIM_TYPING); | |
| 90 | else | |
| 91 | serv_got_typing_stopped(jm->js->gc, from); | |
| 92 | } else { | |
| 8400 | 93 | if(jbr) { |
| 94 | if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 95 | jbr->capabilities |= JABBER_CAP_COMPOSING; | |
| 96 | if(jbr->thread_id) | |
| 97 | g_free(jbr->thread_id); | |
| 98 | jbr->thread_id = g_strdup(jbr->thread_id); | |
| 99 | } | |
| 7014 | 100 | serv_got_im(jm->js->gc, from, jm->xhtml ? jm->xhtml : jm->body, 0, |
| 101 | jm->sent); | |
| 102 | } | |
| 103 | ||
| 104 | g_free(from); | |
| 105 | jabber_id_free(jid); | |
| 106 | } | |
| 107 | ||
| 7145 | 108 | static void handle_headline(JabberMessage *jm) |
| 109 | { | |
| 110 | char *title; | |
| 111 | GString *body = g_string_new(""); | |
| 112 | GList *etc; | |
| 113 | ||
| 114 | title = g_strdup_printf(_("Message from %s"), jm->from); | |
| 115 | ||
| 116 | if(jm->xhtml) | |
| 117 | g_string_append(body, jm->xhtml); | |
| 118 | else if(jm->body) | |
| 119 | g_string_append(body, jm->body); | |
| 120 | ||
| 121 | for(etc = jm->etc; etc; etc = etc->next) { | |
| 122 | xmlnode *x = etc->data; | |
| 123 | const char *xmlns = xmlnode_get_attrib(x, "xmlns"); | |
| 124 | if(xmlns && !strcmp(xmlns, "jabber:x:oob")) { | |
| 125 | xmlnode *url, *desc; | |
| 126 | char *urltxt, *desctxt; | |
| 127 | ||
| 128 | url = xmlnode_get_child(x, "url"); | |
| 129 | desc = xmlnode_get_child(x, "desc"); | |
| 130 | ||
| 131 | if(!url || !desc) | |
| 132 | continue; | |
| 133 | ||
| 134 | urltxt = xmlnode_get_data(url); | |
| 135 | desctxt = xmlnode_get_data(desc); | |
| 136 | ||
| 137 | /* I'm all about ugly hacks */ | |
| 138 | if(body->len && !strcmp(body->str, jm->body)) | |
| 139 | g_string_printf(body, "<a href='%s'>%s</a>", | |
| 140 | urltxt, desctxt); | |
| 141 | else | |
| 142 | g_string_append_printf(body, "<br/><a href='%s'>%s</a>", | |
| 143 | urltxt, desctxt); | |
| 144 | ||
| 145 | g_free(urltxt); | |
| 146 | g_free(desctxt); | |
| 147 | } | |
| 148 | } | |
| 149 | ||
| 150 | gaim_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title, | |
| 151 | NULL, body->str, NULL, NULL); | |
| 152 | ||
| 153 | g_free(title); | |
| 154 | g_string_free(body, TRUE); | |
| 155 | } | |
| 156 | ||
| 157 | static void handle_groupchat(JabberMessage *jm) | |
| 7014 | 158 | { |
| 159 | JabberID *jid = jabber_id_new(jm->from); | |
| 7310 | 160 | JabberChat *chat; |
| 161 | ||
| 162 | if(!jid) | |
| 163 | return; | |
| 164 | ||
| 165 | chat = jabber_chat_find(jm->js, jid->node, jid->domain); | |
| 7014 | 166 | |
| 167 | if(!chat) | |
| 168 | return; | |
| 169 | ||
| 7971 | 170 | if(jm->subject) { |
| 7183 | 171 | gaim_conv_chat_set_topic(GAIM_CONV_CHAT(chat->conv), jid->resource, |
| 172 | jm->subject); | |
| 7971 | 173 | if(!jm->xhtml && !jm->body) { |
| 9762 | 174 | char *msg, *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10607
diff
changeset
|
175 | tmp = g_markup_escape_text(jm->subject, -1); |
| 9762 | 176 | tmp2 = gaim_markup_linkify(tmp); |
| 7971 | 177 | if(jid->resource) |
| 9762 | 178 | msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, tmp2); |
| 7971 | 179 | else |
| 9762 | 180 | msg = g_strdup_printf(_("The topic is: %s"), tmp2); |
| 7971 | 181 | gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", msg, GAIM_MESSAGE_SYSTEM, jm->sent); |
| 9762 | 182 | g_free(tmp); |
| 183 | g_free(tmp2); | |
| 7971 | 184 | g_free(msg); |
| 185 | } | |
| 186 | } | |
| 7014 | 187 | |
| 7630 | 188 | if(jm->xhtml || jm->body) { |
| 189 | if(jid->resource) | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
190 | serv_got_chat_in(jm->js->gc, chat->id, jid->resource, |
|
12216
d80739091a63
[gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11788
diff
changeset
|
191 | jm->delayed ? GAIM_MESSAGE_DELAYED : 0, |
| 7630 | 192 | jm->xhtml ? jm->xhtml : jm->body, jm->sent); |
| 193 | else if(chat->muc) | |
| 194 | gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", | |
| 195 | jm->xhtml ? jm->xhtml : jm->body, | |
| 196 | GAIM_MESSAGE_SYSTEM, jm->sent); | |
| 197 | } | |
| 198 | ||
| 7014 | 199 | jabber_id_free(jid); |
| 200 | } | |
| 201 | ||
| 7145 | 202 | static void handle_groupchat_invite(JabberMessage *jm) |
| 7014 | 203 | { |
| 7310 | 204 | GHashTable *components; |
| 7014 | 205 | JabberID *jid = jabber_id_new(jm->to); |
| 206 | ||
| 7310 | 207 | if(!jid) |
| 208 | return; | |
| 209 | ||
| 210 | components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 211 | ||
| 7332 | 212 | g_hash_table_replace(components, g_strdup("room"), g_strdup(jid->node)); |
| 7448 | 213 | g_hash_table_replace(components, g_strdup("server"), g_strdup(jid->domain)); |
| 7332 | 214 | g_hash_table_replace(components, g_strdup("handle"), |
| 215 | g_strdup(jm->js->user->node)); | |
| 216 | g_hash_table_replace(components, g_strdup("password"), | |
| 217 | g_strdup(jm->password)); | |
| 7014 | 218 | |
| 219 | jabber_id_free(jid); | |
|
10774
f4238d6312ff
[gaim-migrate @ 12383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
220 | serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components); |
| 7014 | 221 | } |
| 222 | ||
| 7145 | 223 | static void handle_error(JabberMessage *jm) |
| 7014 | 224 | { |
| 225 | char *buf; | |
| 226 | ||
| 227 | if(!jm->body) | |
| 228 | return; | |
| 229 | ||
| 230 | buf = g_strdup_printf(_("Message delivery to %s failed: %s"), | |
| 231 | jm->from, jm->error); | |
| 232 | ||
| 7944 | 233 | gaim_notify_formatted(jm->js->gc, _("Jabber Message Error"), _("Jabber Message Error"), buf, |
| 234 | jm->xhtml ? jm->xhtml : jm->body, NULL, NULL); | |
| 7014 | 235 | |
| 236 | g_free(buf); | |
| 237 | } | |
| 238 | ||
| 239 | void jabber_message_parse(JabberStream *js, xmlnode *packet) | |
| 240 | { | |
| 241 | JabberMessage *jm; | |
| 242 | const char *type; | |
| 243 | xmlnode *child; | |
| 244 | ||
| 245 | if(strcmp(packet->name, "message")) | |
| 246 | return; | |
| 247 | ||
| 248 | jm = g_new0(JabberMessage, 1); | |
| 249 | jm->js = js; | |
| 250 | jm->sent = time(NULL); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
251 | jm->delayed = FALSE; |
| 7014 | 252 | |
| 253 | type = xmlnode_get_attrib(packet, "type"); | |
| 254 | ||
| 255 | if(type) { | |
| 256 | if(!strcmp(type, "normal")) | |
| 257 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 258 | else if(!strcmp(type, "chat")) | |
| 259 | jm->type = JABBER_MESSAGE_CHAT; | |
| 260 | else if(!strcmp(type, "groupchat")) | |
| 261 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 262 | else if(!strcmp(type, "headline")) | |
| 263 | jm->type = JABBER_MESSAGE_HEADLINE; | |
| 264 | else if(!strcmp(type, "error")) | |
| 265 | jm->type = JABBER_MESSAGE_ERROR; | |
| 266 | else | |
| 267 | jm->type = JABBER_MESSAGE_OTHER; | |
| 268 | } else { | |
| 269 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 270 | } | |
| 271 | ||
| 272 | jm->from = g_strdup(xmlnode_get_attrib(packet, "from")); | |
| 273 | jm->to = g_strdup(xmlnode_get_attrib(packet, "to")); | |
| 274 | ||
| 275 | for(child = packet->child; child; child = child->next) { | |
| 8135 | 276 | if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 277 | continue; |
| 278 | ||
| 279 | if(!strcmp(child->name, "subject")) { | |
| 280 | if(!jm->subject) | |
| 281 | jm->subject = xmlnode_get_data(child); | |
| 8400 | 282 | } else if(!strcmp(child->name, "thread")) { |
| 283 | if(!jm->thread_id) | |
| 284 | jm->thread_id = xmlnode_get_data(child); | |
| 7014 | 285 | } else if(!strcmp(child->name, "body")) { |
| 13385 | 286 | if(!jm->body) { |
| 287 | char *msg = xmlnode_to_str(child, NULL); | |
| 288 | jm->body = gaim_strdup_withhtml(msg); | |
| 289 | g_free(msg); | |
| 290 | } | |
| 7241 | 291 | } else if(!strcmp(child->name, "html")) { |
| 11788 | 292 | if(!jm->xhtml && xmlnode_get_child(child, "body")) |
| 7642 | 293 | jm->xhtml = xmlnode_to_str(child, NULL); |
| 7014 | 294 | } else if(!strcmp(child->name, "error")) { |
| 295 | const char *code = xmlnode_get_attrib(child, "code"); | |
| 296 | char *code_txt = NULL; | |
| 297 | char *text = xmlnode_get_data(child); | |
| 298 | ||
| 299 | if(code) | |
| 300 | code_txt = g_strdup_printf(_(" (Code %s)"), code); | |
| 301 | ||
| 302 | if(!jm->error) | |
| 303 | jm->error = g_strdup_printf("%s%s", text ? text : "", | |
| 304 | code_txt ? code_txt : ""); | |
| 305 | ||
| 306 | g_free(code_txt); | |
| 307 | g_free(text); | |
| 308 | } else if(!strcmp(child->name, "x")) { | |
| 309 | const char *xmlns = xmlnode_get_attrib(child, "xmlns"); | |
| 310 | if(xmlns && !strcmp(xmlns, "jabber:x:event")) { | |
| 311 | if(xmlnode_get_child(child, "composing")) | |
| 312 | jm->events |= JABBER_MESSAGE_EVENT_COMPOSING; | |
| 313 | } else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { | |
| 314 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
315 | jm->delayed = TRUE; |
| 7014 | 316 | if(timestamp) |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
12216
diff
changeset
|
317 | jm->sent = gaim_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 318 | } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") && |
| 11230 | 319 | jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE && |
| 320 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 321 | const char *jid = xmlnode_get_attrib(child, "jid"); |
| 322 | if(jid) { | |
| 323 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 324 | g_free(jm->to); | |
| 325 | jm->to = g_strdup(jid); | |
| 326 | } | |
| 327 | } else if(xmlns && !strcmp(xmlns, | |
| 11230 | 328 | "http://jabber.org/protocol/muc#user") && |
| 329 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 330 | xmlnode *invite = xmlnode_get_child(child, "invite"); |
| 331 | if(invite) { | |
| 332 | xmlnode *reason, *password; | |
| 7968 | 333 | const char *jid = xmlnode_get_attrib(invite, "from"); |
| 7014 | 334 | g_free(jm->to); |
| 335 | jm->to = jm->from; | |
| 336 | jm->from = g_strdup(jid); | |
| 337 | if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 338 | g_free(jm->body); | |
| 339 | jm->body = xmlnode_get_data(reason); | |
| 340 | } | |
| 11576 | 341 | if((password = xmlnode_get_child(child, "password"))) |
| 7014 | 342 | jm->password = xmlnode_get_data(password); |
| 343 | ||
| 344 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 345 | } | |
| 7145 | 346 | } else { |
| 347 | jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 348 | } |
| 349 | } | |
| 350 | } | |
| 351 | ||
| 352 | switch(jm->type) { | |
| 353 | case JABBER_MESSAGE_NORMAL: | |
| 354 | case JABBER_MESSAGE_CHAT: | |
| 7145 | 355 | handle_chat(jm); |
| 356 | break; | |
| 7014 | 357 | case JABBER_MESSAGE_HEADLINE: |
| 7145 | 358 | handle_headline(jm); |
| 7014 | 359 | break; |
| 360 | case JABBER_MESSAGE_GROUPCHAT: | |
| 361 | handle_groupchat(jm); | |
| 362 | break; | |
| 363 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 364 | handle_groupchat_invite(jm); | |
| 365 | break; | |
| 366 | case JABBER_MESSAGE_ERROR: | |
| 367 | handle_error(jm); | |
| 368 | break; | |
| 369 | case JABBER_MESSAGE_OTHER: | |
| 370 | gaim_debug(GAIM_DEBUG_INFO, "jabber", | |
| 371 | "Received message of unknown type: %s\n", type); | |
| 372 | break; | |
| 373 | } | |
| 374 | jabber_message_free(jm); | |
| 375 | } | |
| 376 | ||
| 377 | void jabber_message_send(JabberMessage *jm) | |
| 378 | { | |
| 379 | xmlnode *message, *child; | |
| 380 | const char *type = NULL; | |
| 381 | ||
| 382 | message = xmlnode_new("message"); | |
| 383 | ||
| 384 | switch(jm->type) { | |
| 385 | case JABBER_MESSAGE_NORMAL: | |
| 386 | type = "normal"; | |
| 387 | break; | |
| 388 | case JABBER_MESSAGE_CHAT: | |
| 389 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 390 | type = "chat"; | |
| 391 | break; | |
| 392 | case JABBER_MESSAGE_HEADLINE: | |
| 393 | type = "headline"; | |
| 394 | break; | |
| 395 | case JABBER_MESSAGE_GROUPCHAT: | |
| 396 | type = "groupchat"; | |
| 397 | break; | |
| 398 | case JABBER_MESSAGE_ERROR: | |
| 399 | type = "error"; | |
| 400 | break; | |
| 401 | case JABBER_MESSAGE_OTHER: | |
| 402 | type = NULL; | |
| 403 | break; | |
| 404 | } | |
| 405 | ||
| 406 | if(type) | |
| 407 | xmlnode_set_attrib(message, "type", type); | |
| 408 | ||
| 409 | xmlnode_set_attrib(message, "to", jm->to); | |
| 410 | ||
| 8400 | 411 | if(jm->thread_id) { |
| 412 | child = xmlnode_new_child(message, "thread"); | |
| 413 | xmlnode_insert_data(child, jm->thread_id, -1); | |
| 414 | } | |
| 415 | ||
| 7971 | 416 | if(jm->events || (!jm->body && !jm->xhtml && !jm->subject)) { |
| 7014 | 417 | child = xmlnode_new_child(message, "x"); |
| 418 | xmlnode_set_attrib(child, "xmlns", "jabber:x:event"); | |
| 419 | if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 420 | xmlnode_new_child(child, "composing"); | |
| 421 | } | |
| 422 | ||
| 423 | if(jm->subject) { | |
| 424 | child = xmlnode_new_child(message, "subject"); | |
| 425 | xmlnode_insert_data(child, jm->subject, -1); | |
| 426 | } | |
| 427 | ||
| 428 | if(jm->body) { | |
| 429 | child = xmlnode_new_child(message, "body"); | |
| 430 | xmlnode_insert_data(child, jm->body, -1); | |
| 431 | } | |
| 432 | ||
| 433 | if(jm->xhtml) { | |
| 434 | child = xmlnode_from_str(jm->xhtml, -1); | |
| 435 | if(child) { | |
| 436 | xmlnode_insert_child(message, child); | |
| 437 | } else { | |
| 438 | gaim_debug(GAIM_DEBUG_ERROR, "jabber", | |
| 439 | "XHTML translation/validation failed, returning: %s\n", | |
| 440 | jm->xhtml); | |
| 441 | } | |
| 442 | } | |
| 443 | ||
| 444 | jabber_send(jm->js, message); | |
| 445 | ||
| 446 | xmlnode_free(message); | |
| 447 | } | |
| 448 | ||
| 449 | int jabber_message_send_im(GaimConnection *gc, const char *who, const char *msg, | |
|
12216
d80739091a63
[gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11788
diff
changeset
|
450 | GaimMessageFlags flags) |
| 7014 | 451 | { |
| 452 | JabberMessage *jm; | |
| 453 | JabberBuddy *jb; | |
| 454 | JabberBuddyResource *jbr; | |
| 455 | char *buf; | |
| 7135 | 456 | char *xhtml; |
| 7306 | 457 | char *resource; |
| 7014 | 458 | |
| 459 | if(!who || !msg) | |
| 460 | return 0; | |
| 461 | ||
| 7306 | 462 | resource = jabber_get_resource(who); |
| 463 | ||
| 7014 | 464 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); |
| 7306 | 465 | jbr = jabber_buddy_find_resource(jb, resource); |
| 466 | ||
| 467 | g_free(resource); | |
| 7014 | 468 | |
| 469 | jm = g_new0(JabberMessage, 1); | |
| 470 | jm->js = gc->proto_data; | |
| 471 | jm->type = JABBER_MESSAGE_CHAT; | |
| 472 | jm->events = JABBER_MESSAGE_EVENT_COMPOSING; | |
| 473 | jm->to = g_strdup(who); | |
| 8400 | 474 | if(jbr && jbr->thread_id) |
| 475 | jm->thread_id = jbr->thread_id; | |
| 7014 | 476 | |
| 7773 | 477 | buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg); |
| 7014 | 478 | |
| 7135 | 479 | gaim_markup_html_to_xhtml(buf, &xhtml, &jm->body); |
| 7014 | 480 | g_free(buf); |
| 481 | ||
| 482 | if(!jbr || jbr->capabilities & JABBER_CAP_XHTML) | |
| 483 | jm->xhtml = xhtml; | |
| 484 | else | |
| 485 | g_free(xhtml); | |
| 486 | ||
| 487 | jabber_message_send(jm); | |
| 488 | jabber_message_free(jm); | |
| 489 | return 1; | |
| 490 | } | |
| 491 | ||
|
12216
d80739091a63
[gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11788
diff
changeset
|
492 | int jabber_message_send_chat(GaimConnection *gc, int id, const char *msg, GaimMessageFlags flags) |
| 7014 | 493 | { |
| 494 | JabberChat *chat; | |
| 495 | JabberMessage *jm; | |
| 8042 | 496 | JabberStream *js; |
| 9130 | 497 | char *buf; |
| 7014 | 498 | |
| 8042 | 499 | if(!msg || !gc) |
| 7014 | 500 | return 0; |
| 501 | ||
| 8042 | 502 | js = gc->proto_data; |
| 7014 | 503 | chat = jabber_chat_find_by_id(js, id); |
| 504 | ||
| 8043 | 505 | if(!chat) |
| 506 | return 0; | |
| 507 | ||
| 9130 | 508 | jm = g_new0(JabberMessage, 1); |
| 509 | jm->js = gc->proto_data; | |
| 510 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 511 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 512 | ||
| 8858 | 513 | buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg); |
| 9130 | 514 | gaim_markup_html_to_xhtml(buf, &jm->xhtml, &jm->body); |
| 8858 | 515 | g_free(buf); |
| 516 | ||
| 9130 | 517 | if(!chat->xhtml) { |
| 518 | g_free(jm->xhtml); | |
| 519 | jm->xhtml = NULL; | |
| 7923 | 520 | } |
| 521 | ||
| 9130 | 522 | jabber_message_send(jm); |
| 523 | jabber_message_free(jm); | |
| 524 | ||
| 7014 | 525 | return 1; |
| 526 | } | |
| 527 | ||
| 528 | int jabber_send_typing(GaimConnection *gc, const char *who, int typing) | |
| 529 | { | |
| 530 | JabberMessage *jm; | |
| 531 | JabberBuddy *jb; | |
| 532 | JabberBuddyResource *jbr; | |
| 7306 | 533 | char *resource = jabber_get_resource(who); |
| 7014 | 534 | |
| 535 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); | |
| 7306 | 536 | jbr = jabber_buddy_find_resource(jb, resource); |
| 537 | ||
| 538 | g_free(resource); | |
| 7014 | 539 | |
| 7187 | 540 | if(!jbr || !(jbr->capabilities & JABBER_CAP_COMPOSING)) |
| 7014 | 541 | return 0; |
| 542 | ||
| 543 | jm = g_new0(JabberMessage, 1); | |
| 544 | jm->js = gc->proto_data; | |
| 545 | jm->type = JABBER_MESSAGE_CHAT; | |
| 546 | jm->to = g_strdup(who); | |
| 547 | ||
| 548 | if(typing == GAIM_TYPING) | |
| 549 | jm->events = JABBER_MESSAGE_EVENT_COMPOSING; | |
| 550 | ||
| 551 | jabber_message_send(jm); | |
| 552 | jabber_message_free(jm); | |
| 553 | ||
| 554 | return JABBER_TYPING_NOTIFY_INT; | |
| 555 | } | |
| 556 |