Changed 'operator' to 'roperator' to avoid C++ conflict.
[yaz-moved-to-github.git] / include / comstack.h
1 /*
2  * Copyright (c) 1995, Index Data.
3  *
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,
6  * provided that:
7  *
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.
11  *
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.
15  *
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
24  * OF THIS SOFTWARE.
25  *
26  * $Log: comstack.h,v $
27  * Revision 1.13  1995-11-01 13:54:33  quinn
28  * Minor adjustments
29  *
30  * Revision 1.12  1995/10/30  12:41:27  quinn
31  * Added hostname lookup for server.
32  *
33  * Revision 1.11  1995/09/29  17:12:01  quinn
34  * Smallish
35  *
36  * Revision 1.10  1995/09/29  17:01:48  quinn
37  * More Windows work
38  *
39  * Revision 1.9  1995/09/28  10:12:36  quinn
40  * Windows-support changes
41  *
42  * Revision 1.8  1995/09/27  15:02:46  quinn
43  * Modified function heads & prototypes.
44  *
45  * Revision 1.7  1995/06/19  12:38:24  quinn
46  * Reorganized include-files. Added small features.
47  *
48  * Revision 1.6  1995/05/30  10:54:51  quinn
49  * Added some backwards compatibility to the comstack (CS_SR->PROTO_SR)
50  *
51  * Revision 1.5  1995/05/29  08:11:31  quinn
52  * Moved oid from odr/asn to util.
53  *
54  * Revision 1.4  1995/05/16  08:50:29  quinn
55  * License, documentation, and memory fixes
56  *
57  * Revision 1.3  1995/04/20  15:12:44  quinn
58  * Cosmetic
59  *
60  * Revision 1.2  1995/04/17  11:28:17  quinn
61  * Smallish
62  *
63  * Revision 1.1  1995/03/30  09:39:40  quinn
64  * Moved .h files to include directory
65  *
66  * Revision 1.11  1995/03/27  08:36:05  quinn
67  * Some work on nonblocking operation in xmosi.c and rfct.c.
68  * Added protocol parameter to cs_create()
69  *
70  * Revision 1.10  1995/03/20  09:47:12  quinn
71  * Added server-side support to xmosi.c
72  * Fixed possible problems in rfct
73  * Other little mods
74  *
75  * Revision 1.9  1995/03/15  15:36:27  quinn
76  * Mods to support nonblocking I/O
77  *
78  * Revision 1.8  1995/03/14  17:00:07  quinn
79  * Bug-fixes - added tracing info to tcpip.c
80  *
81  * Revision 1.7  1995/03/14  10:28:35  quinn
82  * Adding server-side support to tcpip.c and fixing bugs in nonblocking I/O
83  *
84  * Revision 1.6  1995/03/07  16:29:45  quinn
85  * Various fixes.
86  *
87  * Revision 1.5  1995/03/07  10:39:31  quinn
88  * Added cs_fileno
89  *
90  * Revision 1.4  1995/03/06  16:49:29  adam
91  * COMSTACK type inspection possible with cs_type.
92  *
93  * Revision 1.3  1995/02/14  11:54:48  quinn
94  * Beginning to add full CCL.
95  *
96  * Revision 1.2  1995/02/10  18:58:10  quinn
97  * Fixed tcpip_get (formerly tcpip_read).
98  * Turned tst (cli) into a proper, event-driven thing.
99  *
100  * Revision 1.1  1995/02/09  15:51:51  quinn
101  * Works better now.
102  *
103  */
104
105 #ifndef COMSTACK_H
106 #define COMSTACK_H
107
108 #include <yconfig.h>
109 #include <oid.h>
110 #include <xmalloc.h>
111
112 #define COMSTACK_DEFAULT_TIMEOUT -1  /* not used yet */
113
114 struct comstack;
115 typedef struct comstack *COMSTACK;
116 typedef COMSTACK (*CS_TYPE)(int blocking, int protocol);
117
118 struct comstack
119 {
120     CS_TYPE type;
121     int cerrno;     /* current error code of this stack */
122     char *stackerr;/* current lower-layer error string, or null if none */
123     int iofile;    /* UNIX file descriptor for iochannel */
124     int timeout;   /* how long to wait for trailing blocks (ignored for now) */
125     void *private; /* state info for lower stack */
126     int more;      /* connection has extra data in buffer */
127     int state;     /* current state */
128 #define CS_UNBND      0
129 #define CS_IDLE       1
130 #define CS_INCON      2
131 #define CS_OUTCON     3
132 #define CS_DATAXFER   4
133     int newfd;     /* storing new descriptor between listen and accept */
134     int blocking;  /* is this link (supposed to be) blocking? */
135     int event;     /* current event */
136 #define CS_NONE       0
137 #define CS_CONNECT    1
138 #define CS_DISCON     2
139 #define CS_LISTEN     3
140 #define CS_DATA       4
141     enum oid_proto protocol;  /* what application protocol are we talking? */
142     int (*f_look)(COMSTACK handle);
143     int (*f_put)(COMSTACK handle, char *buf, int size);
144     int (*f_get)(COMSTACK handle, char **buf, int *bufsize);
145     int (*f_more)(COMSTACK handle);
146     int (*f_connect)(COMSTACK handle, void *address);
147     int (*f_rcvconnect)(COMSTACK handle);
148     int (*f_bind)(COMSTACK handle, void *address, int mode);
149 #define CS_CLIENT 0
150 #define CS_SERVER 1
151     int (*f_listen)(COMSTACK handle, char *addrp, int *addrlen);
152     COMSTACK (*f_accept)(COMSTACK handle);
153     int (*f_close)(COMSTACK handle);
154     char *(*f_addrstr)(COMSTACK handle);
155 };
156
157 #define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size))
158 #define cs_get(handle, buf, size) ((*(handle)->f_get)(handle, buf, size))
159 #define cs_more(handle) ((*(handle)->f_more)(handle))
160 #define cs_connect(handle, address) ((*(handle)->f_connect)(handle, address))
161 #define cs_rcvconnect(handle) ((*(handle)->f_rcvconnect)(handle))
162 #define cs_bind(handle, ad, mo) ((*(handle)->f_bind)(handle, ad, mo))
163 #define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al))
164 #define cs_accept(handle) ((*(handle)->f_accept)(handle))
165 #define cs_close(handle) ((*(handle)->f_close)(handle))
166 #define cs_create(type, blocking, proto) ((*type)(blocking, proto))
167 #define cs_type(handle) ((handle)->type)
168 #define cs_fileno(handle) ((handle)->iofile)
169 #define cs_stackerr(handle) ((handle)->stackerr)
170 #define cs_getstate(handle) ((handle)->getstate)
171 #define cs_errno(handle) ((handle)->cerrno)
172 #define cs_getproto(handle) ((handle)->protocol)
173 #define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle))
174
175 const char *cs_strerror(COMSTACK h);
176 const char *cs_errmsg(int n);
177
178 /*
179  * error management.
180  */
181
182 #define CSNONE     0
183 #define CSYSERR    1
184 #define CSOUTSTATE 2
185 #define CSNODATA   3
186 #define CSWRONGBUF 4
187
188 extern char *cs_errlist[];
189
190 /* backwards compatibility */
191 #define CS_SR     PROTO_SR
192 #define CS_Z3950  PROTO_Z3950
193
194 #endif