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