Frameworks/libpurple.framework/Versions/2.10.12r8d2874a79747/Headers/directconn.h
branchadium-1.5.11
changeset 6014 fcb71cb71a3d
parent 5941 307f53385811
parent 6013 f8d0dc659e3f
child 6016 325e2ab3406f
equal deleted inserted replaced
5941:307f53385811 6014:fcb71cb71a3d
     1 /**
       
     2  * @file directconn.h MSN direct connection functions
       
     3  *
       
     4  * purple
       
     5  *
       
     6  * Purple is the legal property of its developers, whose names are too numerous
       
     7  * to list here.  Please refer to the COPYRIGHT file distributed with this
       
     8  * source distribution.
       
     9  *
       
    10  * This program is free software; you can redistribute it and/or modify
       
    11  * it under the terms of the GNU General Public License as published by
       
    12  * the Free Software Foundation; either version 2 of the License, or
       
    13  * (at your option) any later version.
       
    14  *
       
    15  * This program is distributed in the hope that it will be useful,
       
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    18  * GNU General Public License for more details.
       
    19  *
       
    20  * You should have received a copy of the GNU General Public License
       
    21  * along with this program; if not, write to the Free Software
       
    22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
       
    23  */
       
    24 #ifndef MSN_DIRECTCONN_H
       
    25 #define MSN_DIRECTCONN_H
       
    26 
       
    27 typedef struct _MsnDirectConn MsnDirectConn;
       
    28 
       
    29 #include "network.h"
       
    30 #include "proxy.h"
       
    31 #include "circbuffer.h"
       
    32 
       
    33 #include "slp.h"
       
    34 #include "slplink.h"
       
    35 #include "slpmsg.h"
       
    36 #include "slpmsg_part.h"
       
    37 #include "p2p.h"
       
    38 
       
    39 #define MSN_DCCONN_MAX_SIZE 1352
       
    40 
       
    41 typedef enum
       
    42 {
       
    43 	DC_STATE_CLOSED,            /*< No socket opened yet */
       
    44 	DC_STATE_FOO,               /*< Waiting for FOO message */
       
    45 	DC_STATE_HANDSHAKE,         /*< Waiting for handshake message */
       
    46 	DC_STATE_HANDSHAKE_REPLY,   /*< Waiting for handshake reply message */
       
    47 	DC_STATE_ESTABLISHED        /*< Handshake complete */
       
    48 } MsnDirectConnState;
       
    49 
       
    50 typedef enum
       
    51 {
       
    52 	DC_PROCESS_OK = 0,
       
    53 	DC_PROCESS_ERROR,
       
    54 	DC_PROCESS_FALLBACK,
       
    55 	DC_PROCESS_CLOSE
       
    56 
       
    57 } MsnDirectConnProcessResult;
       
    58 
       
    59 typedef enum
       
    60 {
       
    61 	DC_NONCE_UNKNOWN,	/**< Invalid scheme */
       
    62 	DC_NONCE_PLAIN,     /**< No hashing */
       
    63 	DC_NONCE_SHA1       /**< First 16 bytes of SHA1 of nonce */
       
    64 
       
    65 } MsnDirectConnNonceType;
       
    66 
       
    67 typedef struct _MsnDirectConnPacket MsnDirectConnPacket;
       
    68 
       
    69 struct _MsnDirectConnPacket {
       
    70 	guint32     length;
       
    71 	guchar      *data;
       
    72 
       
    73 	void        (*sent_cb)(struct _MsnDirectConnPacket*);
       
    74 	MsnSlpMessagePart *part;
       
    75 };
       
    76 
       
    77 struct _MsnDirectConn
       
    78 {
       
    79 	MsnDirectConnState  state;      /**< Direct connection status */
       
    80 	MsnSlpLink          *slplink;   /**< The slplink using this direct connection */
       
    81 	MsnSlpCall          *slpcall;   /**< The slpcall which initiated the direct connection */
       
    82 	char                *msg_body;  /**< The body of message sent by send_connection_info_msg_cb */
       
    83 	MsnSlpMessage       *prev_ack;  /**< The saved SLP ACK message */
       
    84 
       
    85 	MsnDirectConnNonceType nonce_type;         /**< The type of nonce hashing */
       
    86 	guchar                 nonce[16];          /**< The nonce used for handshake */
       
    87 	gchar                  nonce_hash[37];     /**< The hash of nonce */
       
    88 	gchar                  remote_nonce[37];   /**< The remote side's nonce */
       
    89 
       
    90 	PurpleNetworkListenData *listen_data;           /**< The pending socket creation request */
       
    91 	PurpleProxyConnectData  *connect_data;          /**< The pending connection attempt */
       
    92 	int                     listenfd;               /**< The socket we're listening for incoming connections */
       
    93 	guint                   listenfd_handle;        /**< The timeout handle for incoming connection */
       
    94 	guint                   connect_timeout_handle; /**< The timeout handle for outgoing connection */
       
    95 
       
    96 	int     fd;             /**< The direct connection socket */
       
    97 	guint   recv_handle;    /**< The incoming data callback handle */
       
    98 	guint   send_handle;    /**< The outgoing data callback handle */
       
    99 
       
   100 	gchar   *in_buffer; /**< The receive buffer */
       
   101 	int     in_size;    /**< The receive buffer size */
       
   102 	int     in_pos;     /**< The first free position in receive buffer */
       
   103 	GQueue  *out_queue; /**< The outgoing packet queue */
       
   104 	int     msg_pos;    /**< The position of next byte to be sent in the actual packet */
       
   105 
       
   106 	/** The callback used for sending information to the peer about the opened socket */
       
   107 	void (*send_connection_info_msg_cb)(MsnDirectConn *);
       
   108 
       
   109 	gchar   *ext_ip;    /**< Our external IP address */
       
   110 	int     ext_port;   /**< Our external port */
       
   111 
       
   112 	guint       timeout_handle;
       
   113 	gboolean    progress;
       
   114 
       
   115 	/*int   num_calls;*/  /**< The number of slpcalls using this direct connection */
       
   116 };
       
   117 
       
   118 /* Outgoing attempt */
       
   119 #define DC_OUTGOING_TIMEOUT (5)
       
   120 /* Time for internal + external connection attempts */
       
   121 #define DC_INCOMING_TIMEOUT (DC_OUTGOING_TIMEOUT * 3)
       
   122 /* Timeout for lack of activity */
       
   123 #define DC_TIMEOUT          (60)
       
   124 
       
   125 /*
       
   126  * Queues an MSN message to be sent via direct connection.
       
   127  */
       
   128 void
       
   129 msn_dc_enqueue_part(MsnDirectConn *dc, MsnSlpMessagePart *part);
       
   130 
       
   131 /*
       
   132  * Creates, initializes, and returns a new MsnDirectConn structure.
       
   133  */
       
   134 MsnDirectConn *
       
   135 msn_dc_new(MsnSlpCall *slpcall);
       
   136 
       
   137 /*
       
   138  * Destroys an MsnDirectConn structure. Frees every buffer allocated earlier
       
   139  * restores saved callbacks, etc.
       
   140  */
       
   141 void
       
   142 msn_dc_destroy(MsnDirectConn *dc);
       
   143 
       
   144 /*
       
   145  * Fallback to switchboard connection. Used when neither side is able to
       
   146  * create a listening socket.
       
   147  */
       
   148 void
       
   149 msn_dc_fallback_to_sb(MsnDirectConn *dc);
       
   150 
       
   151 /*
       
   152  * Increases the slpcall counter in DC. The direct connection remains open
       
   153  * until all slpcalls using it are destroyed.
       
   154  */
       
   155 void
       
   156 msn_dc_ref(MsnDirectConn *dc);
       
   157 
       
   158 /*
       
   159  * Decrease the slpcall counter in DC. The direct connection remains open
       
   160  * until all slpcalls using it are destroyed.
       
   161  */
       
   162 void
       
   163 msn_dc_unref(MsnDirectConn *dc);
       
   164 
       
   165 /*
       
   166  * Sends a direct connect INVITE message on the associated slplink
       
   167  * with the corresponding connection type and information.
       
   168  */
       
   169 void
       
   170 msn_dc_send_invite(MsnDirectConn *dc);
       
   171 
       
   172 /*
       
   173  * Sends a direct connect OK message as a response to an INVITE received earliaer
       
   174  * on the corresponding slplink.
       
   175  */
       
   176 void
       
   177 msn_dc_send_ok(MsnDirectConn *dc);
       
   178 
       
   179 /*
       
   180  * This callback will be called when we're successfully connected to
       
   181  * the remote host.
       
   182  */
       
   183 void
       
   184 msn_dc_connected_to_peer_cb(gpointer data, gint fd, const gchar *error_msg);
       
   185 
       
   186 /*
       
   187  * This callback will be called when we're unable to connect to
       
   188  * the remote host in DC_CONNECT_TIMEOUT seconds.
       
   189  */
       
   190 gboolean
       
   191 msn_dc_outgoing_connection_timeout_cb(gpointer data);
       
   192 
       
   193 /*
       
   194  * This callback will be called when the listening socket is successfully
       
   195  * created and its parameters (IP/port) are available.
       
   196  */
       
   197 void
       
   198 msn_dc_listen_socket_created_cb(int listenfd, gpointer data);
       
   199 
       
   200 #endif /* MSN_DIRECTCONN_H */