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