Sun, 22 Nov 2009 18:56:06 +0000
Plucked d2a1d52b3bbf29baa53b9ddaa635d50b6332064f from im.pidgin.adium
by Zac West:
Fixed sending DIM messages' encoding. Fixes #9087.
The encoding bytes were being written in the wrong location, so the messages
were being read back as ASCII and failing conversion, ending up being empty
and not being displayed.
Plucked f5376d42261b8efc3d889314df9896bb10d3fe16 from im.pidgin.adium:
iChat sends direct IM messages with its encoding as 0x000d, which was being
forced-interpreted as ASCII. Also, added better debug logging for charset
information being received.
applied changes from 212bd3655451599364562cabe553c5b7a19134ae
through d2a1d52b3bbf29baa53b9ddaa635d50b6332064f
applied changes from d2a1d52b3bbf29baa53b9ddaa635d50b6332064f
through f5376d42261b8efc3d889314df9896bb10d3fe16
| 13593 | 1 | /* |
| 15884 | 2 | * Purple's oscar protocol plugin |
| 13593 | 3 | * This file is the legal property of its developers. |
| 4 | * Please see the AUTHORS file distributed alongside this file. | |
| 5 | * | |
| 6 | * This library is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU Lesser General Public | |
| 8 | * License as published by the Free Software Foundation; either | |
| 9 | * version 2 of the License, or (at your option) any later version. | |
| 10 | * | |
| 11 | * This library 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 GNU | |
| 14 | * Lesser General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU Lesser General Public | |
| 17 | * License along with this library; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18552
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 13593 | 19 | */ |
| 20 | ||
| 21 | /* From the oscar PRPL */ | |
| 22 | #include "oscar.h" | |
| 23 | #include "peer.h" | |
| 24 | ||
| 15884 | 25 | /* From Purple */ |
| 13593 | 26 | #include "conversation.h" |
| 27 | #include "imgstore.h" | |
| 28 | #include "util.h" | |
| 29 | ||
|
20192
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
30 | #define DIRECTIM_MAX_FILESIZE 52428800 |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
31 | |
| 13593 | 32 | /** |
| 33 | * Free any ODC related data and print a message to the conversation | |
| 34 | * window based on conn->disconnect_reason. | |
| 35 | */ | |
| 36 | void | |
| 37 | peer_odc_close(PeerConnection *conn) | |
| 38 | { | |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
39 | gchar *tmp; |
| 13593 | 40 | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
41 | if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
42 | tmp = g_strdup(_("The remote user has closed the connection.")); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
43 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_REFUSED) |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
44 | tmp = g_strdup(_("The remote user has declined your request.")); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
45 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION) |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
46 | tmp = g_strdup_printf(_("Lost connection with the remote user:<br>%s"), |
|
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
47 | conn->error_message); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
48 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA) |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
49 | tmp = g_strdup(_("Received invalid data on connection with remote user.")); |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
50 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT) |
|
27635
0cd19038c417
More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents:
25889
diff
changeset
|
51 | tmp = g_strdup(_("Unable to establish a connection with the remote user.")); |
| 13593 | 52 | else |
| 53 | /* | |
| 54 | * We shouldn't print a message for some disconnect_reasons. | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
55 | * Like OSCAR_DISCONNECT_LOCAL_CLOSED. |
| 13593 | 56 | */ |
| 57 | tmp = NULL; | |
| 58 | ||
| 59 | if (tmp != NULL) | |
| 60 | { | |
| 15884 | 61 | PurpleAccount *account; |
| 62 | PurpleConversation *conv; | |
| 13593 | 63 | |
| 15884 | 64 | account = purple_connection_get_account(conn->od->gc); |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
65 | conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, conn->bn); |
| 15884 | 66 | purple_conversation_write(conv, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL)); |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
67 | g_free(tmp); |
| 13593 | 68 | } |
| 69 | ||
| 70 | if (conn->frame != NULL) | |
| 71 | { | |
| 72 | OdcFrame *frame; | |
| 73 | frame = conn->frame; | |
| 74 | g_free(frame->payload.data); | |
| 75 | g_free(frame); | |
| 76 | } | |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * Write the given OdcFrame to a ByteStream and send it out | |
| 81 | * on the established PeerConnection. | |
| 82 | */ | |
| 83 | static void | |
| 84 | peer_odc_send(PeerConnection *conn, OdcFrame *frame) | |
| 85 | { | |
| 15884 | 86 | PurpleAccount *account; |
| 13593 | 87 | const char *username; |
| 88 | size_t length; | |
| 89 | ByteStream bs; | |
| 90 | ||
| 15884 | 91 | purple_debug_info("oscar", "Outgoing ODC frame to %s with " |
| 13593 | 92 | "type=0x%04x, flags=0x%04x, payload length=%u\n", |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
93 | conn->bn, frame->type, frame->flags, frame->payload.len); |
| 13593 | 94 | |
| 15884 | 95 | account = purple_connection_get_account(conn->od->gc); |
| 96 | username = purple_account_get_username(account); | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
97 | memcpy(frame->bn, username, strlen(username)); |
| 13593 | 98 | memcpy(frame->cookie, conn->cookie, 8); |
| 99 | ||
| 100 | length = 76; | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14464
diff
changeset
|
101 | byte_stream_new(&bs, length + frame->payload.len); |
| 13593 | 102 | byte_stream_putraw(&bs, conn->magic, 4); |
| 103 | byte_stream_put16(&bs, length); | |
| 104 | byte_stream_put16(&bs, frame->type); | |
| 105 | byte_stream_put16(&bs, frame->subtype); | |
| 106 | byte_stream_put16(&bs, 0x0000); | |
| 107 | byte_stream_putraw(&bs, frame->cookie, 8); | |
| 108 | byte_stream_put16(&bs, 0x0000); | |
| 109 | byte_stream_put16(&bs, 0x0000); | |
| 110 | byte_stream_put16(&bs, 0x0000); | |
| 111 | byte_stream_put16(&bs, 0x0000); | |
| 112 | byte_stream_put32(&bs, frame->payload.len); | |
| 113 | byte_stream_put16(&bs, frame->encoding); | |
|
28944
16a690432828
Plucked d2a1d52b3bbf29baa53b9ddaa635d50b6332064f from im.pidgin.adium
Evan Schoenberg <evands@pidgin.im>
parents:
27635
diff
changeset
|
114 | byte_stream_put16(&bs, 0x0000); |
| 13593 | 115 | byte_stream_put16(&bs, 0x0000); |
| 116 | byte_stream_put16(&bs, frame->flags); | |
| 117 | byte_stream_put16(&bs, 0x0000); | |
| 118 | byte_stream_put16(&bs, 0x0000); | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
119 | byte_stream_putraw(&bs, frame->bn, 32); |
| 13593 | 120 | byte_stream_putraw(&bs, frame->payload.data, frame->payload.len); |
| 121 | ||
| 122 | peer_connection_send(conn, &bs); | |
| 123 | ||
|
22862
24f8ae1208ca
Fixed the final stragglers in need of byte_stream_destroy()
Evan Schoenberg <evands@pidgin.im>
parents:
21389
diff
changeset
|
124 | byte_stream_destroy(&bs); |
| 13593 | 125 | } |
| 126 | ||
| 127 | /** | |
| 128 | * Send a very basic ODC frame (which contains the cookie) so that the | |
| 129 | * remote user can verify that we are the person they were expecting. | |
| 130 | * If we made an outgoing connection to then remote user, then we send | |
| 131 | * this immediately. If the remote user connected to us, then we wait | |
| 132 | * for the other person to send this to us, then we send one to them. | |
| 133 | */ | |
| 134 | void | |
| 135 | peer_odc_send_cookie(PeerConnection *conn) | |
| 136 | { | |
| 137 | OdcFrame frame; | |
| 138 | ||
| 139 | memset(&frame, 0, sizeof(OdcFrame)); | |
| 140 | frame.type = 0x0001; | |
| 141 | frame.subtype = 0x0006; | |
| 142 | frame.flags = 0x0060; /* Maybe this means "we're sending the cookie"? */ | |
| 143 | ||
| 144 | peer_odc_send(conn, &frame); | |
| 145 | } | |
| 146 | ||
| 147 | /** | |
| 148 | * Send client-to-client typing notification over an established direct connection. | |
| 149 | */ | |
| 150 | void | |
| 15884 | 151 | peer_odc_send_typing(PeerConnection *conn, PurpleTypingState typing) |
| 13593 | 152 | { |
| 153 | OdcFrame frame; | |
| 154 | ||
| 155 | memset(&frame, 0, sizeof(OdcFrame)); | |
| 156 | frame.type = 0x0001; | |
| 157 | frame.subtype = 0x0006; | |
| 15884 | 158 | if (typing == PURPLE_TYPING) |
| 13593 | 159 | frame.flags = 0x0002 | 0x0008; |
| 15884 | 160 | else if (typing == PURPLE_TYPED) |
| 13593 | 161 | frame.flags = 0x0002 | 0x0004; |
| 162 | else | |
| 163 | frame.flags = 0x0002; | |
| 164 | ||
| 165 | peer_odc_send(conn, &frame); | |
| 166 | } | |
| 167 | ||
| 168 | /** | |
| 169 | * Send client-to-client IM over an established direct connection. | |
| 170 | * To send a direct IM, call this just like you would aim_send_im. | |
| 171 | * | |
| 172 | * @param conn The already-connected ODC connection. | |
| 173 | * @param msg Null-terminated string to send. | |
| 174 | * @param len The length of the message to send, including binary data. | |
| 175 | * @param encoding See the AIM_CHARSET_* defines in oscar.h | |
| 176 | * @param autoreply TRUE if this is any auto-reply. | |
| 177 | */ | |
| 178 | void | |
| 179 | peer_odc_send_im(PeerConnection *conn, const char *msg, int len, int encoding, gboolean autoreply) | |
| 180 | { | |
| 181 | OdcFrame frame; | |
| 182 | ||
| 183 | g_return_if_fail(msg != NULL); | |
| 184 | g_return_if_fail(len > 0); | |
| 185 | ||
| 186 | memset(&frame, 0, sizeof(OdcFrame)); | |
| 187 | frame.type = 0x0001; | |
| 188 | frame.subtype = 0x0006; | |
| 189 | frame.payload.len = len; | |
| 190 | frame.encoding = encoding; | |
| 191 | frame.flags = autoreply; | |
|
15151
bb985812fefa
[gaim-migrate @ 17875]
Mark Doliner <markdoliner@pidgin.im>
parents:
14464
diff
changeset
|
192 | byte_stream_new(&frame.payload, len); |
| 13593 | 193 | byte_stream_putraw(&frame.payload, (guint8 *)msg, len); |
| 194 | ||
| 195 | peer_odc_send(conn, &frame); | |
| 196 | ||
| 197 | g_free(frame.payload.data); | |
| 198 | } | |
| 199 | ||
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
200 | struct embedded_data |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
201 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
202 | size_t size; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
203 | const guint8 *data; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
204 | }; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
205 | |
| 13593 | 206 | /** |
| 207 | * This is called after a direct IM has been received in its entirety. This | |
| 208 | * function is passed a long chunk of data which contains the IM with any | |
| 209 | * data chunks (images) appended to it. | |
| 210 | * | |
| 211 | * This function rips out all the data chunks and creates an imgstore for | |
| 212 | * each one. In order to do this, it first goes through the IM and takes | |
| 213 | * out all the IMG tags. When doing so, it rewrites the original IMG tag | |
| 15884 | 214 | * with one compatible with the imgstore Purple core code. For each one, we |
| 13593 | 215 | * then read in chunks of data from the end of the message and actually |
| 216 | * create the img store using the given data. | |
| 217 | * | |
| 218 | * For somewhat easy reference, here's a sample message | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
219 | * (with added whitespace): |
| 13593 | 220 | * |
| 221 | * <HTML><BODY BGCOLOR="#ffffff"> | |
| 222 | * <FONT LANG="0"> | |
| 223 | * This is a really stupid picture:<BR> | |
| 224 | * <IMG SRC="Sample.jpg" ID="1" WIDTH="283" HEIGHT="212" DATASIZE="9894"><BR> | |
| 225 | * Yeah it is<BR> | |
| 226 | * Here is another one:<BR> | |
| 227 | * <IMG SRC="Soap Bubbles.bmp" ID="2" WIDTH="256" HEIGHT="256" DATASIZE="65978"> | |
| 228 | * </FONT> | |
| 229 | * </BODY></HTML> | |
| 230 | * <BINARY> | |
| 231 | * <DATA ID="1" SIZE="9894">datadatadatadata</DATA> | |
| 232 | * <DATA ID="2" SIZE="65978">datadatadatadata</DATA> | |
| 233 | * </BINARY> | |
| 234 | */ | |
| 235 | static void | |
| 236 | peer_odc_handle_payload(PeerConnection *conn, const char *msg, size_t len, int encoding, gboolean autoreply) | |
| 237 | { | |
| 15884 | 238 | PurpleConnection *gc; |
| 239 | PurpleAccount *account; | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
240 | const char *msgend, *binary_start, *dataend; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
241 | const char *tmp, *start, *end, *idstr, *src, *sizestr; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
242 | GData *attributes; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
243 | GHashTable *embedded_datas; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
244 | struct embedded_data *embedded_data; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
245 | GSList *images; |
| 13593 | 246 | gchar *utf8; |
| 247 | GString *newmsg; | |
| 15884 | 248 | PurpleMessageFlags imflags; |
| 13593 | 249 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
250 | gc = conn->od->gc; |
| 15884 | 251 | account = purple_connection_get_account(gc); |
| 13593 | 252 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
253 | dataend = msg + len; |
| 13593 | 254 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
255 | /* |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
256 | * Create a hash table containing references to each embedded |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
257 | * data chunk. The key is the "ID" and the value is an |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
258 | * embedded_data struct. |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
259 | */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
260 | embedded_datas = g_hash_table_new_full(g_direct_hash, |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
261 | g_direct_equal, NULL, g_free); |
| 13593 | 262 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
263 | /* |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
264 | * Create an index of any binary chunks. If we run into any |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
265 | * problems while parsing the binary data section then we stop |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
266 | * parsing it, and the local user will see broken image icons. |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
267 | */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
268 | /* TODO: Use a length argument when looking for the <binary> tag! */ |
| 15884 | 269 | binary_start = purple_strcasestr(msg, "<binary>"); |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
270 | if (binary_start == NULL) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
271 | msgend = dataend; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
272 | else |
| 13593 | 273 | { |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
274 | msgend = binary_start; |
| 13593 | 275 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
276 | /* Move our pointer to immediately after the <binary> tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
277 | tmp = binary_start + 8; |
| 13593 | 278 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
279 | /* The embedded binary markup has a mimimum length of 29 bytes */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
280 | /* TODO: Use a length argument when looking for the <data> tag! */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
281 | while ((tmp + 29 <= dataend) && |
| 15884 | 282 | purple_markup_find_tag("data", tmp, &start, &tmp, &attributes)) |
| 13593 | 283 | { |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
284 | unsigned int id; |
| 13593 | 285 | size_t size; |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
286 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
287 | /* Move the binary pointer from ">" to the start of the data */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
288 | tmp++; |
| 13593 | 289 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
290 | /* Get the ID */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
291 | idstr = g_datalist_get_data(&attributes, "id"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
292 | if (idstr == NULL) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
293 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
294 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
295 | break; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
296 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
297 | id = atoi(idstr); |
| 13593 | 298 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
299 | /* Get the size */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
300 | sizestr = g_datalist_get_data(&attributes, "size"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
301 | if (sizestr == NULL) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
302 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
303 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
304 | break; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
305 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
306 | size = atol(sizestr); |
| 13593 | 307 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
308 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
309 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
310 | if ((size > 0) && (tmp + size > dataend)) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
311 | break; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
312 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
313 | embedded_data = g_new(struct embedded_data, 1); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
314 | embedded_data->size = size; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
315 | embedded_data->data = (const guint8 *)tmp; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
316 | tmp += size; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
317 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
318 | /* Skip past the closing </data> tag */ |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
17539
diff
changeset
|
319 | if (g_ascii_strncasecmp(tmp, "</data>", 7)) |
|
13600
4f436279a21c
[gaim-migrate @ 15985]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
320 | { |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
321 | g_free(embedded_data); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
322 | break; |
|
13600
4f436279a21c
[gaim-migrate @ 15985]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
323 | } |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
324 | tmp += 7; |
| 13593 | 325 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
326 | g_hash_table_insert(embedded_datas, |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
327 | GINT_TO_POINTER(id), embedded_data); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
328 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
329 | } |
| 13593 | 330 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
331 | /* |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
332 | * Loop through the message, replacing OSCAR img tags with the |
| 15884 | 333 | * equivalent Purple img tag. |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
334 | */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
335 | images = NULL; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
336 | newmsg = g_string_new(""); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
337 | tmp = msg; |
| 15884 | 338 | while (purple_markup_find_tag("img", tmp, &start, &end, &attributes)) |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
339 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
340 | int imgid = 0; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
341 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
342 | idstr = g_datalist_get_data(&attributes, "id"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
343 | src = g_datalist_get_data(&attributes, "src"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
344 | sizestr = g_datalist_get_data(&attributes, "datasize"); |
| 13593 | 345 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
346 | if ((idstr != NULL) && (src != NULL) && (sizestr!= NULL)) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
347 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
348 | unsigned int id; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
349 | size_t size; |
| 13593 | 350 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
351 | id = atoi(idstr); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
352 | size = atol(sizestr); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
353 | embedded_data = g_hash_table_lookup(embedded_datas, |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
354 | GINT_TO_POINTER(id)); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
355 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
356 | if ((embedded_data != NULL) && (embedded_data->size == size)) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
357 | { |
|
16539
75a20ae3a527
Change the imgstore and by extension, then the buddy icon code to take over
Richard Laager <rlaager@pidgin.im>
parents:
16437
diff
changeset
|
358 | imgid = purple_imgstore_add_with_id(g_memdup(embedded_data->data, size), size, src); |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
359 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
360 | /* Record the image number */ |
| 13593 | 361 | images = g_slist_append(images, GINT_TO_POINTER(imgid)); |
| 362 | } | |
| 363 | } | |
| 364 | ||
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
365 | /* Delete the attribute list */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
366 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
367 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
368 | /* Append the message up to the tag */ |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
369 | utf8 = purple_plugin_oscar_decode_im_part(account, conn->bn, |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
370 | encoding, 0x0000, tmp, start - tmp); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
371 | if (utf8 != NULL) { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
372 | g_string_append(newmsg, utf8); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
373 | g_free(utf8); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
374 | } |
| 13593 | 375 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
376 | if (imgid != 0) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
377 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
378 | /* Write the new image tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
379 | g_string_append_printf(newmsg, "<IMG ID=\"%d\">", imgid); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
380 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
381 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
382 | /* Continue from the end of the tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
383 | tmp = end + 1; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
384 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
385 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
386 | /* Append any remaining message data */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
387 | if (tmp <= msgend) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
388 | { |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
389 | utf8 = purple_plugin_oscar_decode_im_part(account, conn->bn, |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
390 | encoding, 0x0000, tmp, msgend - tmp); |
| 13593 | 391 | if (utf8 != NULL) { |
| 392 | g_string_append(newmsg, utf8); | |
| 393 | g_free(utf8); | |
| 394 | } | |
| 395 | } | |
| 396 | ||
|
25426
71bd2a5b4eab
Fixed an errant comment
Evan Schoenberg <evands@pidgin.im>
parents:
25296
diff
changeset
|
397 | /* Display the message we received */ |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
398 | imflags = 0; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
399 | if (images != NULL) |
| 15884 | 400 | imflags |= PURPLE_MESSAGE_IMAGES; |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
401 | if (autoreply) |
| 15884 | 402 | imflags |= PURPLE_MESSAGE_AUTO_RESP; |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
403 | serv_got_im(gc, conn->bn, newmsg->str, imflags, time(NULL)); |
| 13593 | 404 | g_string_free(newmsg, TRUE); |
| 405 | ||
| 406 | /* unref any images we allocated */ | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
407 | if (images) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
408 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
409 | GSList *l; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
410 | for (l = images; l != NULL; l = l->next) |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
411 | purple_imgstore_unref_by_id(GPOINTER_TO_INT(l->data)); |
| 13593 | 412 | g_slist_free(images); |
| 413 | } | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
414 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
415 | /* Delete our list of pointers to embedded images */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
416 | g_hash_table_destroy(embedded_datas); |
| 13593 | 417 | } |
| 418 | ||
| 419 | /** | |
| 15884 | 420 | * This is a purple_input_add() watcher callback function for reading |
| 13593 | 421 | * direct IM payload data. "Payload data" is always an IM and |
| 422 | * maybe some embedded images or files or something. The actual | |
| 423 | * ODC frame is read using peer_connection_recv_cb(). We temporarily | |
| 424 | * switch to this watcher callback ONLY to read the payload, and we | |
| 425 | * switch back once we're done. | |
| 426 | */ | |
| 427 | static void | |
| 15884 | 428 | peer_odc_recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
| 13593 | 429 | { |
| 430 | PeerConnection *conn; | |
| 431 | OdcFrame *frame; | |
| 432 | ByteStream *bs; | |
|
23079
b887906eed60
More s/ssize_t/gssize/
Daniel Atallah <datallah@pidgin.im>
parents:
22862
diff
changeset
|
433 | gssize read; |
| 13593 | 434 | |
| 435 | conn = data; | |
| 436 | frame = conn->frame; | |
| 437 | bs = &frame->payload; | |
| 438 | ||
| 439 | /* Read data into the temporary buffer until it is complete */ | |
| 440 | read = recv(conn->fd, | |
| 441 | &bs->data[bs->offset], | |
| 442 | bs->len - bs->offset, | |
| 443 | 0); | |
| 444 | ||
| 445 | /* Check if the remote user closed the connection */ | |
| 446 | if (read == 0) | |
| 447 | { | |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
448 | peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
| 13593 | 449 | return; |
| 450 | } | |
| 451 | ||
|
17539
0fd875385856
Only check for EAGAIN if send returns -1, not when it returns 0
Mark Doliner <markdoliner@pidgin.im>
parents:
16539
diff
changeset
|
452 | if (read < 0) |
| 13593 | 453 | { |
| 454 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | |
| 455 | /* No worries */ | |
| 456 | return; | |
| 457 | ||
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
458 | peer_connection_destroy(conn, |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
20192
diff
changeset
|
459 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 460 | return; |
| 461 | } | |
| 462 | ||
| 463 | bs->offset += read; | |
| 464 | if (bs->offset < bs->len) | |
| 465 | /* Waiting for more data to arrive */ | |
| 466 | return; | |
| 467 | ||
| 468 | /* We have a complete ODC/OFT frame! Handle it and continue reading */ | |
| 469 | byte_stream_rewind(bs); | |
| 470 | peer_odc_handle_payload(conn, (const char *)bs->data, | |
| 471 | bs->len, frame->encoding, frame->flags & 0x0001); | |
| 472 | g_free(bs->data); | |
| 473 | bs->data = NULL; | |
| 474 | g_free(frame); | |
| 475 | conn->frame = NULL; | |
| 476 | ||
| 15884 | 477 | purple_input_remove(conn->watcher_incoming); |
| 478 | conn->watcher_incoming = purple_input_add(conn->fd, | |
| 479 | PURPLE_INPUT_READ, peer_connection_recv_cb, conn); | |
| 13593 | 480 | } |
| 481 | ||
| 482 | /** | |
| 483 | * Handle an incoming OdcFrame. If there is a payload associated | |
| 484 | * with this frame, then we remove the old watcher and add the | |
| 485 | * ODC watcher to read in the payload. | |
| 486 | */ | |
| 487 | void | |
| 488 | peer_odc_recv_frame(PeerConnection *conn, ByteStream *bs) | |
| 489 | { | |
| 15884 | 490 | PurpleConnection *gc; |
| 13593 | 491 | OdcFrame *frame; |
| 492 | ||
| 493 | gc = conn->od->gc; | |
| 494 | ||
| 495 | frame = g_new0(OdcFrame, 1); | |
| 496 | frame->type = byte_stream_get16(bs); | |
| 497 | frame->subtype = byte_stream_get16(bs); | |
| 498 | byte_stream_advance(bs, 2); | |
| 499 | byte_stream_getrawbuf(bs, frame->cookie, 8); | |
| 500 | byte_stream_advance(bs, 8); | |
| 501 | frame->payload.len = byte_stream_get32(bs); | |
| 502 | frame->encoding = byte_stream_get16(bs); | |
| 503 | byte_stream_advance(bs, 4); | |
| 504 | frame->flags = byte_stream_get16(bs); | |
| 505 | byte_stream_advance(bs, 4); | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
506 | byte_stream_getrawbuf(bs, frame->bn, 32); |
| 13593 | 507 | |
| 15884 | 508 | purple_debug_info("oscar", "Incoming ODC frame from %s with " |
| 13593 | 509 | "type=0x%04x, flags=0x%04x, payload length=%u\n", |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
510 | frame->bn, frame->type, frame->flags, frame->payload.len); |
| 13593 | 511 | |
| 512 | if (!conn->ready) | |
| 513 | { | |
| 514 | /* | |
| 515 | * We need to verify the cookie so that we know we are | |
| 516 | * connected to our friend and not a malicious middle man. | |
| 517 | */ | |
| 518 | ||
| 15884 | 519 | PurpleAccount *account; |
| 520 | PurpleConversation *conv; | |
| 13593 | 521 | |
| 522 | if (conn->flags & PEER_CONNECTION_FLAG_IS_INCOMING) | |
| 523 | { | |
| 524 | if (memcmp(conn->cookie, frame->cookie, 8)) | |
| 525 | { | |
| 526 | /* | |
| 527 | * Oh no! The user that connected to us did not send | |
| 528 | * the correct cookie! They are not our friend. Go try | |
| 529 | * to accept another connection? | |
| 530 | */ | |
| 15884 | 531 | purple_debug_info("oscar", "Received an incorrect cookie. " |
| 13593 | 532 | "Closing connection.\n"); |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
533 | peer_connection_destroy(conn, |
|
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
534 | OSCAR_DISCONNECT_INVALID_DATA, NULL); |
| 13593 | 535 | g_free(frame); |
| 536 | return; | |
| 537 | } | |
| 538 | ||
| 539 | /* | |
| 540 | * Ok, we know they are legit. Now be courteous and | |
| 541 | * send them our cookie. Note: This doesn't seem | |
| 542 | * to be necessary, but it also doesn't seem to hurt. | |
| 543 | */ | |
| 544 | peer_odc_send_cookie(conn); | |
| 545 | } | |
| 546 | ||
| 547 | conn->ready = TRUE; | |
| 548 | ||
| 549 | /* | |
| 550 | * If they connected to us then close the listener socket | |
| 551 | * and send them our cookie. | |
| 552 | */ | |
| 553 | if (conn->listenerfd != -1) | |
| 554 | { | |
| 555 | close(conn->listenerfd); | |
| 556 | conn->listenerfd = -1; | |
| 557 | } | |
| 558 | ||
| 559 | /* Tell the local user that we are connected */ | |
| 15884 | 560 | account = purple_connection_get_account(gc); |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
561 | conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, conn->bn); |
| 15884 | 562 | purple_conversation_write(conv, NULL, _("Direct IM established"), |
| 563 | PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
| 13593 | 564 | } |
| 565 | ||
| 566 | if ((frame->type != 0x0001) && (frame->subtype != 0x0006)) | |
| 567 | { | |
| 15884 | 568 | purple_debug_info("oscar", "Unknown ODC frame type 0x%04hx, " |
| 13593 | 569 | "subtype 0x%04hx.\n", frame->type, frame->subtype); |
|
25296
0450df777754
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7857.
Daniel Atallah <datallah@pidgin.im>
parents:
23079
diff
changeset
|
570 | g_free(frame); |
| 13593 | 571 | return; |
| 572 | } | |
| 573 | ||
| 574 | if (frame->flags & 0x0008) | |
| 575 | { | |
| 576 | /* I had to leave this. It's just too funny. It reminds me of my sister. */ | |
| 15884 | 577 | purple_debug_info("oscar", "ohmigod! %s has started typing " |
| 13593 | 578 | "(DirectIM). He's going to send you a message! " |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
579 | "*squeal*\n", conn->bn); |
|
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
580 | serv_got_typing(gc, conn->bn, 0, PURPLE_TYPING); |
| 13593 | 581 | } |
| 582 | else if (frame->flags & 0x0004) | |
| 583 | { | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
584 | serv_got_typing(gc, conn->bn, 0, PURPLE_TYPED); |
| 13593 | 585 | } |
| 586 | else | |
| 587 | { | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
588 | serv_got_typing_stopped(gc, conn->bn); |
| 13593 | 589 | } |
| 590 | ||
| 591 | if (frame->payload.len > 0) | |
| 592 | { | |
|
20192
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
593 | if (frame->payload.len > DIRECTIM_MAX_FILESIZE) |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
594 | { |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
595 | gchar *tmp, *size1, *size2; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
596 | PurpleAccount *account; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
597 | PurpleConversation *conv; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
598 | |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
599 | size1 = purple_str_size_to_units(frame->payload.len); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
600 | size2 = purple_str_size_to_units(DIRECTIM_MAX_FILESIZE); |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
601 | tmp = g_strdup_printf(_("%s tried to send you a %s file, but we only allow files up to %s over Direct IM. Try using file transfer instead.\n"), conn->bn, size1, size2); |
|
20192
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
602 | g_free(size1); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
603 | g_free(size2); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
604 | |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
605 | account = purple_connection_get_account(conn->od->gc); |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
606 | conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, conn->bn); |
|
20192
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
607 | purple_conversation_write(conv, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL)); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
608 | g_free(tmp); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
609 | |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
610 | peer_connection_destroy(conn, OSCAR_DISCONNECT_LOCAL_CLOSED, NULL); |
|
25296
0450df777754
Fix a leak "KuSh" discovered using "cppcheck". Fixes #7857.
Daniel Atallah <datallah@pidgin.im>
parents:
23079
diff
changeset
|
611 | g_free(frame); |
|
20192
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
612 | return; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
613 | } |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
614 | |
| 13593 | 615 | /* We have payload data! Switch to the ODC watcher to read it. */ |
| 616 | frame->payload.data = g_new(guint8, frame->payload.len); | |
| 617 | frame->payload.offset = 0; | |
| 618 | conn->frame = frame; | |
| 15884 | 619 | purple_input_remove(conn->watcher_incoming); |
| 620 | conn->watcher_incoming = purple_input_add(conn->fd, | |
| 621 | PURPLE_INPUT_READ, peer_odc_recv_cb, conn); | |
| 13593 | 622 | return; |
| 623 | } | |
| 624 | ||
| 625 | g_free(frame); | |
| 626 | } |