| |
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 /* |
| |
22 * OFT and ODC Services |
| |
23 */ |
| |
24 |
| |
25 #ifndef _PEER_H_ |
| |
26 #define _PEER_H_ |
| |
27 |
| |
28 #include "ft.h" |
| |
29 |
| |
30 typedef struct _OdcFrame OdcFrame; |
| |
31 typedef struct _OftFrame OftFrame; |
| |
32 typedef struct _ProxyFrame ProxyFrame; |
| |
33 typedef struct _NewPeerConnectionData NewPeerConnectionData; |
| |
34 typedef struct _PeerConnection PeerConnection; |
| |
35 |
| |
36 #define PEER_CONNECTION_FLAG_INITIATED_BY_ME 0x0001 |
| |
37 #define PEER_CONNECTION_FLAG_APPROVED 0x0002 |
| |
38 #define PEER_CONNECTION_FLAG_TRIED_VERIFIEDIP 0x0004 |
| |
39 #define PEER_CONNECTION_FLAG_TRIED_CLIENTIP 0x0008 |
| |
40 #define PEER_CONNECTION_FLAG_TRIED_INCOMING 0x0010 |
| |
41 #define PEER_CONNECTION_FLAG_TRIED_PROXY 0x0020 |
| |
42 #define PEER_CONNECTION_FLAG_IS_INCOMING 0x0040 |
| |
43 |
| |
44 #define PEER_TYPE_PROMPT 0x0101 /* "I am going to send you this file, is that ok?" */ |
| |
45 #define PEER_TYPE_RESUMESOMETHING 0x0106 /* I really don't know */ |
| |
46 #define PEER_TYPE_ACK 0x0202 /* "Yes, it is ok for you to send me that file" */ |
| |
47 #define PEER_TYPE_DONE 0x0204 /* "I received that file with no problems, thanks a bunch" */ |
| |
48 #define PEER_TYPE_RESUME 0x0205 /* Resume transferring, sent by whoever paused? */ |
| |
49 #define PEER_TYPE_RESUMEACK 0x0207 /* Not really sure */ |
| |
50 |
| |
51 #define PEER_TYPE_GETFILE_REQUESTLISTING 0x1108 /* "I have a listing.txt file, do you want it?" */ |
| |
52 #define PEER_TYPE_GETFILE_RECEIVELISTING 0x1209 /* "Yes, please send me your listing.txt file" */ |
| |
53 #define PEER_TYPE_GETFILE_RECEIVEDLISTING 0x120a /* received corrupt listing.txt file? I'm just guessing about this one... */ |
| |
54 #define PEER_TYPE_GETFILE_ACKLISTING 0x120b /* "I received the listing.txt file successfully" */ |
| |
55 #define PEER_TYPE_GETFILE_REQUESTFILE 0x120c /* "Please send me this file" */ |
| |
56 |
| |
57 /* |
| |
58 * For peer proxying |
| |
59 */ |
| |
60 #define PEER_PROXY_SERVER "ars.oscar.aol.com" |
| |
61 #define PEER_PROXY_PORT 5190 /* The port we should always connect to */ |
| |
62 #define PEER_PROXY_PACKET_VERSION 0x044a |
| |
63 |
| |
64 /* Thanks to Keith Lea and the Joust project for documenting these */ |
| |
65 #define PEER_PROXY_TYPE_ERROR 0x0001 |
| |
66 #define PEER_PROXY_TYPE_CREATE 0x0002 |
| |
67 #define PEER_PROXY_TYPE_CREATED 0x0003 |
| |
68 #define PEER_PROXY_TYPE_JOIN 0x0004 |
| |
69 #define PEER_PROXY_TYPE_READY 0x0005 |
| |
70 |
| |
71 struct _OdcFrame |
| |
72 { |
| |
73 /* guchar magic[4]; */ /* 0 */ |
| |
74 /* guint16 length; */ /* 4 */ |
| |
75 guint16 type; /* 6 */ |
| |
76 guint16 subtype; /* 8 */ |
| |
77 /* Unknown */ /* 10 */ |
| |
78 guchar cookie[8]; /* 12 */ |
| |
79 /* Unknown */ |
| |
80 /* guint32 payloadlength; */ /* 28 */ |
| |
81 guint16 encoding; /* 32 */ |
| |
82 /* Unknown */ |
| |
83 guint16 flags; /* 38 */ |
| |
84 /* Unknown */ |
| |
85 guchar sn[32]; /* 44 */ |
| |
86 /* Unknown */ |
| |
87 ByteStream payload; /* 76 */ |
| |
88 }; |
| |
89 |
| |
90 struct _OftFrame |
| |
91 { |
| |
92 /* guchar magic[4]; */ /* 0 */ |
| |
93 /* guint16 length; */ /* 4 */ |
| |
94 guint16 type; /* 6 */ |
| |
95 guchar cookie[8]; /* 8 */ |
| |
96 guint16 encrypt; /* 16 */ |
| |
97 guint16 compress; /* 18 */ |
| |
98 guint16 totfiles; /* 20 */ |
| |
99 guint16 filesleft; /* 22 */ |
| |
100 guint16 totparts; /* 24 */ |
| |
101 guint16 partsleft; /* 26 */ |
| |
102 guint32 totsize; /* 28 */ |
| |
103 guint32 size; /* 32 */ |
| |
104 guint32 modtime; /* 36 */ |
| |
105 guint32 checksum; /* 40 */ |
| |
106 guint32 rfrcsum; /* 44 */ |
| |
107 guint32 rfsize; /* 48 */ |
| |
108 guint32 cretime; /* 52 */ |
| |
109 guint32 rfcsum; /* 56 */ |
| |
110 guint32 nrecvd; /* 60 */ |
| |
111 guint32 recvcsum; /* 64 */ |
| |
112 guchar idstring[32]; /* 68 */ |
| |
113 guint8 flags; /* 100 */ |
| |
114 guint8 lnameoffset; /* 101 */ |
| |
115 guint8 lsizeoffset; /* 102 */ |
| |
116 guchar dummy[69]; /* 103 */ |
| |
117 guchar macfileinfo[16]; /* 172 */ |
| |
118 guint16 nencode; /* 188 */ |
| |
119 guint16 nlanguage; /* 190 */ |
| |
120 guchar *name; /* 192 */ |
| |
121 size_t name_length; |
| |
122 /* Payload? */ /* 256 */ |
| |
123 }; |
| |
124 |
| |
125 struct _ProxyFrame |
| |
126 { |
| |
127 /* guint16 length; */ /* 0 */ |
| |
128 guint16 version; /* 2 */ |
| |
129 guint16 type; /* 4 */ |
| |
130 guint32 unknown; /* 6 */ |
| |
131 guint16 flags; /* 10 */ |
| |
132 ByteStream payload; /* 12 */ |
| |
133 }; |
| |
134 |
| |
135 struct _NewPeerConnectionData |
| |
136 { |
| |
137 GaimConnection *gc; |
| |
138 PeerConnection *conn; |
| |
139 }; |
| |
140 |
| |
141 struct _PeerConnection |
| |
142 { |
| |
143 OscarData *od; |
| |
144 OscarCapability type; |
| |
145 char *sn; |
| |
146 guchar magic[4]; |
| |
147 guchar cookie[8]; |
| |
148 guint16 lastrequestnumber; |
| |
149 |
| |
150 gboolean ready; |
| |
151 int flags; /**< Bitmask of PEER_CONNECTION_FLAG_ */ |
| |
152 time_t lastactivity; /**< Time of last transmit. */ |
| |
153 guint destroy_timeout; |
| |
154 OscarDisconnectReason disconnect_reason; |
| |
155 |
| |
156 /** |
| |
157 * A pointer to either an OdcFrame or an OftFrame. |
| |
158 */ |
| |
159 gpointer frame; |
| |
160 |
| |
161 /** |
| |
162 * This is only used when the peer connection is being established. |
| |
163 */ |
| |
164 GaimProxyConnectInfo *connect_info; |
| |
165 |
| |
166 /** |
| |
167 * This is only used when the peer connection is being established. |
| |
168 */ |
| |
169 guint connect_timeout_timer; |
| |
170 |
| |
171 /** |
| |
172 * This is only used while the remote user is attempting to |
| |
173 * connect to us. |
| |
174 */ |
| |
175 int listenerfd; |
| |
176 |
| |
177 int fd; |
| |
178 |
| |
179 guint watcher_incoming; |
| |
180 guint watcher_outgoing; |
| |
181 |
| |
182 ByteStream buffer_incoming; |
| |
183 GaimCircBuffer *buffer_outgoing; |
| |
184 |
| |
185 /** |
| |
186 * IP address of the proxy server, if applicable. |
| |
187 */ |
| |
188 gchar *proxyip; |
| |
189 |
| |
190 /** |
| |
191 * IP address of the remote user from THEIR point of view. |
| |
192 */ |
| |
193 gchar *clientip; |
| |
194 |
| |
195 /** |
| |
196 * IP address of the remote user from the oscar server's |
| |
197 * point of view. |
| |
198 */ |
| |
199 gchar *verifiedip; |
| |
200 |
| |
201 guint16 port; |
| |
202 gboolean use_proxy; |
| |
203 |
| |
204 /* TODOFT */ |
| |
205 GaimXfer *xfer; |
| |
206 OftFrame xferdata; |
| |
207 guint sending_data_timer; |
| |
208 }; |
| |
209 |
| |
210 /* |
| |
211 * For all peer connections |
| |
212 */ |
| |
213 |
| |
214 /** |
| |
215 * Create a new PeerConnection structure and initialize it with some |
| |
216 * sane defaults. |
| |
217 * |
| |
218 * @param type The type of the peer connection. One of |
| |
219 * OSCAR_CAPABILITY_DIRECTIM or OSCAR_CAPABILITY_SENDFILE. |
| |
220 */ |
| |
221 PeerConnection *peer_connection_new(OscarData *od, OscarCapability type, const char *sn); |
| |
222 |
| |
223 void peer_connection_destroy(PeerConnection *conn, OscarDisconnectReason reason); |
| |
224 void peer_connection_schedule_destroy(PeerConnection *conn, OscarDisconnectReason reason); |
| |
225 PeerConnection *peer_connection_find_by_type(OscarData *od, const char *sn, OscarCapability type); |
| |
226 PeerConnection *peer_connection_find_by_cookie(OscarData *od, const char *sn, const guchar *cookie); |
| |
227 |
| |
228 void peer_connection_listen_cb(gpointer data, gint source, GaimInputCondition cond); |
| |
229 void peer_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond); |
| |
230 void peer_connection_send(PeerConnection *conn, ByteStream *bs); |
| |
231 |
| |
232 void peer_connection_trynext(PeerConnection *conn); |
| |
233 void peer_connection_finalize_connection(PeerConnection *conn); |
| |
234 void peer_connection_propose(OscarData *od, OscarCapability type, const char *sn); |
| |
235 void peer_connection_got_proposition(OscarData *od, const gchar *sn, const gchar *message, IcbmArgsCh2 *args); |
| |
236 |
| |
237 /* |
| |
238 * For ODC |
| |
239 */ |
| |
240 void peer_odc_close(PeerConnection *conn); |
| |
241 void peer_odc_recv_frame(PeerConnection *conn, ByteStream *bs); |
| |
242 void peer_odc_send_cookie(PeerConnection *conn); |
| |
243 void peer_odc_send_typing(PeerConnection *conn, GaimTypingState typing); |
| |
244 void peer_odc_send_im(PeerConnection *conn, const char *msg, int len, int encoding, gboolean autoreply); |
| |
245 |
| |
246 /* |
| |
247 * For OFT |
| |
248 */ |
| |
249 void peer_oft_close(PeerConnection *conn); |
| |
250 void peer_oft_recv_frame(PeerConnection *conn, ByteStream *bs); |
| |
251 void peer_oft_send_prompt(PeerConnection *conn); |
| |
252 |
| |
253 /* Xfer callbacks for receiving a file */ |
| |
254 void peer_oft_recvcb_init(GaimXfer *xfer); |
| |
255 void peer_oft_recvcb_end(GaimXfer *xfer); |
| |
256 void peer_oft_recvcb_ack_recv(GaimXfer *xfer, const guchar *buffer, size_t size); |
| |
257 |
| |
258 /* Xfer callbacks for sending a file */ |
| |
259 void peer_oft_sendcb_init(GaimXfer *xfer); |
| |
260 void peer_oft_sendcb_ack(GaimXfer *xfer, const guchar *buffer, size_t size); |
| |
261 |
| |
262 /* Xfer callbacks for both sending and receiving */ |
| |
263 void peer_oft_cb_generic_cancel(GaimXfer *xfer); |
| |
264 |
| |
265 /* |
| |
266 * For peer proxying |
| |
267 */ |
| |
268 void peer_proxy_connection_established_cb(gpointer data, gint source, const gchar *error_message); |
| |
269 |
| |
270 #if 0 |
| |
271 int peer_oft_sendheader(OscarData *od, guint16 type, PeerConnection *peer_connection); |
| |
272 guint32 peer_oft_checksum_chunk(const guint8 *buffer, int bufferlen, guint32 prevcheck); |
| |
273 guint32 peer_oft_checksum_file(char *filename); |
| |
274 int peer_oft_sendheader(OscarData *od, guint16 type, PeerConnection *peer_connection); |
| |
275 PeerConnection *peer_oft_createinfo(OscarData *od, const guchar *cookie, const char *sn, |
| |
276 const char *ip, guint16 port, guint32 size, guint32 modtime, char *filename, int send_or_recv, |
| |
277 int method, int stage); |
| |
278 int peer_oft_destroyinfo(PeerConnection *peer_connection); |
| |
279 #endif |
| |
280 |
| |
281 #endif /* _PEER_H_ */ |