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