Mon, 29 Dec 2003 08:59:22 +0000
[gaim-migrate @ 8630]
fun jabber stuff, which isn't done yet. mostly harmless, and committing this now makes the next
commit that much easier for a lazy person such as myself to type.
| 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 | ||
| 7261 | 55 | static GaimConversation * |
| 7318 | 56 | find_unnormalized_im(const char *name, GaimAccount *account) |
| 7261 | 57 | { |
| 58 | GaimConversation *c = NULL; | |
| 59 | GList *cnv; | |
| 60 | ||
| 61 | g_return_val_if_fail(name != NULL, NULL); | |
| 62 | ||
| 63 | for(cnv = gaim_get_conversations(); cnv; cnv = cnv->next) { | |
| 64 | c = (GaimConversation*)cnv->data; | |
| 7318 | 65 | if(gaim_conversation_get_type(c) == GAIM_CONV_IM && |
| 66 | !gaim_utf8_strcasecmp(name, gaim_conversation_get_name(c)) && | |
| 7261 | 67 | account == gaim_conversation_get_account(c)) |
| 68 | return c; | |
| 69 | } | |
| 70 | ||
| 71 | return NULL; | |
| 72 | } | |
| 73 | ||
| 7145 | 74 | static void handle_chat(JabberMessage *jm) |
| 7014 | 75 | { |
| 76 | JabberID *jid = jabber_id_new(jm->from); | |
| 77 | char *from; | |
| 78 | ||
| 79 | JabberBuddy *jb; | |
| 80 | JabberBuddyResource *jbr; | |
| 81 | ||
| 7310 | 82 | if(!jid) |
| 83 | return; | |
| 84 | ||
| 7014 | 85 | jb = jabber_buddy_find(jm->js, jm->from, TRUE); |
| 7306 | 86 | jbr = jabber_buddy_find_resource(jb, jid->resource); |
| 7014 | 87 | |
| 7318 | 88 | if(find_unnormalized_im(jm->from, jm->js->gc->account)) { |
| 7014 | 89 | from = g_strdup(jm->from); |
| 7258 | 90 | } else if(jid->node) { |
| 91 | GaimConversation *conv; | |
| 92 | ||
| 7014 | 93 | from = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 7318 | 94 | conv = find_unnormalized_im(from, jm->js->gc->account); |
| 7258 | 95 | if(conv) |
| 96 | gaim_conversation_set_name(conv, jm->from); | |
| 97 | g_free(from); | |
| 98 | from = g_strdup(jm->from); | |
| 99 | } else { | |
| 7014 | 100 | from = g_strdup(jid->domain); |
| 7258 | 101 | } |
| 7014 | 102 | |
| 103 | if(!jm->xhtml && !jm->body) { | |
| 104 | if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 105 | serv_got_typing(jm->js->gc, from, 0, GAIM_TYPING); | |
| 106 | else | |
| 107 | serv_got_typing_stopped(jm->js->gc, from); | |
| 108 | } else { | |
| 109 | if(jbr && jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 110 | jbr->capabilities |= JABBER_CAP_COMPOSING; | |
| 111 | serv_got_im(jm->js->gc, from, jm->xhtml ? jm->xhtml : jm->body, 0, | |
| 112 | jm->sent); | |
| 113 | } | |
| 114 | ||
| 115 | g_free(from); | |
| 116 | jabber_id_free(jid); | |
| 117 | } | |
| 118 | ||
| 7145 | 119 | static void handle_headline(JabberMessage *jm) |
| 120 | { | |
| 121 | char *title; | |
| 122 | GString *body = g_string_new(""); | |
| 123 | GList *etc; | |
| 124 | ||
| 125 | title = g_strdup_printf(_("Message from %s"), jm->from); | |
| 126 | ||
| 127 | if(jm->xhtml) | |
| 128 | g_string_append(body, jm->xhtml); | |
| 129 | else if(jm->body) | |
| 130 | g_string_append(body, jm->body); | |
| 131 | ||
| 132 | for(etc = jm->etc; etc; etc = etc->next) { | |
| 133 | xmlnode *x = etc->data; | |
| 134 | const char *xmlns = xmlnode_get_attrib(x, "xmlns"); | |
| 135 | if(xmlns && !strcmp(xmlns, "jabber:x:oob")) { | |
| 136 | xmlnode *url, *desc; | |
| 137 | char *urltxt, *desctxt; | |
| 138 | ||
| 139 | url = xmlnode_get_child(x, "url"); | |
| 140 | desc = xmlnode_get_child(x, "desc"); | |
| 141 | ||
| 142 | if(!url || !desc) | |
| 143 | continue; | |
| 144 | ||
| 145 | urltxt = xmlnode_get_data(url); | |
| 146 | desctxt = xmlnode_get_data(desc); | |
| 147 | ||
| 148 | /* I'm all about ugly hacks */ | |
| 149 | if(body->len && !strcmp(body->str, jm->body)) | |
| 150 | g_string_printf(body, "<a href='%s'>%s</a>", | |
| 151 | urltxt, desctxt); | |
| 152 | else | |
| 153 | g_string_append_printf(body, "<br/><a href='%s'>%s</a>", | |
| 154 | urltxt, desctxt); | |
| 155 | ||
| 156 | g_free(urltxt); | |
| 157 | g_free(desctxt); | |
| 158 | } | |
| 159 | } | |
| 160 | ||
| 161 | gaim_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title, | |
| 162 | NULL, body->str, NULL, NULL); | |
| 163 | ||
| 164 | g_free(title); | |
| 165 | g_string_free(body, TRUE); | |
| 166 | } | |
| 167 | ||
| 168 | static void handle_groupchat(JabberMessage *jm) | |
| 7014 | 169 | { |
| 170 | JabberID *jid = jabber_id_new(jm->from); | |
| 7310 | 171 | JabberChat *chat; |
| 172 | ||
| 173 | if(!jid) | |
| 174 | return; | |
| 175 | ||
| 176 | chat = jabber_chat_find(jm->js, jid->node, jid->domain); | |
| 7014 | 177 | |
| 178 | if(!chat) | |
| 179 | return; | |
| 180 | ||
| 181 | if(jm->subject) | |
| 7183 | 182 | gaim_conv_chat_set_topic(GAIM_CONV_CHAT(chat->conv), jid->resource, |
| 183 | jm->subject); | |
| 7014 | 184 | |
| 7630 | 185 | if(jm->xhtml || jm->body) { |
| 186 | if(jid->resource) | |
| 187 | serv_got_chat_in(jm->js->gc, chat->id, jid->resource, 0, | |
| 188 | jm->xhtml ? jm->xhtml : jm->body, jm->sent); | |
| 189 | else if(chat->muc) | |
| 190 | gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", | |
| 191 | jm->xhtml ? jm->xhtml : jm->body, | |
| 192 | GAIM_MESSAGE_SYSTEM, jm->sent); | |
| 193 | } | |
| 194 | ||
| 7014 | 195 | jabber_id_free(jid); |
| 196 | } | |
| 197 | ||
| 7145 | 198 | static void handle_groupchat_invite(JabberMessage *jm) |
| 7014 | 199 | { |
| 7310 | 200 | GHashTable *components; |
| 7014 | 201 | JabberID *jid = jabber_id_new(jm->to); |
| 202 | ||
| 7310 | 203 | if(!jid) |
| 204 | return; | |
| 205 | ||
| 206 | components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 207 | ||
| 7332 | 208 | g_hash_table_replace(components, g_strdup("room"), g_strdup(jid->node)); |
| 7448 | 209 | g_hash_table_replace(components, g_strdup("server"), g_strdup(jid->domain)); |
| 7332 | 210 | g_hash_table_replace(components, g_strdup("handle"), |
| 211 | g_strdup(jm->js->user->node)); | |
| 212 | g_hash_table_replace(components, g_strdup("password"), | |
| 213 | g_strdup(jm->password)); | |
| 7014 | 214 | |
| 215 | jabber_id_free(jid); | |
| 216 | serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components); | |
| 217 | } | |
| 218 | ||
| 7145 | 219 | static void handle_error(JabberMessage *jm) |
| 7014 | 220 | { |
| 221 | char *buf; | |
| 222 | ||
| 223 | if(!jm->body) | |
| 224 | return; | |
| 225 | ||
| 226 | buf = g_strdup_printf(_("Message delivery to %s failed: %s"), | |
| 227 | jm->from, jm->error); | |
| 228 | ||
| 7944 | 229 | gaim_notify_formatted(jm->js->gc, _("Jabber Message Error"), _("Jabber Message Error"), buf, |
| 230 | jm->xhtml ? jm->xhtml : jm->body, NULL, NULL); | |
| 7014 | 231 | |
| 232 | g_free(buf); | |
| 233 | } | |
| 234 | ||
| 235 | void jabber_message_parse(JabberStream *js, xmlnode *packet) | |
| 236 | { | |
| 237 | JabberMessage *jm; | |
| 238 | const char *type; | |
| 239 | xmlnode *child; | |
| 240 | ||
| 241 | if(strcmp(packet->name, "message")) | |
| 242 | return; | |
| 243 | ||
| 244 | jm = g_new0(JabberMessage, 1); | |
| 245 | jm->js = js; | |
| 246 | jm->sent = time(NULL); | |
| 247 | ||
| 248 | type = xmlnode_get_attrib(packet, "type"); | |
| 249 | ||
| 250 | if(type) { | |
| 251 | if(!strcmp(type, "normal")) | |
| 252 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 253 | else if(!strcmp(type, "chat")) | |
| 254 | jm->type = JABBER_MESSAGE_CHAT; | |
| 255 | else if(!strcmp(type, "groupchat")) | |
| 256 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 257 | else if(!strcmp(type, "headline")) | |
| 258 | jm->type = JABBER_MESSAGE_HEADLINE; | |
| 259 | else if(!strcmp(type, "error")) | |
| 260 | jm->type = JABBER_MESSAGE_ERROR; | |
| 261 | else | |
| 262 | jm->type = JABBER_MESSAGE_OTHER; | |
| 263 | } else { | |
| 264 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 265 | } | |
| 266 | ||
| 267 | jm->from = g_strdup(xmlnode_get_attrib(packet, "from")); | |
| 268 | jm->to = g_strdup(xmlnode_get_attrib(packet, "to")); | |
| 269 | ||
| 270 | for(child = packet->child; child; child = child->next) { | |
| 271 | if(child->type != NODE_TYPE_TAG) | |
| 272 | continue; | |
| 273 | ||
| 274 | if(!strcmp(child->name, "subject")) { | |
| 275 | if(!jm->subject) | |
| 276 | jm->subject = xmlnode_get_data(child); | |
| 277 | } else if(!strcmp(child->name, "body")) { | |
| 278 | if(!jm->body) | |
| 7894 | 279 | jm->body = xmlnode_to_str(child, NULL); |
| 7241 | 280 | } else if(!strcmp(child->name, "html")) { |
| 281 | if(!jm->xhtml) | |
| 7642 | 282 | jm->xhtml = xmlnode_to_str(child, NULL); |
| 7014 | 283 | } else if(!strcmp(child->name, "error")) { |
| 284 | const char *code = xmlnode_get_attrib(child, "code"); | |
| 285 | char *code_txt = NULL; | |
| 286 | char *text = xmlnode_get_data(child); | |
| 287 | ||
| 288 | if(code) | |
| 289 | code_txt = g_strdup_printf(_(" (Code %s)"), code); | |
| 290 | ||
| 291 | if(!jm->error) | |
| 292 | jm->error = g_strdup_printf("%s%s", text ? text : "", | |
| 293 | code_txt ? code_txt : ""); | |
| 294 | ||
| 295 | g_free(code_txt); | |
| 296 | g_free(text); | |
| 297 | } else if(!strcmp(child->name, "x")) { | |
| 298 | const char *xmlns = xmlnode_get_attrib(child, "xmlns"); | |
| 299 | if(xmlns && !strcmp(xmlns, "jabber:x:event")) { | |
| 300 | if(xmlnode_get_child(child, "composing")) | |
| 301 | jm->events |= JABBER_MESSAGE_EVENT_COMPOSING; | |
| 302 | } else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { | |
| 303 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); | |
| 304 | if(timestamp) | |
| 305 | jm->sent = str_to_time(timestamp); | |
| 306 | } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") && | |
| 307 | jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE) { | |
| 308 | const char *jid = xmlnode_get_attrib(child, "jid"); | |
| 309 | if(jid) { | |
| 310 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 311 | g_free(jm->to); | |
| 312 | jm->to = g_strdup(jid); | |
| 313 | } | |
| 314 | } else if(xmlns && !strcmp(xmlns, | |
| 315 | "http://jabber.org/protocol/muc#user")) { | |
| 316 | xmlnode *invite = xmlnode_get_child(child, "invite"); | |
| 317 | if(invite) { | |
| 318 | xmlnode *reason, *password; | |
| 319 | const char *jid = xmlnode_get_attrib(child, "from"); | |
| 320 | g_free(jm->to); | |
| 321 | jm->to = jm->from; | |
| 322 | jm->from = g_strdup(jid); | |
| 323 | if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 324 | g_free(jm->body); | |
| 325 | jm->body = xmlnode_get_data(reason); | |
| 326 | } | |
| 327 | if((password = xmlnode_get_child(invite, "password"))) | |
| 328 | jm->password = xmlnode_get_data(password); | |
| 329 | ||
| 330 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 331 | } | |
| 7145 | 332 | } else { |
| 333 | jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 334 | } |
| 335 | } | |
| 336 | } | |
| 337 | ||
| 338 | switch(jm->type) { | |
| 339 | case JABBER_MESSAGE_NORMAL: | |
| 340 | case JABBER_MESSAGE_CHAT: | |
| 7145 | 341 | handle_chat(jm); |
| 342 | break; | |
| 7014 | 343 | case JABBER_MESSAGE_HEADLINE: |
| 7145 | 344 | handle_headline(jm); |
| 7014 | 345 | break; |
| 346 | case JABBER_MESSAGE_GROUPCHAT: | |
| 347 | handle_groupchat(jm); | |
| 348 | break; | |
| 349 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 350 | handle_groupchat_invite(jm); | |
| 351 | break; | |
| 352 | case JABBER_MESSAGE_ERROR: | |
| 353 | handle_error(jm); | |
| 354 | break; | |
| 355 | case JABBER_MESSAGE_OTHER: | |
| 356 | gaim_debug(GAIM_DEBUG_INFO, "jabber", | |
| 357 | "Received message of unknown type: %s\n", type); | |
| 358 | break; | |
| 359 | } | |
| 360 | jabber_message_free(jm); | |
| 361 | } | |
| 362 | ||
| 363 | void jabber_message_send(JabberMessage *jm) | |
| 364 | { | |
| 365 | xmlnode *message, *child; | |
| 366 | const char *type = NULL; | |
| 367 | ||
| 368 | message = xmlnode_new("message"); | |
| 369 | ||
| 370 | switch(jm->type) { | |
| 371 | case JABBER_MESSAGE_NORMAL: | |
| 372 | type = "normal"; | |
| 373 | break; | |
| 374 | case JABBER_MESSAGE_CHAT: | |
| 375 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 376 | type = "chat"; | |
| 377 | break; | |
| 378 | case JABBER_MESSAGE_HEADLINE: | |
| 379 | type = "headline"; | |
| 380 | break; | |
| 381 | case JABBER_MESSAGE_GROUPCHAT: | |
| 382 | type = "groupchat"; | |
| 383 | break; | |
| 384 | case JABBER_MESSAGE_ERROR: | |
| 385 | type = "error"; | |
| 386 | break; | |
| 387 | case JABBER_MESSAGE_OTHER: | |
| 388 | type = NULL; | |
| 389 | break; | |
| 390 | } | |
| 391 | ||
| 392 | if(type) | |
| 393 | xmlnode_set_attrib(message, "type", type); | |
| 394 | ||
| 395 | xmlnode_set_attrib(message, "to", jm->to); | |
| 396 | ||
| 397 | if(jm->events || (!jm->body && !jm->xhtml)) { | |
| 398 | child = xmlnode_new_child(message, "x"); | |
| 399 | xmlnode_set_attrib(child, "xmlns", "jabber:x:event"); | |
| 400 | if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 401 | xmlnode_new_child(child, "composing"); | |
| 402 | } | |
| 403 | ||
| 404 | if(jm->subject) { | |
| 405 | child = xmlnode_new_child(message, "subject"); | |
| 406 | xmlnode_insert_data(child, jm->subject, -1); | |
| 407 | } | |
| 408 | ||
| 409 | if(jm->body) { | |
| 410 | child = xmlnode_new_child(message, "body"); | |
| 411 | xmlnode_insert_data(child, jm->body, -1); | |
| 412 | } | |
| 413 | ||
| 414 | if(jm->xhtml) { | |
| 415 | child = xmlnode_from_str(jm->xhtml, -1); | |
| 416 | if(child) { | |
| 417 | xmlnode_insert_child(message, child); | |
| 418 | } else { | |
| 419 | gaim_debug(GAIM_DEBUG_ERROR, "jabber", | |
| 420 | "XHTML translation/validation failed, returning: %s\n", | |
| 421 | jm->xhtml); | |
| 422 | } | |
| 423 | } | |
| 424 | ||
| 425 | jabber_send(jm->js, message); | |
| 426 | ||
| 427 | xmlnode_free(message); | |
| 428 | } | |
| 429 | ||
| 430 | int jabber_message_send_im(GaimConnection *gc, const char *who, const char *msg, | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
431 | GaimConvImFlags flags) |
| 7014 | 432 | { |
| 433 | JabberMessage *jm; | |
| 434 | JabberBuddy *jb; | |
| 435 | JabberBuddyResource *jbr; | |
| 436 | char *buf; | |
| 7135 | 437 | char *xhtml; |
| 7306 | 438 | char *resource; |
| 7014 | 439 | |
| 440 | if(!who || !msg) | |
| 441 | return 0; | |
| 442 | ||
| 7306 | 443 | resource = jabber_get_resource(who); |
| 444 | ||
| 7014 | 445 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); |
| 7306 | 446 | jbr = jabber_buddy_find_resource(jb, resource); |
| 447 | ||
| 448 | g_free(resource); | |
| 7014 | 449 | |
| 450 | jm = g_new0(JabberMessage, 1); | |
| 451 | jm->js = gc->proto_data; | |
| 452 | jm->type = JABBER_MESSAGE_CHAT; | |
| 453 | jm->events = JABBER_MESSAGE_EVENT_COMPOSING; | |
| 454 | jm->to = g_strdup(who); | |
| 455 | ||
| 7773 | 456 | 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 | 457 | |
| 7135 | 458 | gaim_markup_html_to_xhtml(buf, &xhtml, &jm->body); |
| 7014 | 459 | g_free(buf); |
| 460 | ||
| 461 | if(!jbr || jbr->capabilities & JABBER_CAP_XHTML) | |
| 462 | jm->xhtml = xhtml; | |
| 463 | else | |
| 464 | g_free(xhtml); | |
| 465 | ||
| 466 | jabber_message_send(jm); | |
| 467 | jabber_message_free(jm); | |
| 468 | return 1; | |
| 469 | } | |
| 470 | ||
| 7345 | 471 | int jabber_message_send_chat(GaimConnection *gc, int id, const char *msg) |
| 7014 | 472 | { |
| 473 | JabberChat *chat; | |
| 474 | JabberMessage *jm; | |
| 475 | JabberStream *js = gc->proto_data; | |
| 7345 | 476 | char *buf, *xhtml; |
| 7014 | 477 | |
| 7345 | 478 | if(!msg) |
| 7014 | 479 | return 0; |
| 480 | ||
| 481 | chat = jabber_chat_find_by_id(js, id); | |
| 482 | ||
| 7923 | 483 | if(!strcmp(msg, "/configure") || !strcmp(msg, "/config")) { |
| 484 | jabber_chat_request_room_configure(chat); | |
| 485 | return 1; | |
| 7955 | 486 | } else if(!strcmp(msg, "/register")) { |
| 487 | jabber_chat_register(chat); | |
| 7923 | 488 | } |
| 489 | ||
| 7014 | 490 | jm = g_new0(JabberMessage, 1); |
| 491 | jm->js = gc->proto_data; | |
| 7444 | 492 | jm->type = JABBER_MESSAGE_GROUPCHAT; |
| 7014 | 493 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); |
| 494 | ||
| 7773 | 495 | buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", msg); |
| 7345 | 496 | |
| 497 | gaim_markup_html_to_xhtml(buf, &xhtml, &jm->body); | |
| 498 | g_free(buf); | |
| 499 | ||
| 500 | if(chat->xhtml) | |
| 501 | jm->xhtml = xhtml; | |
| 502 | else | |
| 503 | g_free(xhtml); | |
| 7014 | 504 | |
| 505 | jabber_message_send(jm); | |
| 506 | jabber_message_free(jm); | |
| 507 | return 1; | |
| 508 | } | |
| 509 | ||
| 510 | int jabber_send_typing(GaimConnection *gc, const char *who, int typing) | |
| 511 | { | |
| 512 | JabberMessage *jm; | |
| 513 | JabberBuddy *jb; | |
| 514 | JabberBuddyResource *jbr; | |
| 7306 | 515 | char *resource = jabber_get_resource(who); |
| 7014 | 516 | |
| 517 | jb = jabber_buddy_find(gc->proto_data, who, TRUE); | |
| 7306 | 518 | jbr = jabber_buddy_find_resource(jb, resource); |
| 519 | ||
| 520 | g_free(resource); | |
| 7014 | 521 | |
| 7187 | 522 | if(!jbr || !(jbr->capabilities & JABBER_CAP_COMPOSING)) |
| 7014 | 523 | return 0; |
| 524 | ||
| 525 | jm = g_new0(JabberMessage, 1); | |
| 526 | jm->js = gc->proto_data; | |
| 527 | jm->type = JABBER_MESSAGE_CHAT; | |
| 528 | jm->to = g_strdup(who); | |
| 529 | ||
| 530 | if(typing == GAIM_TYPING) | |
| 531 | jm->events = JABBER_MESSAGE_EVENT_COMPOSING; | |
| 532 | ||
| 533 | jabber_message_send(jm); | |
| 534 | jabber_message_free(jm); | |
| 535 | ||
| 536 | return JABBER_TYPING_NOTIFY_INT; | |
| 537 | } | |
| 538 |