Sat, 17 Apr 2004 18:29:20 +0000
[gaim-migrate @ 9437]
Excess whitespace bad, especially *that* much.
| 8675 | 1 | /* |
| 2 | * nmconn.h | |
| 3 | * | |
| 4 | * Copyright © 2004 Unpublished Work of Novell, Inc. All Rights Reserved. | |
| 5 | * | |
| 6 | * THIS WORK IS AN UNPUBLISHED WORK OF NOVELL, INC. NO PART OF THIS WORK MAY BE | |
| 7 | * USED, PRACTICED, PERFORMED, COPIED, DISTRIBUTED, REVISED, MODIFIED, | |
| 8 | * TRANSLATED, ABRIDGED, CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, | |
| 9 | * RECAST, TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF NOVELL, | |
| 10 | * INC. ANY USE OR EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT | |
| 11 | * THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY. | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
12 | * |
| 8675 | 13 | * AS BETWEEN [GAIM] AND NOVELL, NOVELL GRANTS [GAIM] THE RIGHT TO REPUBLISH |
| 14 | * THIS WORK UNDER THE GPL (GNU GENERAL PUBLIC LICENSE) WITH ALL RIGHTS AND | |
| 15 | * LICENSES THEREUNDER. IF YOU HAVE RECEIVED THIS WORK DIRECTLY OR INDIRECTLY | |
| 16 | * FROM [GAIM] AS PART OF SUCH A REPUBLICATION, YOU HAVE ALL RIGHTS AND LICENSES | |
| 17 | * GRANTED BY [GAIM] UNDER THE GPL. IN CONNECTION WITH SUCH A REPUBLICATION, IF | |
| 18 | * ANYTHING IN THIS NOTICE CONFLICTS WITH THE TERMS OF THE GPL, SUCH TERMS | |
| 19 | * PREVAIL. | |
| 20 | * | |
| 21 | */ | |
| 22 | ||
| 23 | #ifndef __NM_CONN_H__ | |
| 24 | #define __NM_CONN_H__ | |
| 25 | ||
| 26 | typedef struct _NMConn NMConn; | |
| 27 | typedef struct _NMSSLConn NMSSLConn; | |
| 28 | ||
| 29 | #include "nmfield.h" | |
| 30 | #include "nmuser.h" | |
| 31 | ||
| 32 | typedef int (*nm_ssl_read_cb) (gpointer ssl_data, void *buff, int len); | |
| 33 | typedef int (*nm_ssl_write_cb) (gpointer ssl_data, const void *buff, int len); | |
| 34 | ||
| 35 | struct _NMConn | |
| 36 | { | |
| 37 | ||
| 38 | /* The address of the server that we are connecting to. */ | |
| 39 | char *addr; | |
| 40 | ||
| 41 | /* The port that we are connecting to. */ | |
| 42 | int port; | |
| 43 | ||
| 44 | /* The file descriptor of the socket for the connection. */ | |
| 45 | int fd; | |
| 46 | ||
| 47 | /* The transaction counter. */ | |
| 48 | int trans_id; | |
| 49 | ||
| 50 | /* A list of requests currently awaiting a response. */ | |
| 51 | GSList *requests; | |
| 52 | ||
| 53 | /* Are we connected? TRUE if so, FALSE if not. */ | |
| 54 | gboolean connected; | |
| 55 | ||
| 56 | /* Are we running in secure mode? */ | |
| 57 | gboolean use_ssl; | |
| 58 | ||
| 59 | /* Have we been redirected? */ | |
| 60 | gboolean redirect; | |
| 61 | ||
| 62 | /* SSL connection */ | |
| 63 | NMSSLConn *ssl_conn; | |
| 64 | ||
| 65 | }; | |
| 66 | ||
| 67 | struct _NMSSLConn | |
| 68 | { | |
| 69 | ||
| 70 | /* Data to pass to the callbacks */ | |
| 71 | gpointer data; | |
| 72 | ||
| 73 | /* Callbacks for reading/writing */ | |
| 74 | nm_ssl_read_cb read; | |
| 75 | nm_ssl_write_cb write; | |
| 76 | ||
| 77 | }; | |
| 78 | ||
| 79 | /** | |
| 80 | * Write len bytes from the given buffer. | |
| 81 | * | |
| 82 | * @param conn The connection to write to. | |
| 83 | * @param buff The buffer to write from. | |
| 84 | * @param len The number of bytes to write. | |
| 85 | * | |
| 86 | * @return The number of bytes written. | |
| 87 | */ | |
| 88 | int nm_tcp_write(NMConn * conn, const void *buff, int len); | |
| 89 | ||
| 90 | /** | |
| 91 | * Read at most len bytes into the given buffer. | |
| 92 | * | |
| 93 | * @param conn The connection to read from. | |
| 94 | * @param buff The buffer to write to. | |
| 95 | * @param len The maximum number of bytes to read. | |
| 96 | * | |
| 97 | * @return The number of bytes read. | |
| 98 | */ | |
| 99 | int nm_tcp_read(NMConn * conn, void *buff, int len); | |
| 100 | ||
| 101 | /** | |
| 102 | * Read exactly len bytes into the given buffer. | |
| 103 | * | |
| 104 | * @param conn The connection to read from. | |
| 105 | * @param buff The buffer to write to. | |
| 106 | * @param len The number of bytes to read. | |
| 107 | * | |
| 108 | * @return NM_OK on success, NMERR_TCP_READ if read fails. | |
| 109 | */ | |
| 110 | NMERR_T nm_read_all(NMConn * conn, char *buf, int len); | |
| 111 | ||
| 112 | /** | |
| 113 | * Dispatch a request to the server. | |
| 114 | * | |
| 115 | * @param conn The connection. | |
| 116 | * @param cmd The request to dispatch. | |
| 117 | * @param fields The field list for the request. | |
| 118 | * @param req The request. Should be freed with nm_release_request. | |
| 119 | * | |
| 120 | * @return NM_OK on success. | |
| 121 | */ | |
| 122 | NMERR_T nm_send_request(NMConn * conn, char *cmd, NMField * fields, | |
| 123 | NMRequest ** req); | |
| 124 | ||
| 125 | /** | |
| 126 | * Write out the given field list. | |
| 127 | * | |
| 128 | * @param conn The connection to write to. | |
| 129 | * @param fields The field list to write. | |
| 130 | * | |
| 131 | * @return NM_OK on success. | |
| 132 | */ | |
| 133 | NMERR_T nm_write_fields(NMConn * conn, NMField * fields); | |
| 134 | ||
| 135 | /** | |
| 136 | * Read the headers for a response. | |
| 137 | * | |
| 138 | * @param conn The connection to read from. | |
| 139 | * | |
| 140 | * @return NM_OK on success. | |
| 141 | */ | |
| 142 | NMERR_T nm_read_header(NMConn * conn); | |
| 143 | ||
| 144 | /** | |
| 145 | * Read a field list from the connection. | |
| 146 | * | |
| 147 | * @param conn The connection to read from. | |
| 148 | * @param count The maximum number of fields to read (or -1 for no max). | |
| 149 | * @param fields The field list. This is an out param. It | |
| 150 | * should be freed by calling nm_free_fields | |
| 151 | * when finished. | |
| 152 | * | |
| 153 | * @return NM_OK on success. | |
| 154 | */ | |
| 155 | NMERR_T nm_read_fields(NMConn * conn, int count, NMField ** fields); | |
| 156 | ||
| 157 | /** | |
| 158 | * Add a request to the connections request list. | |
| 159 | * | |
| 160 | * @param conn The connection. | |
| 161 | * @param request The request to add to the list. | |
| 162 | */ | |
| 163 | void nm_conn_add_request_item(NMConn * conn, NMRequest * request); | |
| 164 | ||
| 165 | /** | |
| 166 | * Remove a request from the connections list. | |
| 167 | * | |
| 168 | * @param conn The connection. | |
| 169 | * @param request The request to remove from the list. | |
| 170 | */ | |
| 171 | void nm_conn_remove_request_item(NMConn * conn, NMRequest * request); | |
| 172 | ||
| 173 | /** | |
| 174 | * Find the request with the given transaction id in the connections | |
| 175 | * request list. | |
| 176 | * | |
| 177 | * @param conn The connection. | |
| 178 | * @param trans_id The transaction id of the request to return. | |
| 179 | * | |
| 180 | * @return The request, or NULL if a matching request is not | |
| 181 | * found. | |
| 182 | */ | |
| 183 | NMRequest *nm_conn_find_request(NMConn * conn, int trans_id); | |
| 184 | ||
| 185 | /** | |
| 186 | * Get the server address for the connection. | |
| 187 | * | |
| 188 | * @param conn The connection. | |
| 189 | * | |
| 190 | * @return The server address for the connection. | |
| 191 | * | |
| 192 | */ | |
| 193 | const char *nm_conn_get_addr(NMConn * conn); | |
| 194 | ||
| 195 | /** | |
| 196 | * Get the port for the connection. | |
| 197 | * | |
| 198 | * @param conn The connection. | |
| 199 | * | |
| 200 | * @return The port that we are connected to. | |
| 201 | */ | |
| 202 | int nm_conn_get_port(NMConn * conn); | |
| 203 | ||
| 204 | #endif |