rename accountopt.[ch] to purpleaccountoption.[ch]
[pidgin-git.git] / libpurple / protocols / oscar / peer.h
blob8a31307a4a6cb124f4cc4f8ec246596cc3295b80
1 /*
2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * OFT and ODC Services
25 #ifndef PURPLE_OSCAR_PEER_H
26 #define PURPLE_OSCAR_PEER_H
28 #include "xfer.h"
29 #include "network.h"
30 #include "proxy.h"
32 typedef struct _ChecksumData ChecksumData;
33 typedef struct _OdcFrame OdcFrame;
34 typedef struct _OftFrame OftFrame;
35 typedef struct _ProxyFrame ProxyFrame;
36 typedef struct _PeerConnection PeerConnection;
38 #define PEER_CONNECTION_FLAG_INITIATED_BY_ME 0x0001
39 #define PEER_CONNECTION_FLAG_APPROVED 0x0002
40 #define PEER_CONNECTION_FLAG_TRIED_DIRECT 0x0004
41 #define PEER_CONNECTION_FLAG_TRIED_INCOMING 0x0008
42 #define PEER_CONNECTION_FLAG_TRIED_PROXY 0x0010
43 #define PEER_CONNECTION_FLAG_IS_INCOMING 0x0020
45 #define PEER_TYPE_PROMPT 0x0101 /* "I am going to send you this file, is that ok?" */
46 #define PEER_TYPE_RESUMEACCEPT 0x0106 /* We are accepting the resume */
47 #define PEER_TYPE_ACK 0x0202 /* "Yes, it is ok for you to send me that file" */
48 #define PEER_TYPE_DONE 0x0204 /* "I received that file with no problems" or "I already have that file, great!" */
49 #define PEER_TYPE_RESUME 0x0205 /* Resume transferring, sent by whoever receives */
50 #define PEER_TYPE_RESUMEACK 0x0207 /* Our resume accept was ACKed */
52 #define PEER_TYPE_GETFILE_REQUESTLISTING 0x1108 /* "I have a listing.txt file, do you want it?" */
53 #define PEER_TYPE_GETFILE_RECEIVELISTING 0x1209 /* "Yes, please send me your listing.txt file" */
54 #define PEER_TYPE_GETFILE_RECEIVEDLISTING 0x120a /* received corrupt listing.txt file? I'm just guessing about this one... */
55 #define PEER_TYPE_GETFILE_ACKLISTING 0x120b /* "I received the listing.txt file successfully" */
56 #define PEER_TYPE_GETFILE_REQUESTFILE 0x120c /* "Please send me this file" */
59 * For peer proxying
61 #define AIM_PEER_PROXY_SERVER "ars.oscar.aol.com"
62 #define ICQ_PEER_PROXY_SERVER "ars.icq.com"
63 #define PEER_PROXY_PORT 5190 /* The port we should always connect to */
64 #define PEER_PROXY_PACKET_VERSION 0x044a
66 /* Thanks to Keith Lea and the Joust project for documenting these */
67 #define PEER_PROXY_TYPE_ERROR 0x0001
68 #define PEER_PROXY_TYPE_CREATE 0x0002
69 #define PEER_PROXY_TYPE_CREATED 0x0003
70 #define PEER_PROXY_TYPE_JOIN 0x0004
71 #define PEER_PROXY_TYPE_READY 0x0005
73 struct _OdcFrame
75 /* guchar magic[4]; */ /* 0 */
76 /* guint16 length; */ /* 4 */
77 guint16 type; /* 6 */
78 guint16 subtype; /* 8 */
79 /* Unknown */ /* 10 */
80 guchar cookie[8]; /* 12 */
81 /* Unknown */
82 /* guint32 payloadlength; */ /* 28 */
83 guint16 encoding; /* 32 */
84 /* Unknown */
85 guint16 flags; /* 38 */
86 /* Unknown */
87 guchar bn[32]; /* 44 */
88 /* Unknown */
89 ByteStream payload; /* 76 */
92 struct _OftFrame
94 /* guchar magic[4]; */ /* 0 */
95 /* guint16 length; */ /* 4 */
96 guint16 type; /* 6 */
97 guchar cookie[8]; /* 8 */
98 guint16 encrypt; /* 16 */
99 guint16 compress; /* 18 */
100 guint16 totfiles; /* 20 */
101 guint16 filesleft; /* 22 */
102 guint16 totparts; /* 24 */
103 guint16 partsleft; /* 26 */
104 guint32 totsize; /* 28 */
105 guint32 size; /* 32 */
106 guint32 modtime; /* 36 */
107 guint32 checksum; /* 40 */
108 guint32 rfrcsum; /* 44 */
109 guint32 rfsize; /* 48 */
110 guint32 cretime; /* 52 */
111 guint32 rfcsum; /* 56 */
112 guint32 nrecvd; /* 60 */
113 guint32 recvcsum; /* 64 */
114 guchar idstring[32]; /* 68 */
115 guint8 flags; /* 100 */
116 guint8 lnameoffset; /* 101 */
117 guint8 lsizeoffset; /* 102 */
118 guchar dummy[69]; /* 103 */
119 guchar macfileinfo[16]; /* 172 */
120 guint16 nencode; /* 188 */
121 guint16 nlanguage; /* 190 */
122 guchar *name; /* 192 */
123 size_t name_length;
124 /* Payload? */ /* 256 */
127 struct _ProxyFrame
129 /* guint16 length; */ /* 0 */
130 guint16 version; /* 2 */
131 guint16 type; /* 4 */
132 guint32 unknown; /* 6 */
133 guint16 flags; /* 10 */
134 ByteStream payload; /* 12 */
137 struct _PeerConnection
139 OscarData *od;
140 guint64 type;
141 char *bn;
142 guchar magic[4];
143 guchar cookie[8];
144 guint16 lastrequestnumber;
146 gboolean ready;
147 int flags; /**< Bitmask of PEER_CONNECTION_FLAG_ */
148 time_t lastactivity; /**< Time of last transmit. */
149 guint destroy_timeout;
150 OscarDisconnectReason disconnect_reason;
151 char *error_message;
154 * A pointer to either an OdcFrame or an OftFrame.
156 gpointer frame;
159 * This is only used when the peer connection is being established.
161 PurpleProxyConnectData *client_connect_data;
162 PurpleProxyConnectData *verified_connect_data;
165 * This is only used when the peer connection is being established.
167 PurpleNetworkListenData *listen_data;
171 * This is only used when the peer connection is being established.
173 guint connect_timeout_timer;
176 * This is only used while the remote user is attempting to
177 * connect to us.
179 int listenerfd;
181 int fd;
182 guint8 header[6];
183 gssize header_received;
184 guint8 proxy_header[12];
185 gssize proxy_header_received;
186 ByteStream buffer_incoming;
187 PurpleCircularBuffer *buffer_outgoing;
188 guint watcher_incoming;
189 guint watcher_outgoing;
192 * IP address of the proxy server, if applicable.
194 gchar *proxyip;
197 * IP address of the remote user from THEIR point of view.
199 gchar *clientip;
202 * IP address of the remote user from the oscar server's
203 * point of view.
205 gchar *verifiedip;
207 guint16 port;
208 gboolean use_proxy;
211 * Checksumming
213 ChecksumData *checksum_data;
215 /* TODOFT */
216 PurpleXfer *xfer;
217 OftFrame xferdata;
218 guint sending_data_timer;
222 * For all peer connections
226 * Create a new PeerConnection structure and initialize it with some
227 * sane defaults.
229 * @param type The type of the peer connection. One of
230 * OSCAR_CAPABILITY_DIRECTIM or OSCAR_CAPABILITY_SENDFILE.
232 PeerConnection *peer_connection_new(OscarData *od, guint64 type, const char *bn);
234 void peer_connection_destroy(PeerConnection *conn, OscarDisconnectReason reason, const gchar *error_message);
235 void peer_connection_schedule_destroy(PeerConnection *conn, OscarDisconnectReason reason, const gchar *error_message);
236 PeerConnection *peer_connection_find_by_type(OscarData *od, const char *bn, guint64 type);
237 PeerConnection *peer_connection_find_by_cookie(OscarData *od, const char *bn, const guchar *cookie);
239 void peer_connection_listen_cb(gpointer data, gint source, PurpleInputCondition cond);
240 void peer_connection_recv_cb(gpointer data, gint source, PurpleInputCondition cond);
241 void peer_connection_send(PeerConnection *conn, ByteStream *bs);
243 void peer_connection_trynext(PeerConnection *conn);
244 void peer_connection_finalize_connection(PeerConnection *conn);
245 void peer_connection_propose(OscarData *od, guint64 type, const char *bn);
246 void peer_connection_got_proposition(OscarData *od, const gchar *bn, const gchar *message, IcbmArgsCh2 *args);
249 * For ODC
251 void peer_odc_close(PeerConnection *conn);
252 void peer_odc_recv_frame(PeerConnection *conn, ByteStream *bs);
253 void peer_odc_send_cookie(PeerConnection *conn);
254 void peer_odc_send_typing(PeerConnection *conn, PurpleIMTypingState typing);
255 void peer_odc_send_im(PeerConnection *conn, const char *msg, int len, int encoding, gboolean autoreply);
258 * For OFT
260 void peer_oft_close(PeerConnection *conn);
261 void peer_oft_recv_frame(PeerConnection *conn, ByteStream *bs);
262 void peer_oft_send_prompt(PeerConnection *conn);
263 void peer_oft_checksum_destroy(ChecksumData *checksum_data);
265 /* Xfer callbacks for receiving a file */
266 void peer_oft_recvcb_init(PurpleXfer *xfer);
267 void peer_oft_recvcb_end(PurpleXfer *xfer);
268 void peer_oft_recvcb_ack_recv(PurpleXfer *xfer, const guchar *buffer, size_t size);
270 /* Xfer callbacks for sending a file */
271 void peer_oft_sendcb_init(PurpleXfer *xfer);
272 void peer_oft_sendcb_ack(PurpleXfer *xfer, const guchar *buffer, size_t size);
274 /* Xfer callbacks for both sending and receiving */
275 void peer_oft_cb_generic_cancel(PurpleXfer *xfer);
278 * For peer proxying
280 void peer_proxy_connection_established_cb(gpointer data, gint source, const gchar *error_message);
282 /* File transfers */
283 #define OSCAR_TYPE_XFER (oscar_xfer_get_type())
284 G_DECLARE_FINAL_TYPE(OscarXfer, oscar_xfer, OSCAR, XFER, PurpleXfer);
286 struct _OscarXfer {
287 PurpleXfer parent;
289 PeerConnection *conn;
292 void oscar_xfer_register(GTypeModule *module);
293 PeerConnection *oscar_xfer_get_peer_connection(OscarXfer *xfer);
295 #endif /* PURPLE_OSCAR_PEER_H */