Mon, 10 Apr 2006 23:43:49 +0000
[gaim-migrate @ 16003]
A patch from Björn Voigt to implement an error notification when a user search fails.
committer: Richard Laager <rlaager@pidgin.im>
| 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 | { | |
| 13484 | 37 | g_free(jm->from); |
| 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) { |
| 67 | GaimConversation *conv; | |
| 7258 | 68 | |
| 10490 | 69 | from = g_strdup_printf("%s@%s", jid->node, jid->domain); |
| 13304 | 70 | conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, from, jm->js->gc->account); |
| 10490 | 71 | if(conv) { |
| 72 | gaim_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) { | |
| 82 | if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 83 | serv_got_typing(jm->js->gc, from, 0, GAIM_TYPING); | |
| 84 | else | |
| 85 | serv_got_typing_stopped(jm->js->gc, from); | |
| 86 | } else { | |
| 8400 | 87 | if(jbr) { |
| 88 | if(jm->events & JABBER_MESSAGE_EVENT_COMPOSING) | |
| 89 | jbr->capabilities |= JABBER_CAP_COMPOSING; | |
| 90 | if(jbr->thread_id) | |
| 91 | g_free(jbr->thread_id); | |
| 92 | jbr->thread_id = g_strdup(jbr->thread_id); | |
| 93 | } | |
| 7014 | 94 | serv_got_im(jm->js->gc, from, jm->xhtml ? jm->xhtml : jm->body, 0, |
| 95 | jm->sent); | |
| 96 | } | |
| 97 | ||
| 98 | g_free(from); | |
| 99 | jabber_id_free(jid); | |
| 100 | } | |
| 101 | ||
| 7145 | 102 | static void handle_headline(JabberMessage *jm) |
| 103 | { | |
| 104 | char *title; | |
| 105 | GString *body = g_string_new(""); | |
| 106 | GList *etc; | |
| 107 | ||
| 108 | title = g_strdup_printf(_("Message from %s"), jm->from); | |
| 109 | ||
| 110 | if(jm->xhtml) | |
| 111 | g_string_append(body, jm->xhtml); | |
| 112 | else if(jm->body) | |
| 113 | g_string_append(body, jm->body); | |
| 114 | ||
| 115 | for(etc = jm->etc; etc; etc = etc->next) { | |
| 116 | xmlnode *x = etc->data; | |
| 117 | const char *xmlns = xmlnode_get_attrib(x, "xmlns"); | |
| 118 | if(xmlns && !strcmp(xmlns, "jabber:x:oob")) { | |
| 119 | xmlnode *url, *desc; | |
| 120 | char *urltxt, *desctxt; | |
| 121 | ||
| 122 | url = xmlnode_get_child(x, "url"); | |
| 123 | desc = xmlnode_get_child(x, "desc"); | |
| 124 | ||
| 125 | if(!url || !desc) | |
| 126 | continue; | |
| 127 | ||
| 128 | urltxt = xmlnode_get_data(url); | |
| 129 | desctxt = xmlnode_get_data(desc); | |
| 130 | ||
| 131 | /* I'm all about ugly hacks */ | |
| 132 | if(body->len && !strcmp(body->str, jm->body)) | |
| 133 | g_string_printf(body, "<a href='%s'>%s</a>", | |
| 134 | urltxt, desctxt); | |
| 135 | else | |
| 136 | g_string_append_printf(body, "<br/><a href='%s'>%s</a>", | |
| 137 | urltxt, desctxt); | |
| 138 | ||
| 139 | g_free(urltxt); | |
| 140 | g_free(desctxt); | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | gaim_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title, | |
| 145 | NULL, body->str, NULL, NULL); | |
| 146 | ||
| 147 | g_free(title); | |
| 148 | g_string_free(body, TRUE); | |
| 149 | } | |
| 150 | ||
| 151 | static void handle_groupchat(JabberMessage *jm) | |
| 7014 | 152 | { |
| 153 | JabberID *jid = jabber_id_new(jm->from); | |
| 7310 | 154 | JabberChat *chat; |
| 155 | ||
| 156 | if(!jid) | |
| 157 | return; | |
| 158 | ||
| 159 | chat = jabber_chat_find(jm->js, jid->node, jid->domain); | |
| 7014 | 160 | |
| 161 | if(!chat) | |
| 162 | return; | |
| 163 | ||
| 7971 | 164 | if(jm->subject) { |
| 7183 | 165 | gaim_conv_chat_set_topic(GAIM_CONV_CHAT(chat->conv), jid->resource, |
| 166 | jm->subject); | |
| 7971 | 167 | if(!jm->xhtml && !jm->body) { |
| 9762 | 168 | char *msg, *tmp, *tmp2; |
|
10732
5e314ab498bf
[gaim-migrate @ 12334]
Richard Laager <rlaager@pidgin.im>
parents:
10607
diff
changeset
|
169 | tmp = g_markup_escape_text(jm->subject, -1); |
| 9762 | 170 | tmp2 = gaim_markup_linkify(tmp); |
| 7971 | 171 | if(jid->resource) |
| 9762 | 172 | msg = g_strdup_printf(_("%s has set the topic to: %s"), jid->resource, tmp2); |
| 7971 | 173 | else |
| 9762 | 174 | msg = g_strdup_printf(_("The topic is: %s"), tmp2); |
| 7971 | 175 | gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", msg, GAIM_MESSAGE_SYSTEM, jm->sent); |
| 9762 | 176 | g_free(tmp); |
| 177 | g_free(tmp2); | |
| 7971 | 178 | g_free(msg); |
| 179 | } | |
| 180 | } | |
| 7014 | 181 | |
| 7630 | 182 | if(jm->xhtml || jm->body) { |
| 183 | if(jid->resource) | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
184 | 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
|
185 | jm->delayed ? GAIM_MESSAGE_DELAYED : 0, |
| 7630 | 186 | jm->xhtml ? jm->xhtml : jm->body, jm->sent); |
| 187 | else if(chat->muc) | |
| 188 | gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", | |
| 189 | jm->xhtml ? jm->xhtml : jm->body, | |
| 190 | GAIM_MESSAGE_SYSTEM, jm->sent); | |
| 191 | } | |
| 192 | ||
| 7014 | 193 | jabber_id_free(jid); |
| 194 | } | |
| 195 | ||
| 7145 | 196 | static void handle_groupchat_invite(JabberMessage *jm) |
| 7014 | 197 | { |
| 7310 | 198 | GHashTable *components; |
| 7014 | 199 | JabberID *jid = jabber_id_new(jm->to); |
| 200 | ||
| 7310 | 201 | if(!jid) |
| 202 | return; | |
| 203 | ||
| 204 | components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 205 | ||
| 7332 | 206 | g_hash_table_replace(components, g_strdup("room"), g_strdup(jid->node)); |
| 7448 | 207 | g_hash_table_replace(components, g_strdup("server"), g_strdup(jid->domain)); |
| 7332 | 208 | g_hash_table_replace(components, g_strdup("handle"), |
| 209 | g_strdup(jm->js->user->node)); | |
| 210 | g_hash_table_replace(components, g_strdup("password"), | |
| 211 | g_strdup(jm->password)); | |
| 7014 | 212 | |
| 213 | jabber_id_free(jid); | |
|
10774
f4238d6312ff
[gaim-migrate @ 12383]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10732
diff
changeset
|
214 | serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components); |
| 7014 | 215 | } |
| 216 | ||
| 7145 | 217 | static void handle_error(JabberMessage *jm) |
| 7014 | 218 | { |
| 219 | char *buf; | |
| 220 | ||
| 221 | if(!jm->body) | |
| 222 | return; | |
| 223 | ||
| 224 | buf = g_strdup_printf(_("Message delivery to %s failed: %s"), | |
| 225 | jm->from, jm->error); | |
| 226 | ||
| 7944 | 227 | gaim_notify_formatted(jm->js->gc, _("Jabber Message Error"), _("Jabber Message Error"), buf, |
| 228 | jm->xhtml ? jm->xhtml : jm->body, NULL, NULL); | |
| 7014 | 229 | |
| 230 | g_free(buf); | |
| 231 | } | |
| 232 | ||
| 233 | void jabber_message_parse(JabberStream *js, xmlnode *packet) | |
| 234 | { | |
| 235 | JabberMessage *jm; | |
| 236 | const char *type; | |
| 237 | xmlnode *child; | |
| 238 | ||
| 239 | if(strcmp(packet->name, "message")) | |
| 240 | return; | |
| 241 | ||
| 242 | jm = g_new0(JabberMessage, 1); | |
| 243 | jm->js = js; | |
| 244 | jm->sent = time(NULL); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
245 | jm->delayed = FALSE; |
| 7014 | 246 | |
| 247 | type = xmlnode_get_attrib(packet, "type"); | |
| 248 | ||
| 249 | if(type) { | |
| 250 | if(!strcmp(type, "normal")) | |
| 251 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 252 | else if(!strcmp(type, "chat")) | |
| 253 | jm->type = JABBER_MESSAGE_CHAT; | |
| 254 | else if(!strcmp(type, "groupchat")) | |
| 255 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 256 | else if(!strcmp(type, "headline")) | |
| 257 | jm->type = JABBER_MESSAGE_HEADLINE; | |
| 258 | else if(!strcmp(type, "error")) | |
| 259 | jm->type = JABBER_MESSAGE_ERROR; | |
| 260 | else | |
| 261 | jm->type = JABBER_MESSAGE_OTHER; | |
| 262 | } else { | |
| 263 | jm->type = JABBER_MESSAGE_NORMAL; | |
| 264 | } | |
| 265 | ||
| 266 | jm->from = g_strdup(xmlnode_get_attrib(packet, "from")); | |
| 267 | jm->to = g_strdup(xmlnode_get_attrib(packet, "to")); | |
| 13484 | 268 | jm->id = g_strdup(xmlnode_get_attrib(packet, "id")); |
| 7014 | 269 | |
| 270 | for(child = packet->child; child; child = child->next) { | |
| 8135 | 271 | if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 272 | continue; |
| 273 | ||
| 274 | if(!strcmp(child->name, "subject")) { | |
| 275 | if(!jm->subject) | |
| 276 | jm->subject = xmlnode_get_data(child); | |
| 8400 | 277 | } else if(!strcmp(child->name, "thread")) { |
| 278 | if(!jm->thread_id) | |
| 279 | jm->thread_id = xmlnode_get_data(child); | |
| 7014 | 280 | } else if(!strcmp(child->name, "body")) { |
| 13385 | 281 | if(!jm->body) { |
| 282 | char *msg = xmlnode_to_str(child, NULL); | |
| 283 | jm->body = gaim_strdup_withhtml(msg); | |
| 284 | g_free(msg); | |
| 285 | } | |
| 7241 | 286 | } else if(!strcmp(child->name, "html")) { |
| 11788 | 287 | if(!jm->xhtml && xmlnode_get_child(child, "body")) |
| 7642 | 288 | jm->xhtml = xmlnode_to_str(child, NULL); |
| 7014 | 289 | } else if(!strcmp(child->name, "error")) { |
| 290 | const char *code = xmlnode_get_attrib(child, "code"); | |
| 291 | char *code_txt = NULL; | |
| 292 | char *text = xmlnode_get_data(child); | |
| 293 | ||
| 294 | if(code) | |
| 295 | code_txt = g_strdup_printf(_(" (Code %s)"), code); | |
| 296 | ||
| 297 | if(!jm->error) | |
| 298 | jm->error = g_strdup_printf("%s%s", text ? text : "", | |
| 299 | code_txt ? code_txt : ""); | |
| 300 | ||
| 301 | g_free(code_txt); | |
| 302 | g_free(text); | |
| 303 | } else if(!strcmp(child->name, "x")) { | |
| 304 | const char *xmlns = xmlnode_get_attrib(child, "xmlns"); | |
| 305 | if(xmlns && !strcmp(xmlns, "jabber:x:event")) { | |
| 306 | if(xmlnode_get_child(child, "composing")) | |
| 307 | jm->events |= JABBER_MESSAGE_EVENT_COMPOSING; | |
| 308 | } else if(xmlns && !strcmp(xmlns, "jabber:x:delay")) { | |
| 309 | const char *timestamp = xmlnode_get_attrib(child, "stamp"); | |
|
9584
1a6198375303
[gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9130
diff
changeset
|
310 | jm->delayed = TRUE; |
| 7014 | 311 | if(timestamp) |
|
13120
c25222322810
[gaim-migrate @ 15481]
Richard Laager <rlaager@pidgin.im>
parents:
12216
diff
changeset
|
312 | jm->sent = gaim_str_to_time(timestamp, TRUE, NULL, NULL, NULL); |
| 7014 | 313 | } else if(xmlns && !strcmp(xmlns, "jabber:x:conference") && |
| 11230 | 314 | jm->type != JABBER_MESSAGE_GROUPCHAT_INVITE && |
| 315 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 316 | const char *jid = xmlnode_get_attrib(child, "jid"); |
| 317 | if(jid) { | |
| 318 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 319 | g_free(jm->to); | |
| 320 | jm->to = g_strdup(jid); | |
| 321 | } | |
| 322 | } else if(xmlns && !strcmp(xmlns, | |
| 11230 | 323 | "http://jabber.org/protocol/muc#user") && |
| 324 | jm->type != JABBER_MESSAGE_ERROR) { | |
| 7014 | 325 | xmlnode *invite = xmlnode_get_child(child, "invite"); |
| 326 | if(invite) { | |
| 327 | xmlnode *reason, *password; | |
| 7968 | 328 | const char *jid = xmlnode_get_attrib(invite, "from"); |
| 7014 | 329 | g_free(jm->to); |
| 330 | jm->to = jm->from; | |
| 331 | jm->from = g_strdup(jid); | |
| 332 | if((reason = xmlnode_get_child(invite, "reason"))) { | |
| 333 | g_free(jm->body); | |
| 334 | jm->body = xmlnode_get_data(reason); | |
| 335 | } | |
| 11576 | 336 | if((password = xmlnode_get_child(child, "password"))) |
| 7014 | 337 | jm->password = xmlnode_get_data(password); |
| 338 | ||
| 339 | jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; | |
| 340 | } | |
| 7145 | 341 | } else { |
| 342 | jm->etc = g_list_append(jm->etc, child); | |
| 7014 | 343 | } |
| 344 | } | |
| 345 | } | |
| 346 | ||
| 347 | switch(jm->type) { | |
| 348 | case JABBER_MESSAGE_NORMAL: | |
| 349 | case JABBER_MESSAGE_CHAT: | |
| 7145 | 350 | handle_chat(jm); |
| 351 | break; | |
| 7014 | 352 | case JABBER_MESSAGE_HEADLINE: |
| 7145 | 353 | handle_headline(jm); |
| 7014 | 354 | break; |
| 355 | case JABBER_MESSAGE_GROUPCHAT: | |
| 356 | handle_groupchat(jm); | |
| 357 | break; | |
| 358 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 359 | handle_groupchat_invite(jm); | |
| 360 | break; | |
| 361 | case JABBER_MESSAGE_ERROR: | |
| 362 | handle_error(jm); | |
| 363 | break; | |
| 364 | case JABBER_MESSAGE_OTHER: | |
| 365 | gaim_debug(GAIM_DEBUG_INFO, "jabber", | |
| 366 | "Received message of unknown type: %s\n", type); | |
| 367 | break; | |
| 368 | } | |
| 369 | jabber_message_free(jm); | |
| 370 | } | |
| 371 | ||
| 372 | void jabber_message_send(JabberMessage *jm) | |
| 373 | { | |
| 374 | xmlnode *message, *child; | |
| 375 | const char *type = NULL; | |
| 376 | ||
| 377 | message = xmlnode_new("message"); | |
| 378 | ||
| 379 | switch(jm->type) { | |
| 380 | case JABBER_MESSAGE_NORMAL: | |
| 381 | type = "normal"; | |
| 382 | break; | |
| 383 | case JABBER_MESSAGE_CHAT: | |
| 384 | case JABBER_MESSAGE_GROUPCHAT_INVITE: | |
| 385 | type = "chat"; | |
| 386 | break; | |
| 387 | case JABBER_MESSAGE_HEADLINE: | |
| 388 | type = "headline"; | |
| 389 | break; | |
| 390 | case JABBER_MESSAGE_GROUPCHAT: | |
| 391 | type = "groupchat"; | |
| 392 | break; | |
| 393 | case JABBER_MESSAGE_ERROR: | |
| 394 | type = "error"; | |
| 395 | break; | |
| 396 | case JABBER_MESSAGE_OTHER: | |
| 397 | type = NULL; | |
| 398 | break; | |
| 399 | } | |
| 400 | ||
| 401 | if(type) | |
| 402 | xmlnode_set_attrib(message, "type", type); | |
| 13484 | 403 | |
| 404 | if (jm->id) | |
| 405 | xmlnode_set_attrib(message, "id", jm->id); | |
| 7014 | 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, | |
|
12216
d80739091a63
[gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11788
diff
changeset
|
448 | GaimMessageFlags 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); | |
| 13484 | 472 | jm->id = jabber_get_next_id(jm->js); |
| 8400 | 473 | if(jbr && jbr->thread_id) |
| 474 | jm->thread_id = jbr->thread_id; | |
| 7014 | 475 | |
| 7773 | 476 | 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 | 477 | |
| 7135 | 478 | gaim_markup_html_to_xhtml(buf, &xhtml, &jm->body); |
| 7014 | 479 | g_free(buf); |
| 480 | ||
| 481 | if(!jbr || jbr->capabilities & JABBER_CAP_XHTML) | |
| 482 | jm->xhtml = xhtml; | |
| 483 | else | |
| 484 | g_free(xhtml); | |
| 485 | ||
| 486 | jabber_message_send(jm); | |
| 487 | jabber_message_free(jm); | |
| 488 | return 1; | |
| 489 | } | |
| 490 | ||
|
12216
d80739091a63
[gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11788
diff
changeset
|
491 | int jabber_message_send_chat(GaimConnection *gc, int id, const char *msg, GaimMessageFlags flags) |
| 7014 | 492 | { |
| 493 | JabberChat *chat; | |
| 494 | JabberMessage *jm; | |
| 8042 | 495 | JabberStream *js; |
| 9130 | 496 | char *buf; |
| 7014 | 497 | |
| 8042 | 498 | if(!msg || !gc) |
| 7014 | 499 | return 0; |
| 500 | ||
| 8042 | 501 | js = gc->proto_data; |
| 7014 | 502 | chat = jabber_chat_find_by_id(js, id); |
| 503 | ||
| 8043 | 504 | if(!chat) |
| 505 | return 0; | |
| 506 | ||
| 9130 | 507 | jm = g_new0(JabberMessage, 1); |
| 508 | jm->js = gc->proto_data; | |
| 509 | jm->type = JABBER_MESSAGE_GROUPCHAT; | |
| 510 | jm->to = g_strdup_printf("%s@%s", chat->room, chat->server); | |
| 13484 | 511 | jm->id = jabber_get_next_id(jm->js); |
| 9130 | 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); | |
| 13484 | 547 | jm->id = jabber_get_next_id(jm->js); |
| 7014 | 548 | |
| 549 | if(typing == GAIM_TYPING) | |
| 550 | jm->events = JABBER_MESSAGE_EVENT_COMPOSING; | |
| 551 | ||
| 552 | jabber_message_send(jm); | |
| 553 | jabber_message_free(jm); | |
| 554 | ||
| 555 | return JABBER_TYPING_NOTIFY_INT; | |
| 556 | } | |
| 557 |