2 * @file servconn.h Server connection functions
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
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.
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.
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
24 #ifndef _MSN_SERVCONN_H_
25 #define _MSN_SERVCONN_H_
27 typedef struct _MsnServConn MsnServConn;
36 * Connection error types.
40 MSN_SERVCONN_ERROR_NONE,
41 MSN_SERVCONN_ERROR_CONNECT,
42 MSN_SERVCONN_ERROR_WRITE,
43 MSN_SERVCONN_ERROR_READ
62 MsnServConnType type; /**< The type of this connection. */
63 MsnSession *session; /**< The MSN session of this connection. */
64 MsnCmdProc *cmdproc; /**< The command processor of this connection. */
66 PurpleProxyConnectData *connect_data;
68 gboolean connected; /**< A flag that states if it's connected. */
69 gboolean processing; /**< A flag that states if something is working
70 with this connection. */
71 gboolean wasted; /**< A flag that states if it should be destroyed. */
73 char *host; /**< The host this connection is connected or should be
75 int num; /**< A number id of this connection. */
77 MsnHttpConn *httpconn; /**< The HTTP connection this connection should use. */
79 int fd; /**< The connection's file descriptor. */
80 int inpa; /**< The connection's input handler. */
82 char *rx_buf; /**< The receive buffer. */
83 int rx_len; /**< The receive buffer lenght. */
85 size_t payload_len; /**< The length of the payload.
86 It's only set when we've received a command that
89 PurpleCircBuffer *tx_buf;
94 void (*connect_cb)(MsnServConn *); /**< The callback to call when connecting. */
95 void (*disconnect_cb)(MsnServConn *); /**< The callback to call when disconnecting. */
96 void (*destroy_cb)(MsnServConn *); /**< The callback to call when destroying. */
100 * Creates a new connection object.
102 * @param session The session.
103 * @param type The type of the connection.
105 MsnServConn *msn_servconn_new(MsnSession *session, MsnServConnType type);
108 * Destroys a connection object.
110 * @param servconn The connection.
112 void msn_servconn_destroy(MsnServConn *servconn);
115 * Connects to a host.
117 * @param servconn The connection.
118 * @param host The host.
119 * @param port The port.
120 * @param force Force this servconn to connect to a new server.
122 gboolean msn_servconn_connect(MsnServConn *servconn, const char *host, int port,
128 * @param servconn The connection.
130 void msn_servconn_disconnect(MsnServConn *servconn);
133 * Sets the connect callback.
135 * @param servconn The servconn.
136 * @param connect_cb The connect callback.
138 void msn_servconn_set_connect_cb(MsnServConn *servconn,
139 void (*connect_cb)(MsnServConn *));
141 * Sets the disconnect callback.
143 * @param servconn The servconn.
144 * @param disconnect_cb The disconnect callback.
146 void msn_servconn_set_disconnect_cb(MsnServConn *servconn,
147 void (*disconnect_cb)(MsnServConn *));
149 * Sets the destroy callback.
151 * @param servconn The servconn that's being destroyed.
152 * @param destroy_cb The destroy callback.
154 void msn_servconn_set_destroy_cb(MsnServConn *servconn,
155 void (*destroy_cb)(MsnServConn *));
158 * Writes a chunck of data to the servconn.
160 * @param servconn The servconn.
161 * @param buf The data to write.
162 * @param size The size of the data.
164 gssize msn_servconn_write(MsnServConn *servconn, const char *buf,
168 * Function to call whenever an error related to a switchboard occurs.
170 * @param servconn The servconn.
171 * @param error The error that happened.
173 void msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error,
177 * Process the data in servconn->rx_buf. This is called after reading
178 * data from the socket.
180 * @param servconn The servconn.
182 void msn_servconn_process_data(MsnServConn *servconn);
185 * Set a idle timeout fot this servconn
187 * @param servconn The servconn
188 * @param seconds The idle timeout in seconds
190 void msn_servconn_set_idle_timeout(MsnServConn *servconn, guint seconds);
192 #endif /* _MSN_SERVCONN_H_ */