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