Fri, 15 Jun 2012 00:59:46 -0400
From now on, prpls must specify images using SRC instead of ID.
This only fixes libpurple, the UI side doesn't follow this change
just yet.
| 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 | { |
|
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
|
359 | 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
|
360 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
361 | /* Record the image number */ |
| 13593 | 362 | images = g_slist_append(images, GINT_TO_POINTER(imgid)); |
| 363 | } | |
| 364 | } | |
| 365 | ||
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
366 | /* Delete the attribute list */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
367 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
368 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
369 | /* 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
|
370 | 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
|
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 */ |
|
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
|
379 | 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
|
380 | "<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
|
381 | imgid); |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
382 | } |
|
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 | /* Continue from the end of the tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
385 | tmp = end + 1; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
386 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
387 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
388 | /* Append any remaining message data */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
389 | if (tmp <= msgend) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
390 | { |
|
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
|
391 | utf8 = oscar_decode_im(account, conn->bn, encoding, tmp, msgend - tmp); |
| 13593 | 392 | if (utf8 != NULL) { |
| 393 | g_string_append(newmsg, utf8); | |
| 394 | g_free(utf8); | |
| 395 | } | |
| 396 | } | |
| 397 | ||
|
25426
71bd2a5b4eab
Fixed an errant comment
Evan Schoenberg <evands@pidgin.im>
parents:
25296
diff
changeset
|
398 | /* Display the message we received */ |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
399 | imflags = 0; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
400 | if (images != NULL) |
| 15884 | 401 | imflags |= PURPLE_MESSAGE_IMAGES; |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
402 | if (autoreply) |
| 15884 | 403 | 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
|
404 | serv_got_im(gc, conn->bn, newmsg->str, imflags, time(NULL)); |
| 13593 | 405 | g_string_free(newmsg, TRUE); |
| 406 | ||
| 407 | /* unref any images we allocated */ | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
408 | if (images) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
409 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
410 | GSList *l; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
411 | 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
|
412 | purple_imgstore_unref_by_id(GPOINTER_TO_INT(l->data)); |
| 13593 | 413 | g_slist_free(images); |
| 414 | } | |
|
13601
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 | /* Delete our list of pointers to embedded images */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
417 | g_hash_table_destroy(embedded_datas); |
| 13593 | 418 | } |
| 419 | ||
| 420 | /** | |
| 15884 | 421 | * This is a purple_input_add() watcher callback function for reading |
| 13593 | 422 | * direct IM payload data. "Payload data" is always an IM and |
| 423 | * maybe some embedded images or files or something. The actual | |
| 424 | * ODC frame is read using peer_connection_recv_cb(). We temporarily | |
| 425 | * switch to this watcher callback ONLY to read the payload, and we | |
| 426 | * switch back once we're done. | |
| 427 | */ | |
| 428 | static void | |
| 15884 | 429 | peer_odc_recv_cb(gpointer data, gint source, PurpleInputCondition cond) |
| 13593 | 430 | { |
| 431 | PeerConnection *conn; | |
| 432 | OdcFrame *frame; | |
| 433 | ByteStream *bs; | |
|
23079
b887906eed60
More s/ssize_t/gssize/
Daniel Atallah <datallah@pidgin.im>
parents:
22862
diff
changeset
|
434 | gssize read; |
| 13593 | 435 | |
| 436 | conn = data; | |
| 437 | frame = conn->frame; | |
| 438 | bs = &frame->payload; | |
| 439 | ||
| 440 | /* Read data into the temporary buffer until it is complete */ | |
| 441 | read = recv(conn->fd, | |
| 442 | &bs->data[bs->offset], | |
| 443 | bs->len - bs->offset, | |
| 444 | 0); | |
| 445 | ||
| 446 | /* Check if the remote user closed the connection */ | |
| 447 | if (read == 0) | |
| 448 | { | |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
449 | peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED, NULL); |
| 13593 | 450 | return; |
| 451 | } | |
| 452 | ||
|
17539
0fd875385856
Only check for EAGAIN if send returns -1, not when it returns 0
Mark Doliner <markdoliner@pidgin.im>
parents:
16539
diff
changeset
|
453 | if (read < 0) |
| 13593 | 454 | { |
| 455 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | |
| 456 | /* No worries */ | |
| 457 | return; | |
| 458 | ||
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
459 | 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
|
460 | OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); |
| 13593 | 461 | return; |
| 462 | } | |
| 463 | ||
| 464 | bs->offset += read; | |
| 465 | if (bs->offset < bs->len) | |
| 466 | /* Waiting for more data to arrive */ | |
| 467 | return; | |
| 468 | ||
| 469 | /* We have a complete ODC/OFT frame! Handle it and continue reading */ | |
| 470 | byte_stream_rewind(bs); | |
| 471 | peer_odc_handle_payload(conn, (const char *)bs->data, | |
| 472 | bs->len, frame->encoding, frame->flags & 0x0001); | |
| 473 | g_free(bs->data); | |
| 474 | bs->data = NULL; | |
| 475 | g_free(frame); | |
| 476 | conn->frame = NULL; | |
| 477 | ||
| 15884 | 478 | purple_input_remove(conn->watcher_incoming); |
| 479 | conn->watcher_incoming = purple_input_add(conn->fd, | |
| 480 | PURPLE_INPUT_READ, peer_connection_recv_cb, conn); | |
| 13593 | 481 | } |
| 482 | ||
| 483 | /** | |
| 484 | * Handle an incoming OdcFrame. If there is a payload associated | |
| 485 | * with this frame, then we remove the old watcher and add the | |
| 486 | * ODC watcher to read in the payload. | |
| 487 | */ | |
| 488 | void | |
| 489 | peer_odc_recv_frame(PeerConnection *conn, ByteStream *bs) | |
| 490 | { | |
| 15884 | 491 | PurpleConnection *gc; |
| 13593 | 492 | OdcFrame *frame; |
| 493 | ||
| 494 | gc = conn->od->gc; | |
| 495 | ||
| 496 | frame = g_new0(OdcFrame, 1); | |
| 497 | frame->type = byte_stream_get16(bs); | |
| 498 | frame->subtype = byte_stream_get16(bs); | |
| 499 | byte_stream_advance(bs, 2); | |
| 500 | byte_stream_getrawbuf(bs, frame->cookie, 8); | |
| 501 | byte_stream_advance(bs, 8); | |
| 502 | frame->payload.len = byte_stream_get32(bs); | |
| 503 | frame->encoding = byte_stream_get16(bs); | |
| 504 | byte_stream_advance(bs, 4); | |
| 505 | frame->flags = byte_stream_get16(bs); | |
| 506 | 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
|
507 | byte_stream_getrawbuf(bs, frame->bn, 32); |
| 13593 | 508 | |
| 15884 | 509 | 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
|
510 | "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
|
511 | frame->bn, frame->type, frame->flags, frame->payload.len); |
| 13593 | 512 | |
| 513 | if (!conn->ready) | |
| 514 | { | |
| 515 | /* | |
| 516 | * We need to verify the cookie so that we know we are | |
| 517 | * connected to our friend and not a malicious middle man. | |
| 518 | */ | |
| 519 | ||
| 15884 | 520 | PurpleAccount *account; |
| 521 | PurpleConversation *conv; | |
| 13593 | 522 | |
| 523 | if (conn->flags & PEER_CONNECTION_FLAG_IS_INCOMING) | |
| 524 | { | |
| 525 | if (memcmp(conn->cookie, frame->cookie, 8)) | |
| 526 | { | |
| 527 | /* | |
| 528 | * Oh no! The user that connected to us did not send | |
| 529 | * the correct cookie! They are not our friend. Go try | |
| 530 | * to accept another connection? | |
| 531 | */ | |
| 15884 | 532 | purple_debug_info("oscar", "Received an incorrect cookie. " |
| 13593 | 533 | "Closing connection.\n"); |
|
14464
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
534 | peer_connection_destroy(conn, |
|
b7bca43f75b3
[gaim-migrate @ 17110]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
535 | OSCAR_DISCONNECT_INVALID_DATA, NULL); |
| 13593 | 536 | g_free(frame); |
| 537 | return; | |
| 538 | } | |
| 539 | ||
| 540 | /* | |
| 541 | * Ok, we know they are legit. Now be courteous and | |
| 542 | * send them our cookie. Note: This doesn't seem | |
| 543 | * to be necessary, but it also doesn't seem to hurt. | |
| 544 | */ | |
| 545 | peer_odc_send_cookie(conn); | |
| 546 | } | |
| 547 | ||
| 548 | conn->ready = TRUE; | |
| 549 | ||
| 550 | /* | |
| 551 | * If they connected to us then close the listener socket | |
| 552 | * and send them our cookie. | |
| 553 | */ | |
| 554 | if (conn->listenerfd != -1) | |
| 555 | { | |
| 556 | close(conn->listenerfd); | |
| 557 | conn->listenerfd = -1; | |
| 558 | } | |
| 559 | ||
| 560 | /* Tell the local user that we are connected */ | |
| 15884 | 561 | 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
|
562 | conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, conn->bn); |
| 15884 | 563 | purple_conversation_write(conv, NULL, _("Direct IM established"), |
| 564 | PURPLE_MESSAGE_SYSTEM, time(NULL)); | |
| 13593 | 565 | } |
| 566 | ||
| 567 | if ((frame->type != 0x0001) && (frame->subtype != 0x0006)) | |
| 568 | { | |
| 15884 | 569 | purple_debug_info("oscar", "Unknown ODC frame type 0x%04hx, " |
| 13593 | 570 | "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
|
571 | g_free(frame); |
| 13593 | 572 | return; |
| 573 | } | |
| 574 | ||
| 575 | if (frame->flags & 0x0008) | |
| 576 | { | |
| 577 | /* I had to leave this. It's just too funny. It reminds me of my sister. */ | |
| 15884 | 578 | purple_debug_info("oscar", "ohmigod! %s has started typing " |
| 13593 | 579 | "(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
|
580 | "*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
|
581 | serv_got_typing(gc, conn->bn, 0, PURPLE_TYPING); |
| 13593 | 582 | } |
| 583 | else if (frame->flags & 0x0004) | |
| 584 | { | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
585 | serv_got_typing(gc, conn->bn, 0, PURPLE_TYPED); |
| 13593 | 586 | } |
| 587 | else | |
| 588 | { | |
|
25889
26d9ca30335c
Change "screen name" to "username" or "buddy name" in a whole bunch of
Mark Doliner <markdoliner@pidgin.im>
parents:
25426
diff
changeset
|
589 | serv_got_typing_stopped(gc, conn->bn); |
| 13593 | 590 | } |
| 591 | ||
| 592 | if (frame->payload.len > 0) | |
| 593 | { | |
|
20192
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
594 | if (frame->payload.len > DIRECTIM_MAX_FILESIZE) |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
595 | { |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
596 | gchar *tmp, *size1, *size2; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
597 | PurpleAccount *account; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
598 | PurpleConversation *conv; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
599 | |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
600 | size1 = purple_str_size_to_units(frame->payload.len); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
601 | 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
|
602 | 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
|
603 | g_free(size1); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
604 | g_free(size2); |
|
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 | 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
|
607 | 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
|
608 | 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
|
609 | g_free(tmp); |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
610 | |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
611 | 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
|
612 | g_free(frame); |
|
20192
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
613 | return; |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
614 | } |
|
162883eb3251
applied changes from 2ab75e32c52e94c674d0b5a396d224da7e9d509e
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
615 | |
| 13593 | 616 | /* We have payload data! Switch to the ODC watcher to read it. */ |
| 617 | frame->payload.data = g_new(guint8, frame->payload.len); | |
| 618 | frame->payload.offset = 0; | |
| 619 | conn->frame = frame; | |
| 15884 | 620 | purple_input_remove(conn->watcher_incoming); |
| 621 | conn->watcher_incoming = purple_input_add(conn->fd, | |
| 622 | PURPLE_INPUT_READ, peer_odc_recv_cb, conn); | |
| 13593 | 623 | return; |
| 624 | } | |
| 625 | ||
| 626 | g_free(frame); | |
| 627 | } |