|
YAZ 5.38.1
|
Implements TCP/IP + SSL COMSTACK. More...
#include <yaz/yconfig.h>#include <stdio.h>#include <string.h>#include <assert.h>#include <stdlib.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <yaz/thread_create.h>#include <yaz/log.h>#include <yaz/wrbuf.h>#include <yaz/base64.h>#include "comstack-p.h"#include <yaz/tcpip.h>#include <yaz/snprintf.h>#include <yaz/zgdu.h>Go to the source code of this file.
Data Structures | |
| struct | tcpip_state |
Macros | |
| #define | RESOLVER_THREAD 1 |
| #define | YAZ_SOCKLEN_T int |
| #define | CS_TCPIP_BUFCHUNK 4096 |
Typedefs | |
| typedef struct tcpip_state | tcpip_state |
Functions | |
| static void | tcpip_close (COMSTACK h) |
| static int | tcpip_put (COMSTACK h, char *buf, int size) |
| static int | tcpip_get (COMSTACK h, char **buf, int *bufsize) |
| static int | tcpip_connect (COMSTACK h, void *address) |
| static int | tcpip_more (COMSTACK h) |
| static int | tcpip_rcvconnect (COMSTACK h) |
| static int | tcpip_bind (COMSTACK h, void *address, int mode) |
| static int | tcpip_listen (COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int type), void *cd) |
| static int | tcpip_set_blocking (COMSTACK p, int blocking) |
| struct addrinfo * | tcpip_getaddrinfo (const char *str, const char *port, int *ipv6_only) |
| static COMSTACK | tcpip_accept (COMSTACK h) |
| static const char * | tcpip_addrstr (COMSTACK h) |
| static void * | tcpip_straddr (COMSTACK h, const char *str) |
| static int | tcpip_init (void) |
| static struct tcpip_state * | tcpip_state_create (void) |
| static void | tcpip_state_destroy (tcpip_state *sp) |
| COMSTACK | tcpip_type (int s, int flags, int protocol, void *vp) |
| static void | cs_set_error (COMSTACK cs, int error, const char *details) |
| static void | connect_and_bind (COMSTACK p, const char *connect_host, const char *connect_auth, const char *bind_host) |
| COMSTACK | yaz_tcpip_create3 (int s, int flags, int protocol, const char *connect_host, const char *connect_auth, const char *bind_host) |
| COMSTACK | yaz_tcpip_create2 (int s, int flags, int protocol, const char *connect_host, const char *bind_host) |
| COMSTACK | yaz_tcpip_create (int s, int flags, int protocol, const char *connect_host) |
| COMSTACK | ssl_type (int s, int flags, int protocol, void *vp) |
| COMSTACK | yaz_ssl_create (int s, int flags, int protocol, const char *connect_host, const char *connect_auth, const char *bind_host) |
| static void | parse_host_port (const char *host_port, char *tmp, size_t tmp_sz, const char **host, const char **port) |
| static struct addrinfo * | create_net_socket (COMSTACK h) |
| static int | cont_connect (COMSTACK h) |
| void | cs_print_session_info (COMSTACK cs) |
| Prints TLS peer certificate information to standard output. | |
| void * | cs_get_ssl (COMSTACK cs) |
| Legacy OpenSSL session accessor. | |
| int | cs_set_ssl_ctx (COMSTACK cs, void *ctx) |
| Legacy OpenSSL context setter. | |
| int | cs_set_ssl_certificate_file (COMSTACK cs, const char *fname) |
| Selects certificate and private key files for a TLS endpoint. | |
| int | cs_get_peer_certificate_x509 (COMSTACK cs, char **buf, int *len) |
| Gets a human-readable description of the first peer X.509 certificate. | |
| int | yaz_tcpip_set_head_only (COMSTACK cs, int head_only) |
| const char * | yaz_tcpip_get_error_details (COMSTACK cs) |
Variables | |
| static int | log_level = 0 |
| #define CS_TCPIP_BUFCHUNK 4096 |
Definition at line 1207 of file tcpip.c.
Referenced by tcpip_get().
| typedef struct tcpip_state tcpip_state |
|
static |
Definition at line 288 of file tcpip.c.
References tcpip_state::bind_host, connect_and_bind(), tcpip_state::connect_host, tcpip_state::connect_request, comstack::cprivate, wrbuf_alloc(), wrbuf_printf(), xfree, xmalloc, xstrdup, and yaz_base64encode().
Referenced by connect_and_bind(), yaz_ssl_create(), and yaz_tcpip_create3().
|
static |
Definition at line 680 of file tcpip.c.
References tcpip_state::ai_connect, cont_connect(), comstack::cprivate, cs_set_error(), CS_ST_UNBND, CSYSERR, comstack::flags, comstack::iofile, log_level, ssl_type(), comstack::state, tcpip_connect(), tcpip_set_blocking(), comstack::type, and yaz_log().
Referenced by cont_connect(), tcpip_connect(), tcpip_put(), and tcpip_rcvconnect().
|
static |
Definition at line 523 of file tcpip.c.
References tcpip_state::ai, tcpip_state::bind_host, comstack::cprivate, create_net_socket(), cs_set_error(), CSYSERR, comstack::flags, comstack::iofile, tcpip_state::ipv6_only, log_level, tcpip_getaddrinfo(), tcpip_set_blocking(), and yaz_log().
Referenced by create_net_socket(), and tcpip_straddr().
| int cs_get_peer_certificate_x509 | ( | COMSTACK | cs, |
| char ** | buf, | ||
| int * | len ) |
Gets a human-readable description of the first peer X.509 certificate.
| cs | endpoint with an established TLS session |
| buf | required output pointer to allocated, NUL-terminated text |
| len | required output pointer to text length, excluding the terminator |
Requires GnuTLS certificate printing support. Free *buf with xfree after success. The result is descriptive text, not a PEM-encoded certificate.
Definition at line 1733 of file tcpip.c.
References tcpip_state::buf, comstack::cprivate, cs_get_peer_certificate_x509(), ssl_type(), comstack::type, and xstrdup.
Referenced by cs_get_peer_certificate_x509(), and get_cert().
| void * cs_get_ssl | ( | COMSTACK | cs | ) |
Legacy OpenSSL session accessor.
| cs | endpoint |
Definition at line 1680 of file tcpip.c.
References cs_get_ssl().
Referenced by cs_get_ssl().
| void cs_print_session_info | ( | COMSTACK | cs | ) |
Prints TLS peer certificate information to standard output.
| cs | endpoint |
Does nothing for other transports or when no TLS session is available.
Definition at line 1638 of file tcpip.c.
References comstack::cprivate, cs_print_session_info(), ssl_type(), and comstack::type.
Referenced by cs_print_session_info().
|
static |
Definition at line 279 of file tcpip.c.
References comstack::cerrno, comstack::cprivate, cs_set_error(), tcpip_state::error_details, wrbuf_puts(), and wrbuf_rewind().
Referenced by cont_connect(), create_net_socket(), cs_set_error(), cs_set_error(), tcpip_accept(), tcpip_addrstr(), tcpip_bind(), tcpip_connect(), tcpip_get(), tcpip_listen(), tcpip_put(), tcpip_rcvconnect(), unix_accept(), unix_bind(), unix_connect(), unix_get(), unix_listen(), unix_put(), and unix_rcvconnect().
| int cs_set_ssl_certificate_file | ( | COMSTACK | cs, |
| const char * | fname ) |
Selects certificate and private key files for a TLS endpoint.
| cs | endpoint, or NULL |
| fname | filename containing both certificate and key, or "certificate-file,key-file"; NULL or empty disables the default file |
Call before binding or connecting. Filenames are copied; success does not mean the files have been loaded or validated. This overrides the default server certificate filename yaz.pem.
Definition at line 1698 of file tcpip.c.
References comstack::cprivate, cs_set_ssl_certificate_file(), ssl_type(), and comstack::type.
Referenced by add_listener(), cs_set_ssl_certificate_file(), do_connect_host(), and yaz_url_exec().
| int cs_set_ssl_ctx | ( | COMSTACK | cs, |
| void * | ctx ) |
Legacy OpenSSL context setter.
| cs | endpoint, or NULL |
| ctx | ignored legacy context pointer |
Definition at line 1686 of file tcpip.c.
References cs_set_ssl_ctx(), ssl_type(), and comstack::type.
Referenced by cs_set_ssl_ctx().
|
static |
Definition at line 432 of file tcpip.c.
References parse_host_port().
Referenced by parse_host_port(), tcpip_getaddrinfo(), and tcpip_rcvconnect().
| COMSTACK ssl_type | ( | int | s, |
| int | flags, | ||
| int | protocol, | ||
| void * | vp ) |
Definition at line 380 of file tcpip.c.
References comstack::cprivate, ssl_type(), tcpip_type(), and comstack::type.
Referenced by cont_connect(), cs_create_host2(), cs_get_peer_certificate_x509(), cs_parse_host(), cs_print_session_info(), cs_set_head_only(), cs_set_ssl_certificate_file(), cs_set_ssl_ctx(), ssl_type(), tcpip_bind(), tcpip_rcvconnect(), tcpip_straddr(), yaz_ssl_create(), yaz_tcpip_get_error_details(), and yaz_tcpip_set_head_only().
Definition at line 1102 of file tcpip.c.
References comstack::cprivate, cs_close, CS_DATA, cs_set_error(), CS_ST_ACCEPT, CS_ST_DATAXFER, CS_ST_IDLE, CS_ST_INCON, CSOUTSTATE, CSYSERR, comstack::event, comstack::flags, comstack::io_pending, comstack::iofile, log_level, comstack::newfd, comstack::state, tcpip_accept(), tcpip_close(), tcpip_set_blocking(), tcpip_state_create(), tcpip_state_destroy(), xfree, xmalloc, and yaz_log().
Referenced by tcpip_accept(), and tcpip_type().
|
static |
Definition at line 1505 of file tcpip.c.
References tcpip_state::buf, comstack::cprivate, CS_FLAGS_NUMERICHOST, cs_set_error(), CSYSERR, comstack::flags, comstack::iofile, PROTO_HTTP, comstack::protocol, tcpip_addrstr(), yaz_snprintf(), and YAZ_SOCKLEN_T.
Referenced by tcpip_addrstr(), and tcpip_type().
|
static |
Definition at line 960 of file tcpip.c.
References tcpip_state::ai, comstack::cprivate, CS_LISTEN, CS_SERVER, cs_set_error(), CS_ST_IDLE, CSERRORSSL, CSYSERR, comstack::event, comstack::iofile, log_level, ssl_type(), comstack::state, tcpip_bind(), comstack::type, and yaz_log().
Referenced by tcpip_bind(), and tcpip_type().
|
static |
Definition at line 1472 of file tcpip.c.
References comstack::cprivate, comstack::iofile, log_level, tcpip_close(), tcpip_state_destroy(), xfree, yaz_log(), and yaz_thread_join().
Referenced by tcpip_accept(), tcpip_close(), and tcpip_type().
|
static |
Definition at line 720 of file tcpip.c.
References tcpip_state::ai_connect, cont_connect(), comstack::cprivate, CS_CONNECT, CS_FLAGS_BLOCKING, cs_set_error(), CS_ST_CONNECTING, CS_ST_UNBND, CS_WANT_READ, CS_WANT_WRITE, CSOUTSTATE, comstack::event, comstack::flags, comstack::io_pending, comstack::iofile, log_level, comstack::state, tcpip_connect(), tcpip_rcvconnect(), yaz_errno(), and yaz_log().
Referenced by cont_connect(), tcpip_connect(), tcpip_rcvconnect(), and tcpip_type().
|
static |
Definition at line 1213 of file tcpip.c.
References tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::altsize, tcpip_state::complete, comstack::cprivate, CS_FLAGS_BLOCKING, cs_set_error(), CS_TCPIP_BUFCHUNK, CS_WANT_READ, CSBUFSIZE, CSPROTERR, CSYSERR, comstack::flags, comstack::io_pending, comstack::iofile, log_level, comstack::max_recv_bytes, tcpip_get(), xmalloc, xrealloc, yaz_errno(), yaz_log(), and yaz_set_errno().
Referenced by tcpip_get(), tcpip_rcvconnect(), and tcpip_type().
| struct addrinfo * tcpip_getaddrinfo | ( | const char * | str, |
| const char * | port, | ||
| int * | ipv6_only ) |
Definition at line 471 of file tcpip.c.
References parse_host_port(), and tcpip_getaddrinfo().
Referenced by create_net_socket(), tcpip_getaddrinfo(), and tcpip_straddr().
|
static |
Definition at line 154 of file tcpip.c.
References log_level, tcpip_init(), yaz_init_globals(), and yaz_log_module_level().
Referenced by tcpip_init(), tcpip_straddr(), and tcpip_type().
|
static |
Definition at line 1032 of file tcpip.c.
References cs_set_error(), CS_ST_IDLE, CS_ST_INCON, CSDENY, CSNODATA, CSOUTSTATE, CSYSERR, comstack::iofile, log_level, comstack::newfd, comstack::state, tcpip_listen(), yaz_errno(), yaz_log(), and YAZ_SOCKLEN_T.
Referenced by tcpip_listen(), and tcpip_type().
|
static |
Definition at line 673 of file tcpip.c.
References tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::complete, comstack::cprivate, and tcpip_more().
Referenced by tcpip_more(), and tcpip_type().
|
static |
Definition at line 1384 of file tcpip.c.
References tcpip_state::buf, cont_connect(), comstack::cprivate, CS_DATA, CS_FLAGS_BLOCKING, cs_set_error(), CS_WANT_WRITE, CSWRONGBUF, CSYSERR, comstack::event, comstack::flags, comstack::io_pending, comstack::iofile, log_level, tcpip_put(), tcpip_state::towrite, tcpip_state::written, yaz_errno(), and yaz_log().
Referenced by tcpip_put(), tcpip_rcvconnect(), and tcpip_type().
|
static |
Definition at line 820 of file tcpip.c.
References tcpip_state::complete, tcpip_state::connect_host, tcpip_state::connect_phase, tcpip_state::connect_request, tcpip_state::connect_response_buf, tcpip_state::connect_response_len, cont_connect(), comstack::cprivate, cs_complete_auto(), cs_complete_auto_head(), CS_CONNECT, CS_DATA, CS_FLAGS_BLOCKING, CS_FLAGS_CHECK_CERT, cs_set_error(), CS_ST_CONNECTING, CS_ST_DATAXFER, CS_ST_UNBND, CSDENY, CSERRORSSL, CSOUTSTATE, CSPROTERR, comstack::event, comstack::flags, tcpip_state::host_port, comstack::iofile, log_level, parse_host_port(), ssl_type(), comstack::state, tcpip_connect(), tcpip_get(), tcpip_put(), tcpip_rcvconnect(), comstack::type, wrbuf_buf, wrbuf_len, yaz_decode_http_response_first(), and yaz_log().
Referenced by tcpip_connect(), tcpip_rcvconnect(), and tcpip_type().
|
static |
Definition at line 1544 of file tcpip.c.
References CS_FLAGS_BLOCKING, comstack::flags, comstack::iofile, and tcpip_set_blocking().
Referenced by cont_connect(), create_net_socket(), tcpip_accept(), tcpip_set_blocking(), and tcpip_type().
|
static |
Definition at line 181 of file tcpip.c.
References tcpip_state::ai, tcpip_state::ai_connect, tcpip_state::altbuf, tcpip_state::altlen, tcpip_state::altsize, tcpip_state::bind_host, tcpip_state::complete, tcpip_state::connect_host, tcpip_state::connect_phase, tcpip_state::connect_request, tcpip_state::connect_response_buf, tcpip_state::connect_response_len, cs_complete_auto(), tcpip_state::error_details, tcpip_state::host_port, tcpip_state_create(), tcpip_state::towrite, wrbuf_alloc(), tcpip_state::written, and xmalloc.
Referenced by tcpip_accept(), tcpip_state_create(), and tcpip_type().
|
static |
Definition at line 215 of file tcpip.c.
References tcpip_state::ai, tcpip_state::altbuf, tcpip_state::bind_host, tcpip_state::connect_host, tcpip_state::connect_request, tcpip_state::connect_response_buf, tcpip_state::error_details, tcpip_state::host_port, tcpip_state_destroy(), wrbuf_destroy(), and xfree.
Referenced by tcpip_accept(), tcpip_close(), and tcpip_state_destroy().
|
static |
Definition at line 633 of file tcpip.c.
References tcpip_state::ai, comstack::cprivate, create_net_socket(), CS_FLAGS_DNS_NO_BLOCK, CS_ST_UNBND, comstack::flags, tcpip_state::host_port, tcpip_state::ipv6_only, PROTO_HTTP, comstack::protocol, ssl_type(), comstack::state, tcpip_getaddrinfo(), tcpip_init(), tcpip_straddr(), comstack::type, xfree, xstrdup, and yaz_thread_create().
Referenced by tcpip_straddr(), and tcpip_type().
| COMSTACK tcpip_type | ( | int | s, |
| int | flags, | ||
| int | protocol, | ||
| void * | vp ) |
Definition at line 238 of file tcpip.c.
References comstack::cerrno, comstack::cprivate, CS_NONE, CS_ST_IDLE, CS_ST_UNBND, comstack::event, comstack::f_accept, comstack::f_addrstr, comstack::f_bind, comstack::f_close, comstack::f_connect, comstack::f_get, comstack::f_listen, comstack::f_more, comstack::f_put, comstack::f_rcvconnect, comstack::f_set_blocking, comstack::f_straddr, comstack::flags, comstack::io_pending, comstack::iofile, log_level, comstack::max_recv_bytes, comstack::protocol, comstack::state, tcpip_accept(), tcpip_addrstr(), tcpip_bind(), tcpip_close(), tcpip_connect(), tcpip_get(), tcpip_init(), tcpip_listen(), tcpip_more(), tcpip_put(), tcpip_rcvconnect(), tcpip_set_blocking(), tcpip_state_create(), tcpip_straddr(), tcpip_type(), comstack::type, comstack::user, xmalloc, and yaz_log().
Referenced by cs_create_host2(), cs_parse_host(), cs_set_head_only(), inetd_connection(), ssl_type(), tcpip_type(), yaz_tcpip_create3(), yaz_tcpip_get_error_details(), and yaz_tcpip_set_head_only().
| COMSTACK yaz_ssl_create | ( | int | s, |
| int | flags, | ||
| int | protocol, | ||
| const char * | connect_host, | ||
| const char * | connect_auth, | ||
| const char * | bind_host ) |
Definition at line 401 of file tcpip.c.
References connect_and_bind(), ssl_type(), and yaz_ssl_create().
Referenced by cs_create_host2(), and yaz_ssl_create().
| COMSTACK yaz_tcpip_create | ( | int | s, |
| int | flags, | ||
| int | protocol, | ||
| const char * | connect_host ) |
Definition at line 346 of file tcpip.c.
References tcpip_state::connect_host, yaz_tcpip_create(), and yaz_tcpip_create2().
Referenced by yaz_tcpip_create().
| COMSTACK yaz_tcpip_create2 | ( | int | s, |
| int | flags, | ||
| int | protocol, | ||
| const char * | connect_host, | ||
| const char * | bind_host ) |
Definition at line 339 of file tcpip.c.
References tcpip_state::bind_host, tcpip_state::connect_host, yaz_tcpip_create2(), and yaz_tcpip_create3().
Referenced by yaz_tcpip_create(), and yaz_tcpip_create2().
| COMSTACK yaz_tcpip_create3 | ( | int | s, |
| int | flags, | ||
| int | protocol, | ||
| const char * | connect_host, | ||
| const char * | connect_auth, | ||
| const char * | bind_host ) |
Definition at line 327 of file tcpip.c.
References tcpip_state::bind_host, connect_and_bind(), tcpip_state::connect_host, tcpip_type(), and yaz_tcpip_create3().
Referenced by cs_create_host2(), yaz_tcpip_create2(), and yaz_tcpip_create3().
| const char * yaz_tcpip_get_error_details | ( | COMSTACK | cs | ) |
Definition at line 1787 of file tcpip.c.
References comstack::cprivate, tcpip_state::error_details, ssl_type(), tcpip_type(), comstack::type, wrbuf_cstr(), wrbuf_len, and yaz_tcpip_get_error_details().
Referenced by cs_get_error(), and yaz_tcpip_get_error_details().
| int yaz_tcpip_set_head_only | ( | COMSTACK | cs, |
| int | head_only ) |
Definition at line 1772 of file tcpip.c.
References tcpip_state::buf, comstack::cerrno, tcpip_state::complete, comstack::cprivate, cs_complete_auto(), cs_complete_auto_head(), CSOUTSTATE, ssl_type(), tcpip_type(), comstack::type, and yaz_tcpip_set_head_only().
Referenced by cs_set_head_only(), and yaz_tcpip_set_head_only().