annotate src/protocols/oscar/odc.c @ 13997:1c411ca5590c

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