2 * Copyright (c) 1995-1998, Index Data.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation, in whole or in part, for any purpose, is hereby granted,
8 * 1. This copyright and permission notice appear in all copies of the
9 * software and its documentation. Notices of copyright or attribution
10 * which appear at the beginning of any file must remain unchanged.
12 * 2. The name of Index Data or the individual authors may not be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
20 * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
22 * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 * $Log: comstack.h,v $
27 * Revision 1.22 1998-06-22 11:32:37 adam
28 * Added 'conditional cs_listen' feature.
30 * Revision 1.21 1998/05/20 09:52:39 adam
31 * Removed 'dead' definition.
33 * Revision 1.20 1998/05/18 13:06:55 adam
34 * Changed the way attribute sets are handled by the retriaval module.
35 * Extended Explain conversion / schema.
36 * Modified server and client to work with ASN.1 compiled protocol handlers.
38 * Revision 1.19 1997/09/29 07:16:14 adam
39 * Array cs_errlist no longer global.
41 * Revision 1.18 1997/09/17 12:10:31 adam
44 * Revision 1.17 1997/09/01 08:49:47 adam
45 * New windows NT/95 port using MSV5.0. To export DLL functions the
46 * YAZ_EXPORT modifier was added. Defined in yconfig.h.
48 * Revision 1.16 1997/05/14 06:53:37 adam
51 * Revision 1.15 1996/07/06 19:58:32 quinn
52 * System headerfiles gathered in yconfig
54 * Revision 1.14 1996/02/10 12:23:41 quinn
55 * Enable inetd operations fro TCP/IP stack
57 * Revision 1.13 1995/11/01 13:54:33 quinn
60 * Revision 1.12 1995/10/30 12:41:27 quinn
61 * Added hostname lookup for server.
63 * Revision 1.11 1995/09/29 17:12:01 quinn
66 * Revision 1.10 1995/09/29 17:01:48 quinn
69 * Revision 1.9 1995/09/28 10:12:36 quinn
70 * Windows-support changes
72 * Revision 1.8 1995/09/27 15:02:46 quinn
73 * Modified function heads & prototypes.
75 * Revision 1.7 1995/06/19 12:38:24 quinn
76 * Reorganized include-files. Added small features.
78 * Revision 1.6 1995/05/30 10:54:51 quinn
79 * Added some backwards compatibility to the comstack (CS_SR->PROTO_SR)
81 * Revision 1.5 1995/05/29 08:11:31 quinn
82 * Moved oid from odr/asn to util.
84 * Revision 1.4 1995/05/16 08:50:29 quinn
85 * License, documentation, and memory fixes
87 * Revision 1.3 1995/04/20 15:12:44 quinn
90 * Revision 1.2 1995/04/17 11:28:17 quinn
93 * Revision 1.1 1995/03/30 09:39:40 quinn
94 * Moved .h files to include directory
96 * Revision 1.11 1995/03/27 08:36:05 quinn
97 * Some work on nonblocking operation in xmosi.c and rfct.c.
98 * Added protocol parameter to cs_create()
100 * Revision 1.10 1995/03/20 09:47:12 quinn
101 * Added server-side support to xmosi.c
102 * Fixed possible problems in rfct
105 * Revision 1.9 1995/03/15 15:36:27 quinn
106 * Mods to support nonblocking I/O
108 * Revision 1.8 1995/03/14 17:00:07 quinn
109 * Bug-fixes - added tracing info to tcpip.c
111 * Revision 1.7 1995/03/14 10:28:35 quinn
112 * Adding server-side support to tcpip.c and fixing bugs in nonblocking I/O
114 * Revision 1.6 1995/03/07 16:29:45 quinn
117 * Revision 1.5 1995/03/07 10:39:31 quinn
120 * Revision 1.4 1995/03/06 16:49:29 adam
121 * COMSTACK type inspection possible with cs_type.
123 * Revision 1.3 1995/02/14 11:54:48 quinn
124 * Beginning to add full CCL.
126 * Revision 1.2 1995/02/10 18:58:10 quinn
127 * Fixed tcpip_get (formerly tcpip_read).
128 * Turned tst (cli) into a proper, event-driven thing.
130 * Revision 1.1 1995/02/09 15:51:51 quinn
147 #define COMSTACK_DEFAULT_TIMEOUT -1 /* not used yet */
150 typedef struct comstack *COMSTACK;
151 typedef COMSTACK (*CS_TYPE)(int s, int blocking, int protocol);
156 int cerrno; /* current error code of this stack */
157 char *stackerr;/* current lower-layer error string, or null if none */
158 int iofile; /* UNIX file descriptor for iochannel */
159 int timeout; /* how long to wait for trailing blocks (ignored for now) */
160 void *cprivate;/* state info for lower stack */
161 int more; /* connection has extra data in buffer */
162 int state; /* current state */
167 #define CS_DATAXFER 4
168 int newfd; /* storing new descriptor between listen and accept */
169 int blocking; /* is this link (supposed to be) blocking? */
170 int event; /* current event */
176 enum oid_proto protocol; /* what application protocol are we talking? */
177 int (*f_put)(COMSTACK handle, char *buf, int size);
178 int (*f_get)(COMSTACK handle, char **buf, int *bufsize);
179 int (*f_more)(COMSTACK handle);
180 int (*f_connect)(COMSTACK handle, void *address);
181 int (*f_rcvconnect)(COMSTACK handle);
182 int (*f_bind)(COMSTACK handle, void *address, int mode);
185 int (*f_listen)(COMSTACK h, char *raddr, int *addrlen,
186 int (*check_ip)(void *cd, const char *a, int len, int type),
188 COMSTACK (*f_accept)(COMSTACK handle);
189 int (*f_close)(COMSTACK handle);
190 char *(*f_addrstr)(COMSTACK handle);
191 void *(*f_straddr)(COMSTACK handle, const char *str);
194 #define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size))
195 #define cs_get(handle, buf, size) ((*(handle)->f_get)(handle, buf, size))
196 #define cs_more(handle) ((*(handle)->f_more)(handle))
197 #define cs_connect(handle, address) ((*(handle)->f_connect)(handle, address))
198 #define cs_rcvconnect(handle) ((*(handle)->f_rcvconnect)(handle))
199 #define cs_bind(handle, ad, mo) ((*(handle)->f_bind)(handle, ad, mo))
200 #define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al, 0, 0))
201 #define cs_listen_check(handle, ap, al, cf, cd) ((*(handle)->f_listen)(handle, ap, al, cf, cd))
202 #define cs_accept(handle) ((*(handle)->f_accept)(handle))
203 #define cs_close(handle) ((*(handle)->f_close)(handle))
204 #define cs_create(type, blocking, proto) ((*type)(-1, blocking, proto))
205 #define cs_createbysocket(sock, type, blocking, proto) \
206 ((*type)(sock, blocking, proto))
207 #define cs_type(handle) ((handle)->type)
208 #define cs_fileno(handle) ((handle)->iofile)
209 #define cs_stackerr(handle) ((handle)->stackerr)
210 #define cs_getstate(handle) ((handle)->getstate)
211 #define cs_errno(handle) ((handle)->cerrno)
212 #define cs_getproto(handle) ((handle)->protocol)
213 #define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle))
214 #define cs_straddr(handle, str) ((*(handle)->f_straddr)(handle, str))
216 YAZ_EXPORT const char *cs_strerror(COMSTACK h);
217 YAZ_EXPORT const char *cs_errmsg(int n);
230 /* backwards compatibility */
231 #define CS_SR PROTO_SR
232 #define CS_Z3950 PROTO_Z3950