Annotation of ChivanetAimPidgin/oscarprpl/src/c/peer.h, revision 1.1
1.1 ! snw 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.
! 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 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: #include "network.h"
! 30: #include "proxy.h"
! 31:
! 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;
! 37:
! 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
! 44:
! 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 */
! 51:
! 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" */
! 57:
! 58: /*
! 59: * For peer proxying
! 60: */
! 61: #define AIM_PEER_PROXY_SERVER "ars.oscar.nina.chat"
! 62: #define ICQ_PEER_PROXY_SERVER "ars.oscar.nina.chat"
! 63: #define PEER_PROXY_PORT 5190 /* The port we should always connect to */
! 64: #define PEER_PROXY_PACKET_VERSION 0x044a
! 65:
! 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
! 72:
! 73: struct _OdcFrame
! 74: {
! 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 */
! 90: };
! 91:
! 92: struct _OftFrame
! 93: {
! 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 */
! 125: };
! 126:
! 127: struct _ProxyFrame
! 128: {
! 129: /* guint16 length; */ /* 0 */
! 130: guint16 version; /* 2 */
! 131: guint16 type; /* 4 */
! 132: guint32 unknown; /* 6 */
! 133: guint16 flags; /* 10 */
! 134: ByteStream payload; /* 12 */
! 135: };
! 136:
! 137: struct _PeerConnection
! 138: {
! 139: OscarData *od;
! 140: guint64 type;
! 141: char *bn;
! 142: guchar magic[4];
! 143: guchar cookie[8];
! 144: guint16 lastrequestnumber;
! 145:
! 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;
! 152:
! 153: /**
! 154: * A pointer to either an OdcFrame or an OftFrame.
! 155: */
! 156: gpointer frame;
! 157:
! 158: /**
! 159: * This is only used when the peer connection is being established.
! 160: */
! 161: PurpleProxyConnectData *client_connect_data;
! 162: PurpleProxyConnectData *verified_connect_data;
! 163:
! 164: /**
! 165: * This is only used when the peer connection is being established.
! 166: */
! 167: PurpleNetworkListenData *listen_data;
! 168:
! 169:
! 170: /**
! 171: * This is only used when the peer connection is being established.
! 172: */
! 173: guint connect_timeout_timer;
! 174:
! 175: /**
! 176: * This is only used while the remote user is attempting to
! 177: * connect to us.
! 178: */
! 179: int listenerfd;
! 180:
! 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: PurpleCircBuffer *buffer_outgoing;
! 188: guint watcher_incoming;
! 189: guint watcher_outgoing;
! 190:
! 191: /**
! 192: * IP address of the proxy server, if applicable.
! 193: */
! 194: gchar *proxyip;
! 195:
! 196: /**
! 197: * IP address of the remote user from THEIR point of view.
! 198: */
! 199: gchar *clientip;
! 200:
! 201: /**
! 202: * IP address of the remote user from the oscar server's
! 203: * point of view.
! 204: */
! 205: gchar *verifiedip;
! 206:
! 207: guint16 port;
! 208: gboolean use_proxy;
! 209:
! 210: /**
! 211: * Checksumming
! 212: */
! 213: ChecksumData *checksum_data;
! 214:
! 215: /* TODOFT */
! 216: PurpleXfer *xfer;
! 217: OftFrame xferdata;
! 218: guint sending_data_timer;
! 219: };
! 220:
! 221: /*
! 222: * For all peer connections
! 223: */
! 224:
! 225: /**
! 226: * Create a new PeerConnection structure and initialize it with some
! 227: * sane defaults.
! 228: *
! 229: * @param type The type of the peer connection. One of
! 230: * OSCAR_CAPABILITY_DIRECTIM or OSCAR_CAPABILITY_SENDFILE.
! 231: */
! 232: PeerConnection *peer_connection_new(OscarData *od, guint64 type, const char *bn);
! 233:
! 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);
! 238:
! 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);
! 242:
! 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);
! 247:
! 248: /*
! 249: * For ODC
! 250: */
! 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, PurpleTypingState typing);
! 255: void peer_odc_send_im(PeerConnection *conn, const char *msg, int len, int encoding, gboolean autoreply);
! 256:
! 257: /*
! 258: * For OFT
! 259: */
! 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);
! 264:
! 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);
! 269:
! 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);
! 273:
! 274: /* Xfer callbacks for both sending and receiving */
! 275: void peer_oft_cb_generic_cancel(PurpleXfer *xfer);
! 276:
! 277: /*
! 278: * For peer proxying
! 279: */
! 280: void peer_proxy_connection_established_cb(gpointer data, gint source, const gchar *error_message);
! 281:
! 282: #endif /* _PEER_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>