00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00033 #ifndef COMSTACK_H
00034 #define COMSTACK_H
00035
00036 #include <yaz/yconfig.h>
00037 #include <yaz/oid_util.h>
00038 #include <yaz/xmalloc.h>
00039
00040 YAZ_BEGIN_CDECL
00041
00042 #define COMSTACK_DEFAULT_TIMEOUT -1
00043
00044 struct comstack;
00045 typedef struct comstack *COMSTACK;
00046 typedef COMSTACK (*CS_TYPE)(int s, int flags, int protocol, void *vp);
00047
00048 struct comstack
00049 {
00050 CS_TYPE type;
00051 int cerrno;
00052 char *stackerr;
00053 int iofile;
00054 int timeout;
00055 void *cprivate;
00056 int max_recv_bytes;
00057 int state;
00058 #define CS_ST_UNBND 0
00059 #define CS_ST_IDLE 1
00060 #define CS_ST_INCON 2
00061 #define CS_ST_OUTCON 3
00062 #define CS_ST_DATAXFER 4
00063 #define CS_ST_ACCEPT 5
00064 #define CS_ST_CONNECTING 6
00065 int newfd;
00066 int flags;
00067 unsigned io_pending;
00068 int event;
00069 #define CS_NONE 0
00070 #define CS_CONNECT 1
00071 #define CS_DISCON 2
00072 #define CS_LISTEN 3
00073 #define CS_DATA 4
00074 enum oid_proto protocol;
00075 int (*f_put)(COMSTACK handle, char *buf, int size);
00076 int (*f_get)(COMSTACK handle, char **buf, int *bufsize);
00077 int (*f_more)(COMSTACK handle);
00078 int (*f_connect)(COMSTACK handle, void *address);
00079 int (*f_rcvconnect)(COMSTACK handle);
00080 int (*f_bind)(COMSTACK handle, void *address, int mode);
00081 #define CS_CLIENT 0
00082 #define CS_SERVER 1
00083 int (*f_listen)(COMSTACK h, char *raddr, int *addrlen,
00084 int (*check_ip)(void *cd, const char *a, int len, int type),
00085 void *cd);
00086 COMSTACK (*f_accept)(COMSTACK handle);
00087 int (*f_close)(COMSTACK handle);
00088 char *(*f_addrstr)(COMSTACK handle);
00089 void *(*f_straddr)(COMSTACK handle, const char *str);
00090 int (*f_set_blocking)(COMSTACK handle, int blocking);
00091 void *user;
00092 };
00093
00094 #define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size))
00095 #define cs_get(handle, buf, size) ((*(handle)->f_get)(handle, buf, size))
00096 #define cs_more(handle) ((*(handle)->f_more)(handle))
00097 #define cs_connect(handle, address) ((*(handle)->f_connect)(handle, address))
00098 #define cs_rcvconnect(handle) ((*(handle)->f_rcvconnect)(handle))
00099 #define cs_bind(handle, ad, mo) ((*(handle)->f_bind)(handle, ad, mo))
00100 #define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al, 0, 0))
00101 #define cs_listen_check(handle, ap, al, cf, cd) ((*(handle)->f_listen)(handle, ap, al, cf, cd))
00102 #define cs_accept(handle) ((*(handle)->f_accept)(handle))
00103 #define cs_close(handle) ((*(handle)->f_close)(handle))
00104 #define cs_create(type, blocking, proto) ((*type)(-1, blocking, proto, 0))
00105 #define cs_createbysocket(sock, type, blocking, proto) \
00106 ((*type)(sock, blocking, proto, 0))
00107 #define cs_type(handle) ((handle)->type)
00108 #define cs_fileno(handle) ((handle)->iofile)
00109 #define cs_stackerr(handle) ((handle)->stackerr)
00110 #define cs_getstate(handle) ((handle)->getstate)
00111 #define cs_errno(handle) ((handle)->cerrno)
00112 #define cs_getproto(handle) ((handle)->protocol)
00113 #define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle))
00114 #define cs_straddr(handle, str) ((*(handle)->f_straddr)(handle, str))
00115 #define cs_want_read(handle) ((handle)->io_pending & CS_WANT_READ)
00116 #define cs_want_write(handle) ((handle)->io_pending & CS_WANT_WRITE)
00117 #define cs_set_blocking(handle,blocking) ((handle)->f_set_blocking(handle, blocking))
00118
00119 #define CS_WANT_READ 1
00120 #define CS_WANT_WRITE 2
00121
00122 YAZ_EXPORT int cs_look (COMSTACK);
00123 YAZ_EXPORT const char *cs_strerror(COMSTACK h);
00124 YAZ_EXPORT const char *cs_errmsg(int n);
00125 YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host,
00126 int blocking, void **vp);
00127 YAZ_EXPORT void cs_get_host_args(const char *type_and_host, const char **args);
00128 YAZ_EXPORT int cs_complete_auto_head(const char *buf, int len);
00129 YAZ_EXPORT int cs_complete_auto(const char *buf, int len);
00130 YAZ_EXPORT void *cs_get_ssl(COMSTACK cs);
00131 YAZ_EXPORT int cs_set_ssl_ctx(COMSTACK cs, void *ctx);
00132 YAZ_EXPORT int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname);
00133 YAZ_EXPORT int cs_get_peer_certificate_x509(COMSTACK cs, char **buf, int *len);
00134 YAZ_EXPORT void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes);
00135 YAZ_EXPORT int completeWAIS(const char *buf, int len);
00136
00137 YAZ_EXPORT void cs_print_session_info(COMSTACK cs);
00138
00139
00140
00141
00142
00143 #define CSNONE 0
00144 #define CSYSERR 1
00145 #define CSOUTSTATE 2
00146 #define CSNODATA 3
00147 #define CSWRONGBUF 4
00148 #define CSDENY 5
00149 #define CSERRORSSL 6
00150 #define CSBUFSIZE 7
00151 #define CSLASTERROR CSBUFSIZE
00152
00153
00154 #define CS_SR PROTO_SR
00155 #define CS_Z3950 PROTO_Z3950
00156
00157 #define CS_FLAGS_BLOCKING 1
00158 #define CS_FLAGS_NUMERICHOST 2
00159
00160 YAZ_END_CDECL
00161
00162 #endif
00163
00164
00165
00166
00167
00168
00169
00170