YAZ 5.38.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
36
37#ifndef COMSTACK_H
38#define COMSTACK_H
39
40#include <yaz/yconfig.h>
41#include <yaz/oid_util.h>
42#include <yaz/xmalloc.h>
43
45
46struct comstack;
48typedef struct comstack *COMSTACK;
56typedef COMSTACK (*CS_TYPE)(int s, int flags, int protocol, void *vp);
57
65{
67 int cerrno;
68 int iofile;
69 void *cprivate;
71 int state;
73#define CS_ST_UNBND 0
75#define CS_ST_IDLE 1
77#define CS_ST_INCON 2
79#define CS_ST_OUTCON 3
81#define CS_ST_DATAXFER 4
83#define CS_ST_ACCEPT 5
85#define CS_ST_CONNECTING 6
86 int newfd;
87 int flags;
88 unsigned io_pending;
89 int event;
91#define CS_NONE 0
93#define CS_CONNECT 1
95#define CS_DISCON 2
97#define CS_LISTEN 3
99#define CS_DATA 4
102 int (*f_put)(COMSTACK handle, char *buf, int size);
104 int (*f_get)(COMSTACK handle, char **buf, int *bufsize);
106 int (*f_more)(COMSTACK handle);
108 int (*f_connect)(COMSTACK handle, void *address);
110 int (*f_rcvconnect)(COMSTACK handle);
112 int (*f_bind)(COMSTACK handle, void *address, int mode);
114#define CS_CLIENT 0
116#define CS_SERVER 1
118 int (*f_listen)(COMSTACK h, char *raddr, int *addrlen,
119 int (*check_ip)(void *cd, const char *a, int len, int type),
120 void *cd);
124 void (*f_close)(COMSTACK handle);
126 const char *(*f_addrstr)(COMSTACK handle);
128 void *(*f_straddr)(COMSTACK handle, const char *str);
130 int (*f_set_blocking)(COMSTACK handle, int blocking);
131 void *user;
132};
133
143#define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size))
155#define cs_get(handle, buf, size) ((*(handle)->f_get)(handle, buf, size))
162#define cs_more(handle) ((*(handle)->f_more)(handle))
171#define cs_connect(handle, address) ((*(handle)->f_connect)(handle, address))
176#define cs_rcvconnect(handle) ((*(handle)->f_rcvconnect)(handle))
183#define cs_bind(handle, ad, mo) ((*(handle)->f_bind)(handle, ad, mo))
194#define cs_listen(handle, ap, al) ((*(handle)->f_listen)(handle, ap, al, 0, 0))
207#define cs_listen_check(handle, ap, al, cf, cd) ((*(handle)->f_listen)(handle, ap, al, cf, cd))
217#define cs_accept(handle) ((*(handle)->f_accept)(handle))
223#define cs_close(handle) ((*(handle)->f_close)(handle))
230#define cs_create(type, flags, proto) ((*type)(-1, flags, proto, 0))
238#define cs_createbysocket(sock, type, flags, proto) \
239 ((*type)(sock, flags, proto, 0))
240
243#define cs_type(handle) ((handle)->type)
247#define cs_fileno(handle) ((handle)->iofile)
253#define cs_getstate(handle) ((handle)->getstate)
258#define cs_errno(handle) ((handle)->cerrno)
262#define cs_getproto(handle) ((handle)->protocol)
270#define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle))
280#define cs_straddr(handle, str) ((*(handle)->f_straddr)(handle, str))
285#define cs_want_read(handle) ((handle)->io_pending & CS_WANT_READ)
290#define cs_want_write(handle) ((handle)->io_pending & CS_WANT_WRITE)
299#define cs_set_blocking(handle,blocking) ((handle)->f_set_blocking(handle, blocking))
300
302#define CS_WANT_READ 1
304#define CS_WANT_WRITE 2
305
310YAZ_EXPORT int cs_look (COMSTACK);
315YAZ_EXPORT const char *cs_strerror(COMSTACK h);
320YAZ_EXPORT const char *cs_errmsg(int n);
329YAZ_EXPORT int cs_get_error(COMSTACK cs, const char **details);
343YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host,
344 int flags, void **vp);
345
357YAZ_EXPORT COMSTACK cs_create_host_proxy(const char *vhost,
358 int flags, void **vp,
359 const char *proxy_host);
420YAZ_EXPORT COMSTACK cs_create_host2(const char *vhost, int flags, void **vp,
421 const char *proxy_host, int *proxy_mode);
433YAZ_EXPORT void cs_get_host_args(const char *type_and_host, const char **args);
441YAZ_EXPORT int cs_complete_auto_head(const char *buf, int len);
449YAZ_EXPORT int cs_complete_auto(const char *buf, int len);
455YAZ_EXPORT void *cs_get_ssl(COMSTACK cs)
456#ifdef __GNUC__
457 __attribute__ ((deprecated))
458#endif
459 ;
466YAZ_EXPORT int cs_set_ssl_ctx(COMSTACK cs, void *ctx)
467#ifdef __GNUC__
468 __attribute__ ((deprecated))
469#endif
470 ;
481YAZ_EXPORT int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname);
491YAZ_EXPORT int cs_get_peer_certificate_x509(COMSTACK cs, char **buf, int *len);
498YAZ_EXPORT void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes);
504YAZ_EXPORT void cs_print_session_info(COMSTACK cs);
505
523YAZ_EXPORT int cs_parse_host(const char *uri, const char **host,
524 CS_TYPE *t, enum oid_proto *proto,
525 char **connect_host);
532YAZ_EXPORT int cs_set_head_only(COMSTACK cs, int head_only);
533
534/*
535 * error management.
536 */
537
539#define CSNONE 0
541#define CSYSERR 1
543#define CSOUTSTATE 2
545#define CSNODATA 3
547#define CSWRONGBUF 4
549#define CSDENY 5
551#define CSERRORSSL 6
553#define CSBUFSIZE 7
555#define CSPROTERR 8
557#define CSLASTERROR CSPROTERR
558
560#define CS_FLAGS_BLOCKING 1
562#define CS_FLAGS_NUMERICHOST 2
564#define CS_FLAGS_DNS_NO_BLOCK 4
566#define CS_FLAGS_CHECK_CERT 8
567
569
570#endif
571/*
572 * Local variables:
573 * c-basic-offset: 4
574 * c-file-style: "Stroustrup"
575 * indent-tabs-mode: nil
576 * End:
577 * vim: shiftwidth=4 tabstop=8 expandtab
578 */
int cs_get_error(COMSTACK cs, const char **details)
Returns the last COMSTACK error and optional transport details.
Definition comstack.c:51
void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes)
Sets the maximum incoming message size.
Definition comstack.c:536
COMSTACK cs_create_host2(const char *vhost, int flags, void **vp, const char *proxy_host, int *proxy_mode)
Creates an endpoint and selects direct or proxy connection handling.
Definition comstack.c:189
int cs_complete_auto(const char *buf, int len)
Finds the length of a complete BER or HTTP message.
Definition comstack.c:514
int cs_parse_host(const char *uri, const char **host, CS_TYPE *t, enum oid_proto *proto, char **connect_host)
Parses transport and protocol prefixes without resolving an address.
Definition comstack.c:86
void cs_get_host_args(const char *type_and_host, const char **args)
Extracts application arguments from a host or URI specification.
Definition comstack.c:58
int cs_look(COMSTACK cs)
Returns the last recorded event (CS_NONE, CS_CONNECT, etc.).
Definition comstack.c:280
int cs_complete_auto_head(const char *buf, int len)
Finds the length of a BER message or HTTP headers.
Definition comstack.c:519
const char * cs_errmsg(int n)
Returns a static message for a COMSTACK error code.
Definition comstack.c:39
int cs_set_head_only(COMSTACK cs, int head_only)
Selects HTTP header-only framing for TCP/IP, SSL or UNIX transports.
Definition comstack.c:524
COMSTACK cs_create_host(const char *vhost, int flags, void **vp)
Creates an endpoint from a host or URI specification.
Definition comstack.c:177
COMSTACK cs_create_host_proxy(const char *vhost, int flags, void **vp, const char *proxy_host)
Creates an endpoint with an optional proxy.
Definition comstack.c:182
const char * cs_strerror(COMSTACK h)
Returns a static message for the endpoint's last error.
Definition comstack.c:46
struct comstack * COMSTACK
Communication endpoint; release with cs_close.
Definition comstack.h:48
COMSTACK(*) CS_TYPE(int s, int flags, int protocol, void *vp)
Transport constructor and transport identity.
Definition comstack.h:56
Header for OID basic functions.
oid_proto
Definition oid_util.h:45
Public endpoint state and transport dispatch table.
Definition comstack.h:65
COMSTACK(*) f_accept(COMSTACK handle)
Definition comstack.h:122
int flags
Definition comstack.h:87
unsigned io_pending
Definition comstack.h:88
void * user
Definition comstack.h:131
int(*) f_rcvconnect(COMSTACK handle)
Definition comstack.h:110
int(*) f_bind(COMSTACK handle, void *address, int mode)
Definition comstack.h:112
CS_TYPE type
Definition comstack.h:66
int(*) f_put(COMSTACK handle, char *buf, int size)
Definition comstack.h:102
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:118
int state
Definition comstack.h:71
int event
Definition comstack.h:89
int newfd
Definition comstack.h:86
int(*) f_connect(COMSTACK handle, void *address)
Definition comstack.h:108
int(*) f_more(COMSTACK handle)
Definition comstack.h:106
int iofile
Definition comstack.h:68
int cerrno
Definition comstack.h:67
enum oid_proto protocol
Definition comstack.h:100
void * cprivate
Definition comstack.h:69
int(*) f_get(COMSTACK handle, char **buf, int *bufsize)
Definition comstack.h:104
int(*) f_set_blocking(COMSTACK handle, int blocking)
Definition comstack.h:130
int max_recv_bytes
Definition comstack.h:70
void(*) f_close(COMSTACK handle)
Definition comstack.h:124
int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname)
Selects certificate and private key files for a TLS endpoint.
Definition tcpip.c:1698
void cs_print_session_info(COMSTACK cs)
Prints TLS peer certificate information to standard output.
Definition tcpip.c:1638
int cs_get_peer_certificate_x509(COMSTACK cs, char **buf, int *len)
Gets a human-readable description of the first peer X.509 certificate.
Definition tcpip.c:1733
int cs_set_ssl_ctx(COMSTACK cs, void *ctx)
Legacy OpenSSL context setter.
Definition tcpip.c:1686
void * cs_get_ssl(COMSTACK cs)
Legacy OpenSSL session accessor.
Definition tcpip.c:1680
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