Mercurial > pidgin
annotate src/protocols/novell/nmconn.h @ 9125:668ffb8fec00
[gaim-migrate @ 9902]
(12:53:05) nosnilmot: LSchiere: not majorly important, but the pref changes
listed in the ChangeLog are out of sync
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sun, 30 May 2004 16:54:40 +0000 |
| parents | 6663ad2386d9 |
| children | d77537e8bfe5 |
| rev | line source |
|---|---|
| 8675 | 1 /* |
| 2 * nmconn.h | |
| 3 * | |
| 8933 | 4 * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
| 5 * | |
| 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. | |
| 8675 | 9 * |
| 8933 | 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. | |
|
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
14 * |
| 8933 | 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 8675 | 18 * |
| 19 */ | |
| 20 | |
| 21 #ifndef __NM_CONN_H__ | |
| 22 #define __NM_CONN_H__ | |
| 23 | |
| 24 typedef struct _NMConn NMConn; | |
| 25 typedef struct _NMSSLConn NMSSLConn; | |
| 26 | |
| 27 #include "nmfield.h" | |
| 28 #include "nmuser.h" | |
| 29 | |
| 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); | |
| 32 | |
| 33 struct _NMConn | |
| 34 { | |
| 35 | |
| 36 /* The address of the server that we are connecting to. */ | |
| 37 char *addr; | |
| 38 | |
| 39 /* The port that we are connecting to. */ | |
| 40 int port; | |
| 41 | |
| 42 /* The file descriptor of the socket for the connection. */ | |
| 43 int fd; | |
| 44 | |
| 45 /* The transaction counter. */ | |
| 46 int trans_id; | |
| 47 | |
| 48 /* A list of requests currently awaiting a response. */ | |
| 49 GSList *requests; | |
| 50 | |
| 51 /* Are we connected? TRUE if so, FALSE if not. */ | |
| 52 gboolean connected; | |
| 53 | |
| 54 /* Are we running in secure mode? */ | |
| 55 gboolean use_ssl; | |
| 56 | |
| 57 /* Have we been redirected? */ | |
| 58 gboolean redirect; | |
| 59 | |
| 60 /* SSL connection */ | |
| 61 NMSSLConn *ssl_conn; | |
| 62 | |
| 63 }; | |
| 64 | |
| 65 struct _NMSSLConn | |
| 66 { | |
| 67 | |
| 68 /* Data to pass to the callbacks */ | |
| 69 gpointer data; | |
| 70 | |
| 71 /* Callbacks for reading/writing */ | |
| 72 nm_ssl_read_cb read; | |
| 73 nm_ssl_write_cb write; | |
| 74 | |
| 75 }; | |
| 76 | |
| 77 /** | |
| 78 * Write len bytes from the given buffer. | |
| 79 * | |
| 80 * @param conn The connection to write to. | |
| 81 * @param buff The buffer to write from. | |
| 82 * @param len The number of bytes to write. | |
| 83 * | |
| 84 * @return The number of bytes written. | |
| 85 */ | |
| 86 int nm_tcp_write(NMConn * conn, const void *buff, int len); | |
| 87 | |
| 88 /** | |
| 89 * Read at most len bytes into the given buffer. | |
| 90 * | |
| 91 * @param conn The connection to read from. | |
| 92 * @param buff The buffer to write to. | |
| 93 * @param len The maximum number of bytes to read. | |
| 94 * | |
| 95 * @return The number of bytes read. | |
| 96 */ | |
| 97 int nm_tcp_read(NMConn * conn, void *buff, int len); | |
| 98 | |
| 99 /** | |
| 100 * Read exactly len bytes into the given buffer. | |
| 101 * | |
| 102 * @param conn The connection to read from. | |
| 103 * @param buff The buffer to write to. | |
| 104 * @param len The number of bytes to read. | |
| 105 * | |
| 106 * @return NM_OK on success, NMERR_TCP_READ if read fails. | |
| 107 */ | |
| 108 NMERR_T nm_read_all(NMConn * conn, char *buf, int len); | |
| 109 | |
| 110 /** | |
| 8874 | 111 * Read a 32 bit value and convert it to the host byte order. |
| 112 * | |
| 113 * @param conn The connection to read from. | |
| 114 * @param val A pointer to unsigned 32 bit integer | |
| 115 * | |
| 116 * @return NM_OK on success, NMERR_TCP_READ if read fails. | |
| 117 */ | |
| 118 NMERR_T | |
| 119 nm_read_uint32(NMConn *conn, guint32 *val); | |
| 120 | |
| 121 /** | |
| 122 * Read a 16 bit value and convert it to the host byte order. | |
| 123 * | |
| 124 * @param conn The connection to read from. | |
| 125 * @param val A pointer to unsigned 16 bit integer | |
| 126 * | |
| 127 * @return NM_OK on success, NMERR_TCP_READ if read fails. | |
| 128 */ | |
| 129 NMERR_T | |
| 130 nm_read_uint16(NMConn *conn, guint16 *val); | |
| 131 | |
| 132 /** | |
| 8675 | 133 * Dispatch a request to the server. |
| 134 * | |
| 135 * @param conn The connection. | |
| 136 * @param cmd The request to dispatch. | |
| 137 * @param fields The field list for the request. | |
| 138 * @param req The request. Should be freed with nm_release_request. | |
| 139 * | |
| 140 * @return NM_OK on success. | |
| 141 */ | |
| 142 NMERR_T nm_send_request(NMConn * conn, char *cmd, NMField * fields, | |
| 143 NMRequest ** req); | |
| 144 | |
| 145 /** | |
| 146 * Write out the given field list. | |
| 147 * | |
| 148 * @param conn The connection to write to. | |
| 149 * @param fields The field list to write. | |
| 150 * | |
| 151 * @return NM_OK on success. | |
| 152 */ | |
| 153 NMERR_T nm_write_fields(NMConn * conn, NMField * fields); | |
| 154 | |
| 155 /** | |
| 156 * Read the headers for a response. | |
| 157 * | |
| 158 * @param conn The connection to read from. | |
| 159 * | |
| 160 * @return NM_OK on success. | |
| 161 */ | |
| 162 NMERR_T nm_read_header(NMConn * conn); | |
| 163 | |
| 164 /** | |
| 165 * Read a field list from the connection. | |
| 166 * | |
| 167 * @param conn The connection to read from. | |
| 168 * @param count The maximum number of fields to read (or -1 for no max). | |
| 169 * @param fields The field list. This is an out param. It | |
| 170 * should be freed by calling nm_free_fields | |
| 171 * when finished. | |
| 172 * | |
| 173 * @return NM_OK on success. | |
| 174 */ | |
| 175 NMERR_T nm_read_fields(NMConn * conn, int count, NMField ** fields); | |
| 176 | |
| 177 /** | |
| 178 * Add a request to the connections request list. | |
| 179 * | |
| 180 * @param conn The connection. | |
| 181 * @param request The request to add to the list. | |
| 182 */ | |
| 183 void nm_conn_add_request_item(NMConn * conn, NMRequest * request); | |
| 184 | |
| 185 /** | |
| 186 * Remove a request from the connections list. | |
| 187 * | |
| 188 * @param conn The connection. | |
| 189 * @param request The request to remove from the list. | |
| 190 */ | |
| 191 void nm_conn_remove_request_item(NMConn * conn, NMRequest * request); | |
| 192 | |
| 193 /** | |
| 194 * Find the request with the given transaction id in the connections | |
| 195 * request list. | |
| 196 * | |
| 197 * @param conn The connection. | |
| 198 * @param trans_id The transaction id of the request to return. | |
| 199 * | |
| 200 * @return The request, or NULL if a matching request is not | |
| 201 * found. | |
| 202 */ | |
| 203 NMRequest *nm_conn_find_request(NMConn * conn, int trans_id); | |
| 204 | |
| 205 /** | |
| 206 * Get the server address for the connection. | |
| 207 * | |
| 208 * @param conn The connection. | |
| 209 * | |
| 210 * @return The server address for the connection. | |
| 211 * | |
| 212 */ | |
| 213 const char *nm_conn_get_addr(NMConn * conn); | |
| 214 | |
| 215 /** | |
| 216 * Get the port for the connection. | |
| 217 * | |
| 218 * @param conn The connection. | |
| 219 * | |
| 220 * @return The port that we are connected to. | |
| 221 */ | |
| 222 int nm_conn_get_port(NMConn * conn); | |
| 223 | |
| 224 #endif |
