Mercurial > pidgin
annotate src/protocols/jabber/message.c @ 10728:b5259f3dfc29
[gaim-migrate @ 12328]
[15:55] <marv> grim: what does it do?
[15:55] <grim> marv: corrects the logic in my patch that luke commited earlier
[15:55] <grim> it's to make the groups hide when all accounts are offline
committer: Tailor Script <tailor@pidgin.im>
| author | Tim Ringenbach <marv@pidgin.im> |
|---|---|
| date | Fri, 25 Mar 2005 21:56:29 +0000 |
| parents | bf4c9ce533ab |
| children | c4cb90065e1d |
| rev | line source |
|---|---|
| 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
c8bf2da398e3
[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); |
| 76 conv = jabber_find_unnormalized_conv(from, jm->js->gc->account); | |
| 77 if(conv) { | |
| 78 gaim_conversation_set_name(conv, jm->from); | |
| 79 } | |
| 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; |
| 175 tmp = gaim_escape_html(jm->subject); | |
| 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 | 190 serv_got_chat_in(jm->js->gc, chat->id, jid->resource, |
| 191 jm->delayed ? GAIM_CONV_CHAT_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); |
| 8537 | 206 char *stripped; |
| 7014 | 207 |
| 7310 | 208 if(!jid) |
| 209 return; | |
| 210 | |
| 211 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 212 | |
| 7332 | 213 g_hash_table_replace(components, g_strdup("room"), g_strdup(jid->node)); |
| 7448 | 214 g_hash_table_replace(components, g_strdup("server"), g_strdup(jid->domain)); |
| 7332 | 215 g_hash_table_replace(components, g_strdup("handle"), |
| 216 g_strdup(jm->js->user->node)); | |
| 217 g_hash_table_replace(components, g_strdup("password"), | |
| 218 g_strdup(jm->password)); | |
| 7014 | 219 |
| 220 jabber_id_free(jid); | |
| 8537 | 221 stripped = gaim_markup_strip_html(jm->body); |
| 222 serv_got_chat_invite(jm->js->gc, jm->to, jm->from, stripped, components); | |
| 223 g_free(stripped); | |
| 7014 | 224 } |
| 225 | |
| 7145 | 226 static void handle_error(JabberMessage *jm) |
| 7014 | 227 { |
| 228 char *buf; | |
| 229 | |
| 230 if(!jm->body) | |
| 231 return; | |
| 232 | |
| 233 buf = g_strdup_printf(_("Message delivery to %s failed: %s"), | |
| 234 jm->from, jm->error); | |
| 235 | |
| 7944 | 236 gaim_notify_formatted(jm->js->gc, _("Jabber Message Error"), _("Jabber Message Error"), buf, |
| 237 jm->xhtml ? jm->xhtml : jm->body, NULL, NULL); | |
| 7014 | 238 |
| 239 g_free(buf); | |
| 240 } | |
| 241 | |
| 242 void jabber_message_parse(JabberStream *js, xmlnode *packet) | |
| 243 { | |
| 244 JabberMessage *jm; | |
| 245 const char *type; | |
| 246 xmlnode *child; | |
| 247 | |
| 248 if(strcmp(packet->name, "message")) | |
| 249 return; | |
| 250 | |
| 251 jm = g_new0(JabberMessage, 1); | |
| 252 jm->js = js; | |
| 253 jm->sent = time(NULL); | |
| 9584 | 254 jm->delayed = FALSE; |
| 7014 | 255 |
| 256 type = xmlnode_get_attrib(packet, "type"); | |
| 257 | |
| 258 if(type) { | |
| 259 if(!strcmp(type, "normal")) | |
| 260 jm->type = JABBER_MESSAGE_NORMAL; | |
| 261 else if(!strcmp(type, "chat")) | |
| 262 jm->type = JABBER_MESSAGE_CHAT; | |
| 263 else if(!strcmp(type, "groupchat")) | |
| 264 jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 265 else if(!strcmp(type, "headline")) | |
| 266 jm->type = JABBER_MESSAGE_HEADLINE; | |
| 267 else if(!strcmp(type, "error")) | |
| 268 jm->type = JABBER_MESSAGE_ERROR; | |
| 269 else | |
| 270 jm->type = JABBER_MESSAGE_OTHER; | |
| 271 } else { | |
| 272 jm->type = JABBER_MESSAGE_NORMAL; | |
| 273 } | |
| 274 | |
| 275 jm->from = g_strdup(xmlnode_get_attrib(packet, "from")); | |
| 276 jm->to = g_strdup(xmlnode_get_attrib(packet, "to")); | |
| 277 | |
| 278 for(child = packet->child; child; child = child->next) { | |
| 8135 | 279 if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 280 continue; |
| 281 | |
| 282 if(!strcmp(child->name, "subject")) { | |
| 283 if(!jm->subject) | |
| 284 jm->subject = xmlnode_get_data(child); | |
| 8400 | 285 } else if(!strcmp(child->name, "thread")) { |
| 286 if(!jm->thread_id) | |
| 287 jm->thread_id = xmlnode_get_data(child); | |
| 7014 | 288 } else if(!strcmp(child->name, "body")) { |
| 289 if(!jm->body) | |
| 7894 | 290 jm->body = xmlnode_to_str(child, NULL); |
| 7241 | 291 } else if(!strcmp(child->name, "html")) { |
| 10607 | 292 if(!jm->xhtml && child->data_sz > 0) |
| 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 | 315 jm->delayed = TRUE; |
| 7014 | 316 if(timestamp) |
| 8577 | 317 jm->sent = gaim_str_to_time(timestamp, TRUE); |
| 7014 | 318 } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") && |
| 319 jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE) { | |
| 320 const char *jid = xmlnode_get_attrib(child, "jid"); | |
| 321 if(jid) { | |
| 322 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 323 g_free(jm->to); | |
| 324 jm->to = g_strdup(jid); | |
| 325 } | |
| 326 } else if(xmlns && !strcmp(xmlns, | |
| 327 "http://jabber.org/protocol/muc#user")) { | |
| 328 xmlnode *invite = xmlnode_get_child(child, "invite"); | |
| 329 if(invite) { | |
| 330 xmlnode *reason, *password; | |
| 7968 | 331 const char *jid = xmlnode_get_attrib(invite, "from"); |
| 7014 | 332 g_free(jm->to); |
| 333 jm->to = jm->from; | |
| 334 jm->from = g_strdup(jid); | |
| 335 if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 336 g_free(jm->body); | |
| 337 jm->body = xmlnode_get_data(reason); | |
| 338 } | |
| 339 if((password = xmlnode_get_child(invite, "password"))) | |
| 340 jm->password = xmlnode_get_data(password); | |
| 341 | |
| 342 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 343 } | |
| 7145 | 344 } else { |
| 345 jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 346 } |
| 347 } | |
| 348 } | |
| 349 | |
| 350 switch(jm->type) { | |
| 351 case JABBER_MESSAGE_NORMAL: | |
| 352 case JABBER_MESSAGE_CHAT: | |
| 7145 | 353 handle_chat(jm); |
| 354 break; | |
| 7014 | 355 case JABBER_MESSAGE_HEADLINE: |
| 7145 | 356 handle_headline(jm); |
| 7014 | 357 break; |
| 358 case JABBER_MESSAGE_GROUPCHAT: | |
| 359 handle_groupchat(jm); | |
| 360 break; | |
| 361 case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 362 handle_groupchat_invite(jm); | |
| 363 break; | |
| 364 case JABBER_MESSAGE_ERROR: | |
| 365 handle_error(jm); | |
| 366 break; | |
| 367 case JABBER_MESSAGE_OTHER: | |
| 368 gaim_debug(GAIM_DEBUG_INFO, "jabber", | |
| 369 "Received message of unknown type: %s\n", type); | |
| 370 break; | |
| 371 } | |
| 372 jabber_message_free(jm); | |
| 373 } | |
| 374 | |
| 375 void jabber_message_send(JabberMessage *jm) | |
| 376 { | |
| 377 xmlnode *message, *child; | |
| 378 const char *type = NULL; | |
| 379 | |
| 380 message = xmlnode_new("message"); | |
| 381 | |
| 382 switch(jm->type) { | |
| 383 case JABBER_MESSAGE_NORMAL: | |
| 384 type = "normal"; | |
| 385 break; | |
| 386 case JABBER_MESSAGE_CHAT: | |
| 387 case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 388 type = "chat"; | |
| 389 break; | |
| 390 case JABBER_MESSAGE_HEADLINE: | |
| 391 type = "headline"; | |
| 392 break; | |
| 393 case JABBER_MESSAGE_GROUPCHAT: | |
| 394 type = "groupchat"; | |
| 395 break; | |
| 396 case JABBER_MESSAGE_ERROR: | |
| 397 type = "error"; | |
| 398 break; | |
| 399 case JABBER_MESSAGE_OTHER: | |
| 400 type = NULL; | |
| 401 break; | |
| 402 } | |
| 403 | |
| 404 if(type) | |
| 405 xmlnode_set_attrib(message, "type", type); | |
| 406 | |
| 407 xmlnode_set_attrib(message, "to", jm->to); | |
| 408 | |
| 8400 | 409 if(jm->thread_id) { |
| 410 child = xmlnode_new_child(message, "thread"); | |
| 411 xmlnode_insert_data(child, jm->thread_id, -1); | |
| 412 } | |
| 413 | |
| 7971 | 414 if(jm->events || (!jm->body && !jm->xhtml && !jm->subject)) { |
| 7014 | 415 child = xmlnode_new_child(message, "x"); |
| 416 xmlnode_set_attrib(child, "xmlns", "jabber:x:event"); | |
| 417 if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 418 xmlnode_new_child(child, "composing"); | |
| 419 } | |
| 420 | |
| 421 if(jm->subject) { | |
| 422 child = xmlnode_new_child(message, "subject"); | |
| 423 xmlnode_insert_data(child, jm->subject, -1); | |
| 424 } | |
| 425 | |
| 426 if(jm->body) { | |
| 427 child = xmlnode_new_child(message, "body"); | |
| 428 xmlnode_insert_data(child, jm->body, -1); | |
| 429 } | |
| 430 | |
| 431 if(jm->xhtml) { | |
| 432 child = xmlnode_from_str(jm->xhtml, -1); | |
| 433 if(child) { | |
| 434 xmlnode_insert_child(message, child); | |
| 435 } else { | |
| 436 gaim_debug(GAIM_DEBUG_ERROR, "jabber", | |
| 437 "XHTML translation/validation failed, returning: %s\n", | |
| 438 jm->xhtml); | |
| 439 } | |
| 440 } | |
| 441 | |
| 442 jabber_send(jm->js, message); | |
| 443 | |
| 444 xmlnode_free(message); | |
| 445 } | |
| 446 | |
| 447 int jabber_message_send_im(GaimConnection *gc, const char *who, const char *msg, | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7095
diff
changeset
|
448 GaimConvImFlags flags) |
| 7014 | 449 { |
| 450 JabberMessage *jm; | |
| 451 JabberBuddy *jb; | |
| 452 JabberBuddyResource *jbr; | |
| 453 char *buf; | |
| 7135 | 454 char *xhtml; |
| 7306 | 455 char *resource; |
| 7014 | 456 |
| 457 if(!who || !msg) | |
| 458 return 0; | |
| 459 | |
| 7306 | 460 resource = jabber_get_resource(who); |
| 461 | |
| 7014 | 462 jb = jabber_buddy_find(gc->proto_data, who, TRUE); |
| 7306 | 463 jbr = jabber_buddy_find_resource(jb, resource); |
| 464 | |
| 465 g_free(resource); | |
| 7014 | 466 |
| 467 jm = g_new0(JabberMessage, 1); | |
| 468 jm->js = gc->proto_data; | |
| 469 jm->type = JABBER_MESSAGE_CHAT; | |
| 470 jm->events = JABBER_MESSAGE_EVENT_COMPOSING; | |
| 471 jm->to = g_strdup(who); | |
| 8400 | 472 if(jbr && jbr->thread_id) |
| 473 jm->thread_id = jbr->thread_id; | |
| 7014 | 474 |
| 7773 | 475 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 | 476 |
| 7135 | 477 gaim_markup_html_to_xhtml(buf, &xhtml, &jm->body); |
| 7014 | 478 g_free(buf); |
| 479 | |
| 480 if(!jbr || jbr->capabilities & JABBER_CAP_XHTML) | |
| 481 jm->xhtml = xhtml; | |
| 482 else | |
| 483 g_free(xhtml); | |
| 484 | |
| 485 jabber_message_send(jm); | |
| 486 jabber_message_free(jm); | |
| 487 return 1; | |
| 488 } | |
| 489 | |
| 7345 | 490 int jabber_message_send_chat(GaimConnection *gc, int id, const char *msg) |
| 7014 | 491 { |
| 492 JabberChat *chat; | |
| 493 JabberMessage *jm; | |
| 8042 | 494 JabberStream *js; |
| 9130 | 495 char *buf; |
| 7014 | 496 |
| 8042 | 497 if(!msg || !gc) |
| 7014 | 498 return 0; |
| 499 | |
| 8042 | 500 js = gc->proto_data; |
| 7014 | 501 chat = jabber_chat_find_by_id(js, id); |
| 502 | |
| 8043 | 503 if(!chat) |
| 504 return 0; | |
| 505 | |
| 9130 | 506 jm = g_new0(JabberMessage, 1); |
| 507 jm->js = gc->proto_data; | |
| 508 jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 509 jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 510 | |
| 8858 | 511 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 | 512 gaim_markup_html_to_xhtml(buf, &jm->xhtml, &jm->body); |
| 8858 | 513 g_free(buf); |
| 514 | |
| 9130 | 515 if(!chat->xhtml) { |
| 516 g_free(jm->xhtml); | |
| 517 jm->xhtml = NULL; | |
| 7923 | 518 } |
| 519 | |
| 9130 | 520 jabber_message_send(jm); |
| 521 jabber_message_free(jm); | |
| 522 | |
| 7014 | 523 return 1; |
| 524 } | |
| 525 | |
| 526 int jabber_send_typing(GaimConnection *gc, const char *who, int typing) | |
| 527 { | |
| 528 JabberMessage *jm; | |
| 529 JabberBuddy *jb; | |
| 530 JabberBuddyResource *jbr; | |
| 7306 | 531 char *resource = jabber_get_resource(who); |
| 7014 | 532 |
| 533 jb = jabber_buddy_find(gc->proto_data, who, TRUE); | |
| 7306 | 534 jbr = jabber_buddy_find_resource(jb, resource); |
| 535 | |
| 536 g_free(resource); | |
| 7014 | 537 |
| 7187 | 538 if(!jbr || !(jbr->capabilities & JABBER_CAP_COMPOSING)) |
| 7014 | 539 return 0; |
| 540 | |
| 541 jm = g_new0(JabberMessage, 1); | |
| 542 jm->js = gc->proto_data; | |
| 543 jm->type = JABBER_MESSAGE_CHAT; | |
| 544 jm->to = g_strdup(who); | |
| 545 | |
| 546 if(typing == GAIM_TYPING) | |
| 547 jm->events = JABBER_MESSAGE_EVENT_COMPOSING; | |
| 548 | |
| 549 jabber_message_send(jm); | |
| 550 jabber_message_free(jm); | |
| 551 | |
| 552 return JABBER_TYPING_NOTIFY_INT; | |
| 553 } | |
| 554 |
