13592
|
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
|
13608
|
39 if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED)
|
|
40 tmp = _("The remote user has closed the connection.");
|
|
41 else if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_REFUSED)
|
|
42 tmp = _("The remote user has declined your request.");
|
|
43 else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION)
|
|
44 tmp = _("Lost connection with the remote user for an unknown reason.");
|
|
45 else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA)
|
|
46 tmp = _("Received invalid data on connection with remote user.");
|
|
47 else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT)
|
|
48 tmp = _("Could not establish a connection with the remote user.");
|
13592
|
49 else
|
|
50 /*
|
|
51 * We shouldn't print a message for some disconnect_reasons.
|
13608
|
52 * Like OSCAR_DISCONNECT_LOCAL_CLOSED.
|
13592
|
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
|
13600
|
197 struct embedded_data
|
|
198 {
|
|
199 size_t size;
|
|
200 const guint8 *data;
|
|
201 };
|
|
202
|
13592
|
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
|
13600
|
216 * (with added whitespace):
|
13592
|
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;
|
13600
|
237 const char *msgend, *binary_start, *dataend;
|
|
238 const char *tmp, *start, *end, *idstr, *src, *sizestr;
|
|
239 GData *attributes;
|
|
240 GHashTable *embedded_datas;
|
|
241 struct embedded_data *embedded_data;
|
|
242 GSList *images;
|
13592
|
243 gchar *utf8;
|
|
244 GString *newmsg;
|
13600
|
245 GaimMessageFlags imflags;
|
13592
|
246
|
13600
|
247 gc = conn->od->gc;
|
13592
|
248 account = gaim_connection_get_account(gc);
|
|
249
|
13600
|
250 dataend = msg + len;
|
13592
|
251
|
13600
|
252 /*
|
|
253 * Create a hash table containing references to each embedded
|
|
254 * data chunk. The key is the "ID" and the value is an
|
|
255 * embedded_data struct.
|
|
256 */
|
|
257 embedded_datas = g_hash_table_new_full(g_direct_hash,
|
|
258 g_direct_equal, NULL, g_free);
|
13592
|
259
|
13600
|
260 /*
|
|
261 * Create an index of any binary chunks. If we run into any
|
|
262 * problems while parsing the binary data section then we stop
|
|
263 * parsing it, and the local user will see broken image icons.
|
|
264 */
|
|
265 /* TODO: Use a length argument when looking for the <binary> tag! */
|
|
266 binary_start = gaim_strcasestr(msg, "<binary>");
|
|
267 if (binary_start == NULL)
|
|
268 msgend = dataend;
|
|
269 else
|
13592
|
270 {
|
13600
|
271 msgend = binary_start;
|
13592
|
272
|
13600
|
273 /* Move our pointer to immediately after the <binary> tag */
|
|
274 tmp = binary_start + 8;
|
13592
|
275
|
13600
|
276 /* The embedded binary markup has a mimimum length of 29 bytes */
|
|
277 /* TODO: Use a length argument when looking for the <data> tag! */
|
|
278 while ((tmp + 29 <= dataend) &&
|
|
279 gaim_markup_find_tag("data", tmp, &start, &tmp, &attributes))
|
13592
|
280 {
|
13600
|
281 unsigned int id;
|
13592
|
282 size_t size;
|
13600
|
283
|
|
284 /* Move the binary pointer from ">" to the start of the data */
|
|
285 tmp++;
|
13592
|
286
|
13600
|
287 /* Get the ID */
|
|
288 idstr = g_datalist_get_data(&attributes, "id");
|
|
289 if (idstr == NULL)
|
|
290 {
|
|
291 g_datalist_clear(&attributes);
|
|
292 break;
|
|
293 }
|
|
294 id = atoi(idstr);
|
13592
|
295
|
13600
|
296 /* Get the size */
|
|
297 sizestr = g_datalist_get_data(&attributes, "size");
|
|
298 if (sizestr == NULL)
|
|
299 {
|
|
300 g_datalist_clear(&attributes);
|
|
301 break;
|
|
302 }
|
|
303 size = atol(sizestr);
|
13592
|
304
|
13600
|
305 g_datalist_clear(&attributes);
|
|
306
|
|
307 if ((size > 0) && (tmp + size > dataend))
|
|
308 break;
|
|
309
|
|
310 embedded_data = g_new(struct embedded_data, 1);
|
|
311 embedded_data->size = size;
|
|
312 embedded_data->data = (const guint8 *)tmp;
|
|
313 tmp += size;
|
|
314
|
|
315 /* Skip past the closing </data> tag */
|
|
316 if (strncasecmp(tmp, "</data>", 7))
|
13599
|
317 {
|
13600
|
318 g_free(embedded_data);
|
|
319 break;
|
13599
|
320 }
|
13600
|
321 tmp += 7;
|
13592
|
322
|
13600
|
323 g_hash_table_insert(embedded_datas,
|
|
324 GINT_TO_POINTER(id), embedded_data);
|
|
325 }
|
|
326 }
|
13592
|
327
|
13600
|
328 /*
|
|
329 * Loop through the message, replacing OSCAR img tags with the
|
|
330 * equivalent Gaim img tag.
|
|
331 */
|
|
332 images = NULL;
|
|
333 newmsg = g_string_new("");
|
|
334 tmp = msg;
|
|
335 while (gaim_markup_find_tag("img", tmp, &start, &end, &attributes))
|
|
336 {
|
|
337 int imgid = 0;
|
|
338
|
|
339 idstr = g_datalist_get_data(&attributes, "id");
|
|
340 src = g_datalist_get_data(&attributes, "src");
|
|
341 sizestr = g_datalist_get_data(&attributes, "datasize");
|
13592
|
342
|
13600
|
343 if ((idstr != NULL) && (src != NULL) && (sizestr!= NULL))
|
|
344 {
|
|
345 unsigned int id;
|
|
346 size_t size;
|
13592
|
347
|
13600
|
348 id = atoi(idstr);
|
|
349 size = atol(sizestr);
|
|
350 embedded_data = g_hash_table_lookup(embedded_datas,
|
|
351 GINT_TO_POINTER(id));
|
|
352
|
|
353 if ((embedded_data != NULL) && (embedded_data->size == size))
|
|
354 {
|
|
355 imgid = gaim_imgstore_add(embedded_data->data, size, src);
|
|
356
|
|
357 /* Record the image number */
|
13592
|
358 images = g_slist_append(images, GINT_TO_POINTER(imgid));
|
|
359 }
|
|
360 }
|
|
361
|
13600
|
362 /* Delete the attribute list */
|
|
363 g_datalist_clear(&attributes);
|
|
364
|
|
365 /* Append the message up to the tag */
|
|
366 utf8 = gaim_plugin_oscar_decode_im_part(account, conn->sn,
|
|
367 encoding, 0x0000, tmp, start - tmp);
|
|
368 if (utf8 != NULL) {
|
|
369 g_string_append(newmsg, utf8);
|
|
370 g_free(utf8);
|
|
371 }
|
13592
|
372
|
13600
|
373 if (imgid != 0)
|
|
374 {
|
|
375 /* Write the new image tag */
|
|
376 g_string_append_printf(newmsg, "<IMG ID=\"%d\">", imgid);
|
|
377 }
|
|
378
|
|
379 /* Continue from the end of the tag */
|
|
380 tmp = end + 1;
|
|
381 }
|
|
382
|
|
383 /* Append any remaining message data */
|
|
384 if (tmp <= msgend)
|
|
385 {
|
13592
|
386 utf8 = gaim_plugin_oscar_decode_im_part(account, conn->sn,
|
13600
|
387 encoding, 0x0000, tmp, msgend - tmp);
|
13592
|
388 if (utf8 != NULL) {
|
|
389 g_string_append(newmsg, utf8);
|
|
390 g_free(utf8);
|
|
391 }
|
|
392 }
|
|
393
|
13600
|
394 /* Send the message */
|
|
395 imflags = 0;
|
|
396 if (images != NULL)
|
|
397 imflags |= GAIM_MESSAGE_IMAGES;
|
|
398 if (autoreply)
|
|
399 imflags |= GAIM_MESSAGE_AUTO_RESP;
|
13592
|
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 */
|
13600
|
404 if (images)
|
|
405 {
|
|
406 GSList *l;
|
|
407 for (l = images; l != NULL; l = l->next)
|
|
408 gaim_imgstore_unref(GPOINTER_TO_INT(l->data));
|
13592
|
409 g_slist_free(images);
|
|
410 }
|
13600
|
411
|
|
412 /* Delete our list of pointers to embedded images */
|
|
413 g_hash_table_destroy(embedded_datas);
|
13592
|
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 {
|
13608
|
445 peer_connection_destroy(conn, OSCAR_DISCONNECT_REMOTE_CLOSED);
|
13592
|
446 return;
|
|
447 }
|
|
448
|
|
449 if (read == -1)
|
|
450 {
|
|
451 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
|
|
452 /* No worries */
|
|
453 return;
|
|
454
|
13608
|
455 peer_connection_destroy(conn, OSCAR_DISCONNECT_LOST_CONNECTION);
|
13592
|
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");
|
13608
|
529 peer_connection_destroy(conn, OSCAR_DISCONNECT_INVALID_DATA);
|
13592
|
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 }
|