4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 #ifndef PURPLE_NOVELL_NMCONN_H
22 #define PURPLE_NOVELL_NMCONN_H
24 typedef struct _NMConn NMConn
;
25 typedef struct _NMSSLConn NMSSLConn
;
30 typedef int (*nm_ssl_read_cb
) (gpointer ssl_data
, void *buff
, int len
);
31 typedef int (*nm_ssl_write_cb
) (gpointer ssl_data
, const void *buff
, int len
);
36 /* The address of the server that we are connecting to. */
39 /* The port that we are connecting to. */
42 /* The file descriptor of the socket for the connection. */
45 /* The transaction counter. */
48 /* A list of requests currently awaiting a response. */
51 /* Are we connected? TRUE if so, FALSE if not. */
54 /* Are we running in secure mode? */
57 /* Have we been redirected? */
68 /* Data to pass to the callbacks */
71 /* Callbacks for reading/writing */
73 nm_ssl_write_cb write
;
78 * Allocate a new NMConn struct
80 * @param The address of the server that we are connecting to.
81 * @param The port that we are connecting to.
83 * @return A pointer to a newly allocated NMConn struct, should
84 * be freed by calling nm_release_conn()
86 NMConn
*nm_create_conn(const char *addr
, int port
);
91 * @param Pointer to the NMConn to release.
94 void nm_release_conn(NMConn
*conn
);
97 * Write len bytes from the given buffer.
99 * @param conn The connection to write to.
100 * @param buff The buffer to write from.
101 * @param len The number of bytes to write.
103 * @return The number of bytes written.
105 int nm_tcp_write(NMConn
* conn
, const void *buff
, int len
);
108 * Read at most len bytes into the given buffer.
110 * @param conn The connection to read from.
111 * @param buff The buffer to write to.
112 * @param len The maximum number of bytes to read.
114 * @return The number of bytes read.
116 int nm_tcp_read(NMConn
* conn
, void *buff
, int len
);
119 * Read exactly len bytes into the given buffer.
121 * @param conn The connection to read from.
122 * @param buff The buffer to write to.
123 * @param len The number of bytes to read.
125 * @return NM_OK on success, NMERR_TCP_READ if read fails.
127 NMERR_T
nm_read_all(NMConn
* conn
, char *buf
, int len
);
130 * Read a 32 bit value and convert it to the host byte order.
132 * @param conn The connection to read from.
133 * @param val A pointer to unsigned 32 bit integer
135 * @return NM_OK on success, NMERR_TCP_READ if read fails.
138 nm_read_uint32(NMConn
*conn
, guint32
*val
);
141 * Read a 16 bit value and convert it to the host byte order.
143 * @param conn The connection to read from.
144 * @param val A pointer to unsigned 16 bit integer
146 * @return NM_OK on success, NMERR_TCP_READ if read fails.
149 nm_read_uint16(NMConn
*conn
, guint16
*val
);
152 * Dispatch a request to the server.
154 * @param conn The connection.
155 * @param cmd The request to dispatch.
156 * @param fields The field list for the request.
157 * @param cb The response callback for the new request object.
158 * @param data The user defined data for the request (to be passed to the resp cb).
159 * @param req The request. Should be freed with nm_release_request.
161 * @return NM_OK on success.
164 nm_send_request(NMConn
*conn
, char *cmd
, NMField
*fields
,
165 nm_response_cb cb
, gpointer data
, NMRequest
**request
);
168 * Write out the given field list.
170 * @param conn The connection to write to.
171 * @param fields The field list to write.
173 * @return NM_OK on success.
175 NMERR_T
nm_write_fields(NMConn
* conn
, NMField
* fields
);
178 * Read the headers for a response.
180 * @param conn The connection to read from.
182 * @return NM_OK on success.
184 NMERR_T
nm_read_header(NMConn
* conn
);
187 * Read a field list from the connection.
189 * @param conn The connection to read from.
190 * @param count The maximum number of fields to read (or -1 for no max).
191 * @param fields The field list. This is an out param. It
192 * should be freed by calling nm_free_fields
195 * @return NM_OK on success.
197 NMERR_T
nm_read_fields(NMConn
* conn
, int count
, NMField
** fields
);
200 * Add a request to the connections request list.
202 * @param conn The connection.
203 * @param request The request to add to the list.
205 void nm_conn_add_request_item(NMConn
* conn
, NMRequest
* request
);
208 * Remove a request from the connections list.
210 * @param conn The connection.
211 * @param request The request to remove from the list.
213 void nm_conn_remove_request_item(NMConn
* conn
, NMRequest
* request
);
216 * Find the request with the given transaction id in the connections
219 * @param conn The connection.
220 * @param trans_id The transaction id of the request to return.
222 * @return The request, or NULL if a matching request is not
225 NMRequest
*nm_conn_find_request(NMConn
* conn
, int trans_id
);
228 * Get the server address for the connection.
230 * @param conn The connection.
232 * @return The server address for the connection.
235 const char *nm_conn_get_addr(NMConn
* conn
);
238 * Get the port for the connection.
240 * @param conn The connection.
242 * @return The port that we are connected to.
244 int nm_conn_get_port(NMConn
* conn
);
246 #endif /* PURPLE_NOVELL_NMCONN_H */