YAZ 5.35.1
comstack.h
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data.
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
33#ifndef COMSTACK_H
34#define COMSTACK_H
35
36#include <yaz/yconfig.h>
37#include <yaz/oid_util.h>
38#include <yaz/xmalloc.h>
39
41
42struct comstack;
43typedef struct comstack *COMSTACK;
44typedef COMSTACK (*CS_TYPE)(int s, int flags, int protocol, void *vp);
45
47{
49 int cerrno; /* current error code of this stack */
50 int iofile; /* UNIX file descriptor for iochannel */
51 void *cprivate;/* state info for lower stack */
52 int max_recv_bytes; /* max size of incoming package */
53 int state; /* current state */
54#define CS_ST_UNBND 0
55#define CS_ST_IDLE 1
56#define CS_ST_INCON 2
57#define CS_ST_OUTCON 3
58#define CS_ST_DATAXFER 4
59#define CS_ST_ACCEPT 5
60#define CS_ST_CONNECTING 6
61 int newfd; /* storing new descriptor between listen and accept */
62 int flags; /* flags, blocking etc.. CS_FLAGS_.. */
63 unsigned io_pending; /* flag to signal read / write op is incomplete */
64 int event; /* current event */
65#define CS_NONE 0
66#define CS_CONNECT 1
67#define CS_DISCON 2
68#define CS_LISTEN 3
69#define CS_DATA 4
70 enum oid_proto protocol; /* what application protocol are we talking? */
71 int (*f_put)(COMSTACK handle, char *buf, int size);
72 int (*f_get)(COMSTACK handle, char **buf, int *bufsize);
73 int (*f_more)(COMSTACK handle);
74 int (*f_connect)(COMSTACK handle, void *address);
75 int (*f_rcvconnect)(COMSTACK handle);
76 int (*f_bind)(COMSTACK handle, void *address, int mode);
77#define CS_CLIENT 0
78#define CS_SERVER 1
79 int (*f_listen)(COMSTACK h, char *raddr, int *addrlen,
80 int (*check_ip)(void *cd, const char *a, int len, int type),
81 void *cd);
83 void (*f_close)(COMSTACK handle);
84 const char *(*f_addrstr)(COMSTACK handle);
85 void *(*f_straddr)(COMSTACK handle, const char *str);
86 int (*f_set_blocking)(COMSTACK handle, int blocking);
87 void *user; /* user defined data associated with COMSTACK */
88};
89
90#define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size))
91#define cs_get(handle, buf, size) ((*(handle)->f_get)(handle, buf, size))
92#define cs_more(handle) ((*(handle)->f_more)(handle))
93#define cs_connect(handle, address) ((*(handle)->f_connect)(handle, address))
94#define cs_rcvconnect(handle) ((*(handle)->f_rcvconnect)(handle))
95#define cs_bind(handle, ad, mo) ((*(handle)->f_bind)(handle, ad, mo))
96#define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al, 0, 0))
97#define cs_listen_check(handle, ap, al, cf, cd) ((*(handle)->f_listen)(handle, ap, al, cf, cd))
98#define cs_accept(handle) ((*(handle)->f_accept)(handle))
99#define cs_close(handle) ((*(handle)->f_close)(handle))
100#define cs_create(type, blocking, proto) ((*type)(-1, blocking, proto, 0))
101#define cs_createbysocket(sock, type, blocking, proto) \
102 ((*type)(sock, blocking, proto, 0))
103#define cs_type(handle) ((handle)->type)
104#define cs_fileno(handle) ((handle)->iofile)
105#define cs_getstate(handle) ((handle)->getstate)
106#define cs_errno(handle) ((handle)->cerrno)
107#define cs_getproto(handle) ((handle)->protocol)
108#define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle))
109#define cs_straddr(handle, str) ((*(handle)->f_straddr)(handle, str))
110#define cs_want_read(handle) ((handle)->io_pending & CS_WANT_READ)
111#define cs_want_write(handle) ((handle)->io_pending & CS_WANT_WRITE)
112#define cs_set_blocking(handle,blocking) ((handle)->f_set_blocking(handle, blocking))
113
114#define CS_WANT_READ 1
115#define CS_WANT_WRITE 2
116
117YAZ_EXPORT int cs_look (COMSTACK);
118YAZ_EXPORT const char *cs_strerror(COMSTACK h);
119YAZ_EXPORT const char *cs_errmsg(int n);
120YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host,
121 int blocking, void **vp);
122
123YAZ_EXPORT COMSTACK cs_create_host_proxy(const char *vhost,
124 int blocking, void **vp,
125 const char *proxy_host);
126YAZ_EXPORT COMSTACK cs_create_host2(const char *vhost, int blocking, void **vp,
127 const char *proxy_host, int *proxy_mode);
128YAZ_EXPORT void cs_get_host_args(const char *type_and_host, const char **args);
129YAZ_EXPORT int cs_complete_auto_head(const char *buf, int len);
130YAZ_EXPORT int cs_complete_auto(const char *buf, int len);
131YAZ_EXPORT void *cs_get_ssl(COMSTACK cs)
132#ifdef __GNUC__
133 __attribute__ ((deprecated))
134#endif
135 ;
136YAZ_EXPORT int cs_set_ssl_ctx(COMSTACK cs, void *ctx)
137#ifdef __GNUC__
138 __attribute__ ((deprecated))
139#endif
140 ;
141YAZ_EXPORT int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname);
142YAZ_EXPORT int cs_get_peer_certificate_x509(COMSTACK cs, char **buf, int *len);
143YAZ_EXPORT void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes);
144YAZ_EXPORT void cs_print_session_info(COMSTACK cs);
145
146YAZ_EXPORT int cs_parse_host(const char *uri, const char **host,
147 CS_TYPE *t, enum oid_proto *proto,
148 char **connect_host);
149YAZ_EXPORT int cs_set_head_only(COMSTACK cs, int head_only);
150
151/*
152 * error management.
153 */
154
155#define CSNONE 0
156#define CSYSERR 1
157#define CSOUTSTATE 2
158#define CSNODATA 3
159#define CSWRONGBUF 4
160#define CSDENY 5
161#define CSERRORSSL 6
162#define CSBUFSIZE 7
163#define CSLASTERROR CSBUFSIZE /* must be the value of last CS error */
164
165#define CS_FLAGS_BLOCKING 1
166#define CS_FLAGS_NUMERICHOST 2
167#define CS_FLAGS_DNS_NO_BLOCK 4
168
170
171#endif
172/*
173 * Local variables:
174 * c-basic-offset: 4
175 * c-file-style: "Stroustrup"
176 * indent-tabs-mode: nil
177 * End:
178 * vim: shiftwidth=4 tabstop=8 expandtab
179 */
180
int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname)
Definition tcpip.c:1552
void cs_print_session_info(COMSTACK cs)
Definition tcpip.c:1492
COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp)
Definition comstack.c:167
int cs_get_peer_certificate_x509(COMSTACK cs, char **buf, int *len)
Definition tcpip.c:1566
void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes)
Definition comstack.c:476
int cs_complete_auto(const char *buf, int len)
Definition comstack.c:466
int cs_set_ssl_ctx(COMSTACK cs, void *ctx)
Definition tcpip.c:1540
int cs_parse_host(const char *uri, const char **host, CS_TYPE *t, enum oid_proto *proto, char **connect_host)
Definition comstack.c:76
void cs_get_host_args(const char *type_and_host, const char **args)
Definition comstack.c:48
int cs_complete_auto_head(const char *buf, int len)
Definition comstack.c:471
struct comstack * COMSTACK
Definition comstack.h:43
COMSTACK cs_create_host2(const char *vhost, int blocking, void **vp, const char *proxy_host, int *proxy_mode)
Definition comstack.c:179
const char * cs_errmsg(int n)
Definition comstack.c:36
COMSTACK cs_create_host_proxy(const char *vhost, int blocking, void **vp, const char *proxy_host)
Definition comstack.c:172
int cs_set_head_only(COMSTACK cs, int head_only)
Definition tcpip.c:1605
int cs_look(COMSTACK)
Definition comstack.c:257
void * cs_get_ssl(COMSTACK cs)
Definition tcpip.c:1534
const char * cs_strerror(COMSTACK h)
Definition comstack.c:43
COMSTACK(* CS_TYPE)(int s, int flags, int protocol, void *vp)
Definition comstack.h:44
Header for OID basic functions.
oid_proto
Definition oid_util.h:45
int(* f_bind)(COMSTACK handle, void *address, int mode)
Definition comstack.h:76
int flags
Definition comstack.h:62
COMSTACK(* f_accept)(COMSTACK handle)
Definition comstack.h:82
void(* f_close)(COMSTACK handle)
Definition comstack.h:83
unsigned io_pending
Definition comstack.h:63
void * user
Definition comstack.h:87
int(* f_listen)(COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int type), void *cd)
Definition comstack.h:79
int(* f_put)(COMSTACK handle, char *buf, int size)
Definition comstack.h:71
CS_TYPE type
Definition comstack.h:48
int(* f_more)(COMSTACK handle)
Definition comstack.h:73
int state
Definition comstack.h:53
int event
Definition comstack.h:64
int newfd
Definition comstack.h:61
int(* f_set_blocking)(COMSTACK handle, int blocking)
Definition comstack.h:86
int iofile
Definition comstack.h:50
int(* f_rcvconnect)(COMSTACK handle)
Definition comstack.h:75
int cerrno
Definition comstack.h:49
int(* f_connect)(COMSTACK handle, void *address)
Definition comstack.h:74
int(* f_get)(COMSTACK handle, char **buf, int *bufsize)
Definition comstack.h:72
enum oid_proto protocol
Definition comstack.h:70
void * cprivate
Definition comstack.h:51
int max_recv_bytes
Definition comstack.h:52
Header for memory handling functions.
Header with fundamental macros.
#define YAZ_BEGIN_CDECL
Definition yconfig.h:56
#define YAZ_END_CDECL
Definition yconfig.h:57