Sat, 19 Aug 2006 01:50:10 +0000
[gaim-migrate @ 16863]
Renamed 'core' to 'libgaim'
| 13593 | 1 | /* |
| 2 | * Gaim's oscar protocol plugin | |
| 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 | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | */ | |
| 20 | ||
| 21 | /* From the oscar PRPL */ | |
| 22 | #include "oscar.h" | |
| 23 | #include "peer.h" | |
| 24 | ||
| 25 | /* From Gaim */ | |
| 26 | #include "conversation.h" | |
| 27 | #include "imgstore.h" | |
| 28 | #include "util.h" | |
| 29 | ||
| 30 | /** | |
| 31 | * Free any ODC related data and print a message to the conversation | |
| 32 | * window based on conn->disconnect_reason. | |
| 33 | */ | |
| 34 | void | |
| 35 | peer_odc_close(PeerConnection *conn) | |
| 36 | { | |
| 37 | const gchar *tmp; | |
| 38 | ||
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
39 | if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED) |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
40 | tmp = _("The remote user has closed the connection."); |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
41 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_REFUSED) |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
42 | tmp = _("The remote user has declined your request."); |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
43 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION) |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
44 | tmp = _("Lost connection with the remote user for an unknown reason."); |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
45 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA) |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
46 | tmp = _("Received invalid data on connection with remote user."); |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
47 | else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT) |
|
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
48 | tmp = _("Could not establish a connection with the remote user."); |
| 13593 | 49 | else |
| 50 | /* | |
| 51 | * We shouldn't print a message for some disconnect_reasons. | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
52 | * Like OSCAR_DISCONNECT_LOCAL_CLOSED. |
| 13593 | 53 | */ |
| 54 | tmp = NULL; | |
| 55 | ||
| 56 | if (tmp != NULL) | |
| 57 | { | |
| 58 | GaimAccount *account; | |
| 59 | GaimConversation *conv; | |
| 60 | ||
| 61 | account = gaim_connection_get_account(conn->od->gc); | |
| 62 | conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, conn->sn); | |
| 63 | gaim_conversation_write(conv, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 64 | } | |
| 65 | ||
| 66 | if (conn->frame != NULL) | |
| 67 | { | |
| 68 | OdcFrame *frame; | |
| 69 | frame = conn->frame; | |
| 70 | g_free(frame->payload.data); | |
| 71 | g_free(frame); | |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Write the given OdcFrame to a ByteStream and send it out | |
| 77 | * on the established PeerConnection. | |
| 78 | */ | |
| 79 | static void | |
| 80 | peer_odc_send(PeerConnection *conn, OdcFrame *frame) | |
| 81 | { | |
| 82 | GaimAccount *account; | |
| 83 | const char *username; | |
| 84 | size_t length; | |
| 85 | ByteStream bs; | |
| 86 | ||
| 87 | gaim_debug_info("oscar", "Outgoing ODC frame to %s with " | |
| 88 | "type=0x%04x, flags=0x%04x, payload length=%u\n", | |
| 89 | conn->sn, frame->type, frame->flags, frame->payload.len); | |
| 90 | ||
| 91 | account = gaim_connection_get_account(conn->od->gc); | |
| 92 | username = gaim_account_get_username(account); | |
| 93 | memcpy(frame->sn, username, strlen(username)); | |
| 94 | memcpy(frame->cookie, conn->cookie, 8); | |
| 95 | ||
| 96 | length = 76; | |
| 97 | byte_stream_init(&bs, malloc(length + frame->payload.len), | |
| 98 | length + frame->payload.len); | |
| 99 | byte_stream_putraw(&bs, conn->magic, 4); | |
| 100 | byte_stream_put16(&bs, length); | |
| 101 | byte_stream_put16(&bs, frame->type); | |
| 102 | byte_stream_put16(&bs, frame->subtype); | |
| 103 | byte_stream_put16(&bs, 0x0000); | |
| 104 | byte_stream_putraw(&bs, frame->cookie, 8); | |
| 105 | byte_stream_put16(&bs, 0x0000); | |
| 106 | byte_stream_put16(&bs, 0x0000); | |
| 107 | byte_stream_put16(&bs, 0x0000); | |
| 108 | byte_stream_put16(&bs, 0x0000); | |
| 109 | byte_stream_put32(&bs, frame->payload.len); | |
| 110 | byte_stream_put16(&bs, 0x0000); | |
| 111 | byte_stream_put16(&bs, frame->encoding); | |
| 112 | byte_stream_put16(&bs, 0x0000); | |
| 113 | byte_stream_put16(&bs, frame->flags); | |
| 114 | byte_stream_put16(&bs, 0x0000); | |
| 115 | byte_stream_put16(&bs, 0x0000); | |
| 116 | byte_stream_putraw(&bs, frame->sn, 32); | |
| 117 | byte_stream_putraw(&bs, frame->payload.data, frame->payload.len); | |
| 118 | ||
| 119 | peer_connection_send(conn, &bs); | |
| 120 | ||
| 121 | free(bs.data); | |
| 122 | } | |
| 123 | ||
| 124 | /** | |
| 125 | * Send a very basic ODC frame (which contains the cookie) so that the | |
| 126 | * remote user can verify that we are the person they were expecting. | |
| 127 | * If we made an outgoing connection to then remote user, then we send | |
| 128 | * this immediately. If the remote user connected to us, then we wait | |
| 129 | * for the other person to send this to us, then we send one to them. | |
| 130 | */ | |
| 131 | void | |
| 132 | peer_odc_send_cookie(PeerConnection *conn) | |
| 133 | { | |
| 134 | OdcFrame frame; | |
| 135 | ||
| 136 | memset(&frame, 0, sizeof(OdcFrame)); | |
| 137 | frame.type = 0x0001; | |
| 138 | frame.subtype = 0x0006; | |
| 139 | frame.flags = 0x0060; /* Maybe this means "we're sending the cookie"? */ | |
| 140 | ||
| 141 | peer_odc_send(conn, &frame); | |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * Send client-to-client typing notification over an established direct connection. | |
| 146 | */ | |
| 147 | void | |
| 148 | peer_odc_send_typing(PeerConnection *conn, GaimTypingState typing) | |
| 149 | { | |
| 150 | OdcFrame frame; | |
| 151 | ||
| 152 | memset(&frame, 0, sizeof(OdcFrame)); | |
| 153 | frame.type = 0x0001; | |
| 154 | frame.subtype = 0x0006; | |
| 155 | if (typing == GAIM_TYPING) | |
| 156 | frame.flags = 0x0002 | 0x0008; | |
| 157 | else if (typing == GAIM_TYPED) | |
| 158 | frame.flags = 0x0002 | 0x0004; | |
| 159 | else | |
| 160 | frame.flags = 0x0002; | |
| 161 | ||
| 162 | peer_odc_send(conn, &frame); | |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * Send client-to-client IM over an established direct connection. | |
| 167 | * To send a direct IM, call this just like you would aim_send_im. | |
| 168 | * | |
| 169 | * @param conn The already-connected ODC connection. | |
| 170 | * @param msg Null-terminated string to send. | |
| 171 | * @param len The length of the message to send, including binary data. | |
| 172 | * @param encoding See the AIM_CHARSET_* defines in oscar.h | |
| 173 | * @param autoreply TRUE if this is any auto-reply. | |
| 174 | */ | |
| 175 | void | |
| 176 | peer_odc_send_im(PeerConnection *conn, const char *msg, int len, int encoding, gboolean autoreply) | |
| 177 | { | |
| 178 | OdcFrame frame; | |
| 179 | ||
| 180 | g_return_if_fail(msg != NULL); | |
| 181 | g_return_if_fail(len > 0); | |
| 182 | ||
| 183 | memset(&frame, 0, sizeof(OdcFrame)); | |
| 184 | frame.type = 0x0001; | |
| 185 | frame.subtype = 0x0006; | |
| 186 | frame.payload.len = len; | |
| 187 | frame.encoding = encoding; | |
| 188 | frame.flags = autoreply; | |
| 189 | byte_stream_init(&frame.payload, malloc(len), len); | |
| 190 | byte_stream_putraw(&frame.payload, (guint8 *)msg, len); | |
| 191 | ||
| 192 | peer_odc_send(conn, &frame); | |
| 193 | ||
| 194 | g_free(frame.payload.data); | |
| 195 | } | |
| 196 | ||
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
197 | struct embedded_data |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
198 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
199 | size_t size; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
200 | const guint8 *data; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
201 | }; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
202 | |
| 13593 | 203 | /** |
| 204 | * This is called after a direct IM has been received in its entirety. This | |
| 205 | * function is passed a long chunk of data which contains the IM with any | |
| 206 | * data chunks (images) appended to it. | |
| 207 | * | |
| 208 | * This function rips out all the data chunks and creates an imgstore for | |
| 209 | * each one. In order to do this, it first goes through the IM and takes | |
| 210 | * out all the IMG tags. When doing so, it rewrites the original IMG tag | |
| 211 | * with one compatible with the imgstore Gaim core code. For each one, we | |
| 212 | * then read in chunks of data from the end of the message and actually | |
| 213 | * create the img store using the given data. | |
| 214 | * | |
| 215 | * For somewhat easy reference, here's a sample message | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
216 | * (with added whitespace): |
| 13593 | 217 | * |
| 218 | * <HTML><BODY BGCOLOR="#ffffff"> | |
| 219 | * <FONT LANG="0"> | |
| 220 | * This is a really stupid picture:<BR> | |
| 221 | * <IMG SRC="Sample.jpg" ID="1" WIDTH="283" HEIGHT="212" DATASIZE="9894"><BR> | |
| 222 | * Yeah it is<BR> | |
| 223 | * Here is another one:<BR> | |
| 224 | * <IMG SRC="Soap Bubbles.bmp" ID="2" WIDTH="256" HEIGHT="256" DATASIZE="65978"> | |
| 225 | * </FONT> | |
| 226 | * </BODY></HTML> | |
| 227 | * <BINARY> | |
| 228 | * <DATA ID="1" SIZE="9894">datadatadatadata</DATA> | |
| 229 | * <DATA ID="2" SIZE="65978">datadatadatadata</DATA> | |
| 230 | * </BINARY> | |
| 231 | */ | |
| 232 | static void | |
| 233 | peer_odc_handle_payload(PeerConnection *conn, const char *msg, size_t len, int encoding, gboolean autoreply) | |
| 234 | { | |
| 235 | GaimConnection *gc; | |
| 236 | GaimAccount *account; | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
237 | const char *msgend, *binary_start, *dataend; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
238 | const char *tmp, *start, *end, *idstr, *src, *sizestr; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
239 | GData *attributes; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
240 | GHashTable *embedded_datas; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
241 | struct embedded_data *embedded_data; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
242 | GSList *images; |
| 13593 | 243 | gchar *utf8; |
| 244 | GString *newmsg; | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
245 | GaimMessageFlags imflags; |
| 13593 | 246 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
247 | gc = conn->od->gc; |
| 13593 | 248 | account = gaim_connection_get_account(gc); |
| 249 | ||
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
250 | dataend = msg + len; |
| 13593 | 251 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
252 | /* |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
253 | * Create a hash table containing references to each embedded |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
254 | * 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
|
255 | * embedded_data struct. |
|
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 | embedded_datas = g_hash_table_new_full(g_direct_hash, |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
258 | g_direct_equal, NULL, g_free); |
| 13593 | 259 | |
|
13601
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 | * 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
|
262 | * problems while parsing the binary data section then we stop |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
263 | * parsing it, and the local user will see broken image icons. |
|
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 | /* TODO: Use a length argument when looking for the <binary> tag! */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
266 | binary_start = gaim_strcasestr(msg, "<binary>"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
267 | if (binary_start == NULL) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
268 | msgend = dataend; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
269 | else |
| 13593 | 270 | { |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
271 | msgend = binary_start; |
| 13593 | 272 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
273 | /* Move our pointer to immediately after the <binary> tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
274 | tmp = binary_start + 8; |
| 13593 | 275 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
276 | /* The embedded binary markup has a mimimum length of 29 bytes */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
277 | /* TODO: Use a length argument when looking for the <data> tag! */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
278 | while ((tmp + 29 <= dataend) && |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
279 | gaim_markup_find_tag("data", tmp, &start, &tmp, &attributes)) |
| 13593 | 280 | { |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
281 | unsigned int id; |
| 13593 | 282 | size_t size; |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
283 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
284 | /* Move the binary pointer from ">" to the start of the data */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
285 | tmp++; |
| 13593 | 286 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
287 | /* Get the ID */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
288 | idstr = g_datalist_get_data(&attributes, "id"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
289 | if (idstr == NULL) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
290 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
291 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
292 | break; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
293 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
294 | id = atoi(idstr); |
| 13593 | 295 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
296 | /* Get the size */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
297 | sizestr = g_datalist_get_data(&attributes, "size"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
298 | if (sizestr == NULL) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
299 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
300 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
301 | break; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
302 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
303 | size = atol(sizestr); |
| 13593 | 304 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
305 | g_datalist_clear(&attributes); |
|
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 | if ((size > 0) && (tmp + size > dataend)) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
308 | break; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
309 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
310 | embedded_data = g_new(struct embedded_data, 1); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
311 | embedded_data->size = size; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
312 | embedded_data->data = (const guint8 *)tmp; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
313 | tmp += size; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
314 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
315 | /* Skip past the closing </data> tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
316 | if (strncasecmp(tmp, "</data>", 7)) |
|
13600
4f436279a21c
[gaim-migrate @ 15985]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
317 | { |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
318 | g_free(embedded_data); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
319 | break; |
|
13600
4f436279a21c
[gaim-migrate @ 15985]
Mark Doliner <markdoliner@pidgin.im>
parents:
13593
diff
changeset
|
320 | } |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
321 | tmp += 7; |
| 13593 | 322 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
323 | g_hash_table_insert(embedded_datas, |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
324 | GINT_TO_POINTER(id), embedded_data); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
325 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
326 | } |
| 13593 | 327 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
328 | /* |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
329 | * Loop through the message, replacing OSCAR img tags with the |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
330 | * equivalent Gaim img tag. |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
331 | */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
332 | images = NULL; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
333 | newmsg = g_string_new(""); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
334 | tmp = msg; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
335 | while (gaim_markup_find_tag("img", tmp, &start, &end, &attributes)) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
336 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
337 | int imgid = 0; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
338 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
339 | idstr = g_datalist_get_data(&attributes, "id"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
340 | src = g_datalist_get_data(&attributes, "src"); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
341 | sizestr = g_datalist_get_data(&attributes, "datasize"); |
| 13593 | 342 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
343 | if ((idstr != NULL) && (src != NULL) && (sizestr!= NULL)) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
344 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
345 | unsigned int id; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
346 | size_t size; |
| 13593 | 347 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
348 | id = atoi(idstr); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
349 | size = atol(sizestr); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
350 | embedded_data = g_hash_table_lookup(embedded_datas, |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
351 | GINT_TO_POINTER(id)); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
352 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
353 | if ((embedded_data != NULL) && (embedded_data->size == size)) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
354 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
355 | imgid = gaim_imgstore_add(embedded_data->data, size, src); |
|
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 | /* Record the image number */ |
| 13593 | 358 | images = g_slist_append(images, GINT_TO_POINTER(imgid)); |
| 359 | } | |
| 360 | } | |
| 361 | ||
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
362 | /* Delete the attribute list */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
363 | g_datalist_clear(&attributes); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
364 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
365 | /* Append the message up to the tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
366 | utf8 = gaim_plugin_oscar_decode_im_part(account, conn->sn, |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
367 | encoding, 0x0000, tmp, start - tmp); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
368 | if (utf8 != NULL) { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
369 | g_string_append(newmsg, utf8); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
370 | g_free(utf8); |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
371 | } |
| 13593 | 372 | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
373 | if (imgid != 0) |
|
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 | /* Write the new image tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
376 | g_string_append_printf(newmsg, "<IMG ID=\"%d\">", imgid); |
|
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 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
379 | /* Continue from the end of the tag */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
380 | tmp = end + 1; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
381 | } |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
382 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
383 | /* Append any remaining message data */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
384 | if (tmp <= msgend) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
385 | { |
| 13593 | 386 | utf8 = gaim_plugin_oscar_decode_im_part(account, conn->sn, |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
387 | encoding, 0x0000, tmp, msgend - tmp); |
| 13593 | 388 | if (utf8 != NULL) { |
| 389 | g_string_append(newmsg, utf8); | |
| 390 | g_free(utf8); | |
| 391 | } | |
| 392 | } | |
| 393 | ||
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
394 | /* Send the message */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
395 | imflags = 0; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
396 | if (images != NULL) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
397 | imflags |= GAIM_MESSAGE_IMAGES; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
398 | if (autoreply) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
399 | imflags |= GAIM_MESSAGE_AUTO_RESP; |
| 13593 | 400 | serv_got_im(gc, conn->sn, newmsg->str, imflags, time(NULL)); |
| 401 | g_string_free(newmsg, TRUE); | |
| 402 | ||
| 403 | /* unref any images we allocated */ | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
404 | if (images) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
405 | { |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
406 | GSList *l; |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
407 | for (l = images; l != NULL; l = l->next) |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
408 | gaim_imgstore_unref(GPOINTER_TO_INT(l->data)); |
| 13593 | 409 | g_slist_free(images); |
| 410 | } | |
|
13601
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
411 | |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
412 | /* Delete our list of pointers to embedded images */ |
|
d22aea27e7e6
[gaim-migrate @ 15986]
Mark Doliner <markdoliner@pidgin.im>
parents:
13600
diff
changeset
|
413 | g_hash_table_destroy(embedded_datas); |
| 13593 | 414 | } |
| 415 | ||
| 416 | /** | |
| 417 | * This is a gaim_input_add() watcher callback function for reading | |
| 418 | * direct IM payload data. "Payload data" is always an IM and | |
| 419 | * maybe some embedded images or files or something. The actual | |
| 420 | * ODC frame is read using peer_connection_recv_cb(). We temporarily | |
| 421 | * switch to this watcher callback ONLY to read the payload, and we | |
| 422 | * switch back once we're done. | |
| 423 | */ | |
| 424 | static void | |
| 425 | peer_odc_recv_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 426 | { | |
| 427 | PeerConnection *conn; | |
| 428 | OdcFrame *frame; | |
| 429 | ByteStream *bs; | |
| 430 | ssize_t read; | |
| 431 | ||
| 432 | conn = data; | |
| 433 | frame = conn->frame; | |
| 434 | bs = &frame->payload; | |
| 435 | ||
| 436 | /* Read data into the temporary buffer until it is complete */ | |
| 437 | read = recv(conn->fd, | |
| 438 | &bs->data[bs->offset], | |
| 439 | bs->len - bs->offset, | |
| 440 | 0); | |
| 441 | ||
| 442 | /* Check if the remote user closed the connection */ | |
| 443 | if (read == 0) | |
| 444 | { | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
445 | peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED); |
| 13593 | 446 | return; |
| 447 | } | |
| 448 | ||
| 449 | if (read == -1) | |
| 450 | { | |
| 451 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | |
| 452 | /* No worries */ | |
| 453 | return; | |
| 454 | ||
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
455 | peer_connection_destroy(conn, OSCAR_DISCONNECT_LOST_CONNECTION); |
| 13593 | 456 | return; |
| 457 | } | |
| 458 | ||
| 459 | bs->offset += read; | |
| 460 | if (bs->offset < bs->len) | |
| 461 | /* Waiting for more data to arrive */ | |
| 462 | return; | |
| 463 | ||
| 464 | /* We have a complete ODC/OFT frame! Handle it and continue reading */ | |
| 465 | byte_stream_rewind(bs); | |
| 466 | peer_odc_handle_payload(conn, (const char *)bs->data, | |
| 467 | bs->len, frame->encoding, frame->flags & 0x0001); | |
| 468 | g_free(bs->data); | |
| 469 | bs->data = NULL; | |
| 470 | g_free(frame); | |
| 471 | conn->frame = NULL; | |
| 472 | ||
| 473 | gaim_input_remove(conn->watcher_incoming); | |
| 474 | conn->watcher_incoming = gaim_input_add(conn->fd, | |
| 475 | GAIM_INPUT_READ, peer_connection_recv_cb, conn); | |
| 476 | } | |
| 477 | ||
| 478 | /** | |
| 479 | * Handle an incoming OdcFrame. If there is a payload associated | |
| 480 | * with this frame, then we remove the old watcher and add the | |
| 481 | * ODC watcher to read in the payload. | |
| 482 | */ | |
| 483 | void | |
| 484 | peer_odc_recv_frame(PeerConnection *conn, ByteStream *bs) | |
| 485 | { | |
| 486 | GaimConnection *gc; | |
| 487 | OdcFrame *frame; | |
| 488 | ||
| 489 | gc = conn->od->gc; | |
| 490 | ||
| 491 | frame = g_new0(OdcFrame, 1); | |
| 492 | frame->type = byte_stream_get16(bs); | |
| 493 | frame->subtype = byte_stream_get16(bs); | |
| 494 | byte_stream_advance(bs, 2); | |
| 495 | byte_stream_getrawbuf(bs, frame->cookie, 8); | |
| 496 | byte_stream_advance(bs, 8); | |
| 497 | frame->payload.len = byte_stream_get32(bs); | |
| 498 | frame->encoding = byte_stream_get16(bs); | |
| 499 | byte_stream_advance(bs, 4); | |
| 500 | frame->flags = byte_stream_get16(bs); | |
| 501 | byte_stream_advance(bs, 4); | |
| 502 | byte_stream_getrawbuf(bs, frame->sn, 32); | |
| 503 | ||
| 504 | gaim_debug_info("oscar", "Incoming ODC frame from %s with " | |
| 505 | "type=0x%04x, flags=0x%04x, payload length=%u\n", | |
| 506 | frame->sn, frame->type, frame->flags, frame->payload.len); | |
| 507 | ||
| 508 | if (!conn->ready) | |
| 509 | { | |
| 510 | /* | |
| 511 | * We need to verify the cookie so that we know we are | |
| 512 | * connected to our friend and not a malicious middle man. | |
| 513 | */ | |
| 514 | ||
| 515 | GaimAccount *account; | |
| 516 | GaimConversation *conv; | |
| 517 | ||
| 518 | if (conn->flags & PEER_CONNECTION_FLAG_IS_INCOMING) | |
| 519 | { | |
| 520 | if (memcmp(conn->cookie, frame->cookie, 8)) | |
| 521 | { | |
| 522 | /* | |
| 523 | * Oh no! The user that connected to us did not send | |
| 524 | * the correct cookie! They are not our friend. Go try | |
| 525 | * to accept another connection? | |
| 526 | */ | |
| 527 | gaim_debug_info("oscar", "Received an incorrect cookie. " | |
| 528 | "Closing connection.\n"); | |
|
13609
a6fbfad454b6
[gaim-migrate @ 15994]
Mark Doliner <markdoliner@pidgin.im>
parents:
13601
diff
changeset
|
529 | peer_connection_destroy(conn, OSCAR_DISCONNECT_INVALID_DATA); |
| 13593 | 530 | g_free(frame); |
| 531 | return; | |
| 532 | } | |
| 533 | ||
| 534 | /* | |
| 535 | * Ok, we know they are legit. Now be courteous and | |
| 536 | * send them our cookie. Note: This doesn't seem | |
| 537 | * to be necessary, but it also doesn't seem to hurt. | |
| 538 | */ | |
| 539 | peer_odc_send_cookie(conn); | |
| 540 | } | |
| 541 | ||
| 542 | conn->ready = TRUE; | |
| 543 | ||
| 544 | /* | |
| 545 | * If they connected to us then close the listener socket | |
| 546 | * and send them our cookie. | |
| 547 | */ | |
| 548 | if (conn->listenerfd != -1) | |
| 549 | { | |
| 550 | close(conn->listenerfd); | |
| 551 | conn->listenerfd = -1; | |
| 552 | } | |
| 553 | ||
| 554 | /* Tell the local user that we are connected */ | |
| 555 | account = gaim_connection_get_account(gc); | |
| 556 | conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, conn->sn); | |
| 557 | gaim_conversation_write(conv, NULL, _("Direct IM established"), | |
| 558 | GAIM_MESSAGE_SYSTEM, time(NULL)); | |
| 559 | } | |
| 560 | ||
| 561 | if ((frame->type != 0x0001) && (frame->subtype != 0x0006)) | |
| 562 | { | |
| 563 | gaim_debug_info("oscar", "Unknown ODC frame type 0x%04hx, " | |
| 564 | "subtype 0x%04hx.\n", frame->type, frame->subtype); | |
| 565 | return; | |
| 566 | } | |
| 567 | ||
| 568 | if (frame->flags & 0x0008) | |
| 569 | { | |
| 570 | /* I had to leave this. It's just too funny. It reminds me of my sister. */ | |
| 571 | gaim_debug_info("oscar", "ohmigod! %s has started typing " | |
| 572 | "(DirectIM). He's going to send you a message! " | |
| 573 | "*squeal*\n", conn->sn); | |
| 574 | serv_got_typing(gc, conn->sn, 0, GAIM_TYPING); | |
| 575 | } | |
| 576 | else if (frame->flags & 0x0004) | |
| 577 | { | |
| 578 | serv_got_typing(gc, conn->sn, 0, GAIM_TYPED); | |
| 579 | } | |
| 580 | else | |
| 581 | { | |
| 582 | serv_got_typing_stopped(gc, conn->sn); | |
| 583 | } | |
| 584 | ||
| 585 | if (frame->payload.len > 0) | |
| 586 | { | |
| 587 | /* We have payload data! Switch to the ODC watcher to read it. */ | |
| 588 | frame->payload.data = g_new(guint8, frame->payload.len); | |
| 589 | frame->payload.offset = 0; | |
| 590 | conn->frame = frame; | |
| 591 | gaim_input_remove(conn->watcher_incoming); | |
| 592 | conn->watcher_incoming = gaim_input_add(conn->fd, | |
| 593 | GAIM_INPUT_READ, peer_odc_recv_cb, conn); | |
| 594 | return; | |
| 595 | } | |
| 596 | ||
| 597 | g_free(frame); | |
| 598 | } |